3 ms·
It's a class factory function, so right off the bat it's a bit weird. The original intent of using spaces was probably to minimize typing. Since they're attribu
by sgtnoodle 5y ago
It's a class factory function, so right off the bat it's a bit weird. The original intent of using spaces was probably to minimize typing. Since they're attribute names they can't have spaces in them, so it's a safe delimiter.
You could imagine the function dynamically creates the class by manipulating the underlying dictionary (or whatever the "slot" alternative uses). At that level of python, attributes are strings anyway. Handling spaces is just a matter of calling .split().
In modern python, there's a whole metaclass system that would possibly let you do the equivalent without getting your hands dirty with internal data structures.
- Pokepokalypse 5y agoI envy coders who can actually save time by using a space as a delimiter instead of ['x', 'y']. I really have no use for such syntactic sugar.
- denimnerd42 5y agosyntactic sugar actually drives me nuts because it makes code harder to read for non experts
- sgtnoodle 5y agoYeah, I think more time is wasted in confusion and arguing about style than is saved in keyboard strokes. There's definitely a class of persnickety coders out there though. As a technical leader within a growing organization, sometimes the bulk of my time spent in a code review turns into style guide enforcement. It can get old arguing about the subtle merits of someone's preferred but style violating syntax over and over, especially when all I care about is maintaining a standard of consistency.
- framecowbird 5y agoThis kind of thing grates me: one thing I love about Python is that there is usually only one way of doing everything.