Moka - Minimalist functional python library
11–20 of 37 posts
Re: Moka - Minimalist functional python library
#12Clickable link for the doc: http://phzbox.com/moka/index.html Moka is still in an alpha stage; but that being said, I'd love to hear some feedback. Feel free to browse the code, it should be pretty straightforward to any python dev.
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.
Re: Moka - Minimalist functional python library
#13Clickable link for the doc: http://phzbox.com/moka/index.html Moka is still in an alpha stage; but that being said, I'd love to hear some feedback. Feel free to browse the code, it should be pretty straightforward to any python dev.
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 enti…
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.
Re: Moka - Minimalist functional python library
#14The doc at http://www.phzbox.com/moka/index.html is pretty complete. The only thing I find is missing is a few words about efficiency. Does calling List(l) copy the list l for example?
As for the copy, yes it does as it tries to act like a builtin list as much as possible. (In fact, moka.List inherit from list). When it's in immutable state, a new list is returned at each step. If it's in mutable, self[:] = (..) is used.
Re: Moka - Minimalist functional python library
#15The doc at http://www.phzbox.com/moka/index.html is pretty complete. The only thing I find is missing is a few words about efficiency. Does calling List(l) copy the list l for example?
Re: Moka - Minimalist functional python library
#16Earlier quoted context omitted.
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 enti…
Thanks 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(strin…
Re: Moka - Minimalist functional python library
#17Earlier quoted context omitted.
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 enti…
Thanks 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(strin…
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.
Re: Moka - Minimalist functional python library
#18Earlier quoted context omitted.
Thanks 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(strin…
#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 abou…
you are replacing the pythonic style with your own taste.
don't confuse the two.
Re: Moka - Minimalist functional python library
#19Earlier quoted context omitted.
Thanks 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(strin…
#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 abou…
from the outset you haven't made any attempt to learn python style. go and read the zen of python.
I only picked on a handful of examples, but wait! theres more - almost every example on your page has a way to do it in python. that other python developers use and understand.
#chaining example:
you say 'we believe chaining constructs are easier to read and maintain than deeply nested expressions.'
zen: flat is better than nested
> Dict(a=1, b=2).update(c=3).rem(lambda x, y: x=='a')
becomes
> d = dict(a=1, b=2)
> d['c'] = 3
> del d['a']
#'partial application' example
> List([1,2,3]).map(string.zfill, 8, _)
becomes
> [str(i).zfill(8) for i in [1,2,3])
# magic argument names
zen: 'explcit is better than implicit'
different methods have different magic attached: it isn't obvious from the outset why update takes named args but keep takes args are named operators
> List([1,2,3]).keep(gt=1)
becomes
> [x for x in [1,2,3] if x > 1]
# you reinvent all
> List(range(1,10)).all(lambda x: x becomes
> all(x # 'compact' example
> List([None, 0, 2, []]).compact()
becomes
> [x for x in [None, 0 , 2, []] if x]
# 'list is empty' example
> List([]).empty()
becomes
> bool([])
# 'sort'
> List([5,3,1]).sort()
becomes
> sorted([5,3,1])
'uniq'
> List([1,1,2,3,2,1]).uniq().sort()
becomes
> collections.Counter([1,1,2,3,2,1])
for every example you give, there is an equivalent piece of python code to do it, designed in mind with the rest of python. the built in operations give you flexible control over the evaluation too - you can have generator expressions and list expressions. many iterable versions of the standard operators exist in itertools.
really, this is the least pythonic thing since ruby came out. it seems I can only spell this out to you by elaborating through your jquery library and presenting you with python code python developers understand.
please stop re-inventing python without trying to understand why it looks that way first.
Re: Moka - Minimalist functional python library
#20Clickable link for the doc: http://phzbox.com/moka/index.html Moka is still in an alpha stage; but that being said, I'd love to hear some feedback. Feel free to browse the code, it should be pretty straightforward to any python dev.
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 enti…
'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.