6 ms·
You've invented your own incompatible dialect of python. You've broken composition, objects and the general design choices of python. 1. You break Composition
by tef____ 15y ago
You've invented your own incompatible dialect of python. You've broken composition, objects and the general design choices of python.
1. You break Composition
Your magic flag within a list changes all the semantics of the methods between immutable and mutable lists.
> x = List([1,2,3]).saving()
So now, if you're passed a list you have no idea if the operations you do will mutate the list.
This breaks composition entirely. You can't pass a mutable list into a function built for immutable lists without destroying things.
2. You break objects
Picking another example, this breaks duck typing and inheritance and polymorphism.
>def user_logged(users):
> return List(users).all(User.is_logged)
this does not have the same semantics as:
> def user_logged(users):
> return all(user.is_logged() for user)
Because the method lookup is done per instance, rather than assuming everything is the same class.
3. You're writing jquery in python
Python chose not to demand that all iterables implement a series of operators, but provides them as functions within a module. The rationale is that it is easier to add new functions within itertools, and there is far less to do to correctly implement the iterator protocol
You can see this in the "".join(foo) operator too. Instead of demanding all iterables support join, string takes an iterable as argument.
Making readable and maintainable python comes from using the existing idioms within the language and used within the community. Your proposed solution isn't readable, and it isn't pythonic.
- phzbOx 15y agoThanks for the feedback, these are interesting points. I'd like to clarify a couple of things about your #2 and #3. def user_logged(users): > return List(users).all(User.is_logged) # If you want per instance: def user_logged(users): > return List(users).all(lambda x: x.is_logged()) And, about the "".join; you are right. However, Moka's construct allow you to use whatever you want, i.e.: moka.List(['a', 'b']).do(string.join, '').last_value Or, you can still use: ''.join(moka.List(['a', 'b'])) However, about the #1, I have to agree. I've added the saving() recently and had a bad taste about it. The right way to do it might be to make it mutable by default and only toggle it off in certain circumstances. Please note that everything done by the community is still perfectly usable; in fact, it's even easier to use useful high-level functions. I.e. map(str, range(1,10)) or List(range(1,10)).map(str); is syntactically different but does the same job.
- ScottBurson 15y agoYeah, get rid of saving(). Not only are the semantics dangerous and confusing, but the name suggests the opposite of what it actually does.
- tef____ 15y ago#1 the correct way to do it is to have the methods perform the same action on mutable and immutable objects. this is the only way to guarantee composition. you do not change the semantics of shared methods. #2 for both of these examples you give 'to use whatever you want' "".join(['a','b']) is how everyone else does it in python code. it isn't about things in the community being usable within your library, it is about your library being /unusable/ within the community. You re-invent new and awkward ways to do standard things without standard idioms. 'i've just invented a whole bunch of new semantics for things so it will be readable' readability is about /convention/. readable to whom? pushing your own love of jquery method chaining only serves to ostracise those already somewhat knowledgable within python. it is not pythonic in any way shape of form.
- tef____ 15y agoif you are inventing a new way to do existing things outside the idioms of the language there is no conceivable way you can claim to be pythonic. you are replacing the pythonic style with your own taste. don't confuse the two.
- phzbOx 15y agoI'm not sure why you created a fake account to answer this but thanks again for your time. You're right that it was built for my own taste using simultaneously other languages (clojure, arc and js for instance). At the end of the day, what's important is that it increases the quality of the code and this is my goal with Moka. This is still in an alpha stage, but I'll definitely tweak it based on good feedback (Like yours) Feel free to drop me a line: phzbox at gmail if you want to continue this discussion.
- 15y ago
- timtadh 15y agoWhat is with all the hate lately on anyone who dares to write Python with different semantics than employed by the stdlib builtins? 'You've invented your own incompatible dialect of python. ' It isn't a "dialect." You don't need a different parser. There are no macros. It is simply a container with slightly different semantics than the stdlib ones. "You've broken composition, objects and the general design choices of python." No those all still work and if you don't like his semantics don't use them. They are perfectly readable and easily understandable if you having a passing familiarity with the pattern he is using. tl;dr : I don't see what the big deal is, people are allowed to write Python however they want.
- deleted 15y ago[deleted]
- tef____ 15y agotl;dr: you didn't read my post. I am pretty sure I made it clear how composition breaks. 'people are allowed to write Python however they want.' people are encouraged to write python other people understand.
- timtadh 15y agoNo I did read your post. Actually I read all of them. My point is he didn't "break" composition. In isn't like you import this guy's library and suddenly function composition no longer works. Breaking isn't the right word. It is agressive and wrong on a semantic level. You could say "You functional list does not properly support composition. Here are some problems." You posts were needlessly combative. I only spoke out because I have seen this kind of thing cropping up recently with respect to Python functional libraries. "people are encouraged to write python other people understand." As I said, the semantics of his library are reasonably clear on inspection doubly so if you read the docs. EDIT: I just re-read some of your other posts on this thread. You really do keep banging on "He made his own 'dialect.'" To clarify, no he didn't. Making a library isn't a dialect. A dialect needs to be a significant enough departure that you would actually need a different parser/interpreter. That is a "dialect." If you would like I can point you actual Python dialects. This is a library. Deal with it.