5 ms·
It is when you get to this part of python, that you achieve true Nirvana. It's absolutely bonkers the extent to which you can be dynamic in this language. It'
by devxpy 8y ago
It is when you get to this part of python, that you achieve true Nirvana.
It's absolutely bonkers the extent to which you can be dynamic in this language.
It's the very reason why Django is so DRY.
- misiti3780 8y agocan you explain what you mean about django ?
- lalos 8y agoThis would be an example: https://www.agiliq.com/blog/2018/01/understanding-python-magic-methods-with-djang-querysets/ https://www.agiliq.com/blog/2018/01/understanding-python-mag...
- sbjs 8y agoBut this article is just explaining operator overloading, right? Doesn't everyone learn that halfway through semester in C++ 101? And operator overloading has nothing to do with DRY, in fact it's generally better to avoid it except for in very niche situations, like adding __add__ to a matrix type.
- devxpy 8y agohttps://docs.python.org/3/reference/datamodel.html#customizing-attribute-access https://docs.python.org/3/reference/datamodel.html#customizi...
- nikofeyn 8y agowhy is this so bonkers? it seems like it's just basic patterns of method overriding and operator overloading. if people think this is so magic, it's almost as if lisps, schemes, and prologs never existed.
- jlarocco 8y ago> if people think this is so magic, it's almost as if lisps, schemes, and prologs never existed. I write quite a bit of Lisp, and the conclusion I've come to is that for 95% of software developers, Lisp, Scheme, and Prolog might as well not exist. Even here on HN, where I'd expect the bar to be a little higher, the amount of incorrect info posted about Lisp is pretty crazy. I'm almost certain most people's only experience with Lisp(s) and Prolog was a week or two using it in their programming languages class at university.
- matheusmoreira 8y agoI felt the same way as I learned Python. People told me Python had this magical framework built into the language and that I'd understand everything once I learned it. Turns out the built-in language features are syntax sugar for some __special_method__ calls. Simple and functional, but underwhelming...
- Waterluvian 8y agoDjango's DRY suuuuuuuucks when you're getting started. It's basically all this magic that you can't understand without already knowing Django. Why does get_attr get called? Oh because it begins with the word "get" and there's an attribute that defines a method field called "attr". I use Django a lot and generally it's great. But I hate that you can't follow your code paths from start to finish on the surface. You have to know about how it works underneath. Meaning you can't just be a python + web server expert. You have to also be a Django expert. So I get non-Django experts reviewing code and they have no clue why things work or break. Just an opinion. Not saying this is objectively wrong.
- sbjs 8y agoPeople who feel this way usually use Flask instead. Worth checking out. http://flask.pocoo.org/ http://flask.pocoo.org/
- Waterluvian 8y agoFlask is great for smaller things where Django is far too verbose. Like single file webservers for basic stuff. Its also for more complex stuff but then you have to grab additional libraries to do stuff like db management, migrations, serialization, etc. Flask also has some, in my opinion, rather uncomfortablly unintuitive global scope stuff. Where responses aren't passed into the view function, they're available on the imported flask object.
- sbjs 8y agoGood to know. I haven't used Flask recently, I have used Express.js which is Node.js's version of Flask, and I really like how simple it is. Most apps these days seem to have a REST (or GraphQL) backend and dynamic (often React.js) frontend. Flask (and Flask-RESTful) would probably be a better fit for this type of app than Django.
- Waterluvian 8y agoYeah don't let me dissuade you. Flask is a prime piece of software.