
Moka - Minimalist functional python library - phzbOx
https://github.com/phzbox/moka/
======
phzbOx
Clickable 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.

~~~
tef____
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.

~~~
timtadh
What 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.

~~~
tef____
tl;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
No 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.

~~~
tef____
"the semantics of his library are reasonably clear on inspection"

does .remove() mutate in place or not ? depends on the constructor!

this would be an example of breaking composition - you can no longer use a
function built for an immutable list on a mutable list. I am sure I explained
this too.

a dialect is a style, in linguistic terms, if I speak a dialect of english, I
still speak english.

if I needed a different parser/interpreter I am pretty sure that is the stage
of 'new language' where new syntax and semantics are introduced.

the 'dialect' he is introducing is a arc/clojure inspired syntax for what
/already/ exists in python.

thanks for the semantic pedantry! the long and the short of it is that if you
want to write python, write python that looks like python. not like scheme or
clojure.

as someone who gets paid to maintain shitty code, i'd rather people stuck to
the existing idioms of the language, rather than blindly copy paste them from
another language.

~~~
timtadh
"if I needed a different parser/interpreter I am pretty sure that is the stage
of 'new language' where new syntax and semantics are introduced.

the 'dialect' he is introducing is a arc/clojure inspired syntax for what
/already/ exists in python."

No a dialect is another version of the language. For instance python3 is a
dialect of python, just as python2 is. They are not 100% compatible.

"as someone who gets paid to maintain shitty code, i'd rather people stuck to
the existing idioms of the language, rather than blindly copy paste them from
another language."

It is not his problem you see a lot of shitty python. It is also not his
problem if you want every one to stay stuck in the poor design choices that
were made in the stdlib a long time ago. You can fight evolution of languages
or you can embrace them. I don't see you advocating for "thou" in English ;-)

"the 'dialect' he is introducing is a arc/clojure inspired syntax for what
/already/ exists in python."

"syntax" --> no thats is what is defined by the grammar of python. This _is_
python syntax.

"a dialect is a style, in linguistic terms, if I speak a dialect of english, I
still speak english."

No it is a mutation. But I agree with you if you speak a dialect you still
speak the "language." Olde English is still English.

\---

However my main point remains. You are needlessly combative in this thread. He
made a library you attacked him like he insulted the Pope of Python. I am
sorry you maintain shitty Python but you don't need to take you anger about
_that_ out on some poor guy on hacker news.

------
sashahart
Here's a gist comparing the Moka front page example to a slightly more typical
Python way of doing things:

<https://gist.github.com/1380898>

EDIT: using the timeit module on these, the Moka version is about 18 times
slower on my machine... not that this matters much if it's a much nicer way of
expressing the program

~~~
phzbOx
Thanks for sharing. And ya, it's freaking slow right now.

------
ynd
The 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?

~~~
phzbOx
Optimizing for performance is the next big step of Moka and I understand that
it's the breaking point for lots of python developers. So, I'll make sure to
work on that and provide realistic benchmarks.

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.

------
lucian1900
This is indeed minimalist, there's less code in it than I'd expected.

The idioms it introduces do clash with Python ones, but on the other hand,
I've been learning Clojure lately and my Python code has more comprehensions
than previously. I'm not sure what to think.

------
tmcw
Needs a README and examples without a hop.

------
Codayus
This is pretty interesting looking. I'm tempted to try using it on my next
project...anyone else used it yet? Seem stable/bug free?

~~~
phzbOx
It's fairly new but feel free to browse the code; it should be pretty
straightforward to you. I've tried to provide good examples to make it easy to
learn/use on phzbox.com/moka/.

