4 ms·
I'd like you and the parent comment to provide one example of "magic strings" in Python and Javascript. Javascript has really bad type coercion, no doubt. But
by rglullis 11y ago
I'd like you and the parent comment to provide one example of "magic strings" in Python and Javascript.
Javascript has really bad type coercion, no doubt. But there is nothing on the language that is built upon these concepts.
And I don't get the comparison between Rails (a framework that, indeed, does use a lot of "magic" in the naming of the classes) to programming languages.
- cm2187 11y agoIn a dynamic language, every function or property is a magic string since the IDE/Compiler has no way to tell that this function will exist or not until runtime.
- rglullis 11y agoThat's a total stretch. Stop moving goal posts, and please provide one example of function or variable in either python or JS that behaves in some special way only because of the name.
- pavel_lishin 11y ago__getitem__
- rglullis 11y agoThat is just a method for an object. And the "double double underscore" thing is more of a way to show that the method is specialized and that there is no good reason to be redefining it. Nothing magic happens on the runtime in your application if you redefine the method. If these would count as "magic", so would any language that supports operator-overloading and templates, which basically means that even C and C++ have "magic strings". Still, you got close. If there is one thing that I could accept as "magic" is the fact that Python changes the accessor of functions if the function name starts with double underscore (but not if it also ends with double underscores). Even that would be debatable, because the behavior is well-defined and the transformation is simple.
- skrebbel 11y agoThe "magic" about the strings in ASP.NET MVC is that the name of certain strings define which method gets called further down the line. That's exactly what dynamically typed languages do. Typos are caught at runtime, not at compile time, and possibly with cryptic errors if you're unlucky. The GP is used to C#, where (except if you use MVC), typos are immediately highlighted by the editor. Your definition of "magic" is much stronger than that, so by accident of not entirely understanding the GP's complaint, you think we're moving goalposts.
- rglullis 11y agoWhile your answer does help in clarifying some misunderstanding ("magic string" to me is supposed to mean something else entirely), it still conflates programming languages with frameworks. ASP.NET MVC is not a language, as far as I know. Also, most "dynamic languages" have linters and syntax analyzers that you can hook up to your editor. If I have a typo in my code, flake8 will find it right away, and I don't need to run the code to do it.
- PascalsMugger 11y agoI'd call "__proto__" a magic string, but it's kind of an accident of history and a one off that everyone wants to get rid of, but can't.
- kqr 11y agoThe `clean_xxx` method will be called when the `xxx` field needs to be cleaned. If you rename the `xxx` field and forget to similarly rename the `clean` method... sucks to be you! The same thing goes for a bunch of the `ContentType` stuff where you address specific instances generically using the string `applabel.modelname.id`. Edit: Oops, misread. This is Django specifically, not Python generally.