Live data from Hacker News

Coconut: Simple, elegant, Pythonic functional programming

coconut-lang.org

11–20 of 65 posts

Re: Coconut: Simple, elegant, Pythonic functional programming

#11
Those who like clojure/lisp, can try with Hy [1]. The latest version removed Python 2 support, but previous versions would work on Python 2 and 3. Can directly run hy code, compile to pyc or readable python source files.

For functional programming aficionados that still prefer python, don't forget PyToolz [2] or single-source-file underscore.py [3].

[1] https://docs.hylang.org/en/stable/

[2] https://toolz.readthedocs.io/en/latest/

[3] https://github.com/serkanyersen/underscore.py

Re: Coconut: Simple, elegant, Pythonic functional programming

#12
post #5

This is cool stuff, but it's kind of sad that Python doesn't have any of this stuff. Apparently the Pythonic way to do anything is to repeat yourself, type a lot, implement flatten yourself, and cripple lambdas so no one will want to use them. It's a shame, because there's no reason why Python couldn't be an acceptable language for FP, like Julia. It'll never be great at it of course (just like Julia), but good enoug…

While I share your opinions, I disagree with the conclusion. I don't think Python doesn't need anything to survive.

That's misunderstanding who use Python. The majority of people who use Python love Python and swear only by it. Those people are completely fine with the language not changing or not having the same features than modern languages. They use Python because of how easy it is to get the job done. They don't want to learn new features or new syntaxes, they just want to keep using Python the same way they learned it once. All the people I know who swear only by Python have been using it for 5-10 years and they don't know f strings, type hints, asyncio or the walrus operator (and that doesn't stop them from doing their job, and that doesn't make them bad Python developers). Every time a new version of Python is announced, there is a bunch of comments on HN about how Python has been losing its simplicity for years.

Re: Coconut: Simple, elegant, Pythonic functional programming

#13
post #5

This is cool stuff, but it's kind of sad that Python doesn't have any of this stuff. Apparently the Pythonic way to do anything is to repeat yourself, type a lot, implement flatten yourself, and cripple lambdas so no one will want to use them. It's a shame, because there's no reason why Python couldn't be an acceptable language for FP, like Julia. It'll never be great at it of course (just like Julia), but good enoug…

Python is likely to get pattern matching in 3.10, at least: https://www.python.org/dev/peps/pep-0622/

Alas, not as an expression. Just a statement. I couldn't disagree more with that decision.

Re: Coconut: Simple, elegant, Pythonic functional programming

#15
post #5

This is cool stuff, but it's kind of sad that Python doesn't have any of this stuff. Apparently the Pythonic way to do anything is to repeat yourself, type a lot, implement flatten yourself, and cripple lambdas so no one will want to use them. It's a shame, because there's no reason why Python couldn't be an acceptable language for FP, like Julia. It'll never be great at it of course (just like Julia), but good enoug…

Can anything really be done by a single-threaded, GIL-laden, dynamic language trying to compete with a modern, natively parallel, JIT-ed language like Julia? That's a bit apples to oranges, no? Once other languages like Go, Swift, Kotlin, Rust and Julia catch-up with Python's range of data science libraries I'd say Python's days are numbered. Python is the Betmax of programming languages and FP is where the shallowness of its design really shows.

Re: Coconut: Simple, elegant, Pythonic functional programming

#16
post #5

This is cool stuff, but it's kind of sad that Python doesn't have any of this stuff. Apparently the Pythonic way to do anything is to repeat yourself, type a lot, implement flatten yourself, and cripple lambdas so no one will want to use them. It's a shame, because there's no reason why Python couldn't be an acceptable language for FP, like Julia. It'll never be great at it of course (just like Julia), but good enoug…

Functional is my preferred paradigm. I do a lot of work in Python, too, and often find myself rubbing up against Python's less-than-complete support for FP. That being said, I am quite happy that Python does not have most of this stuff. It's good for a language to pick a paradigm, and stick to it. Trying to be all things to all people is the best way to grow a good language into a great big mushball. Python, for its…

you mean has been greatly exaggerated ?

Re: Coconut: Simple, elegant, Pythonic functional programming

#17
post #5

This is cool stuff, but it's kind of sad that Python doesn't have any of this stuff. Apparently the Pythonic way to do anything is to repeat yourself, type a lot, implement flatten yourself, and cripple lambdas so no one will want to use them. It's a shame, because there's no reason why Python couldn't be an acceptable language for FP, like Julia. It'll never be great at it of course (just like Julia), but good enoug…

This is quite a bit of alarmism without acknowledging somewhat recent facts. Python's parser is being updated to allow for richer grammars, the community has embraced gradual typing, and the project hasn't been very conservative for years now. The withdrawal of Guido as BDFL is quite a step in that direction.

Beyond the GIL and the lack of multi-line lambdas, Python is still a pleasant language to start new projects in.

Re: Coconut: Simple, elegant, Pythonic functional programming

#18
post #14

"... compiles to Python"? Am I missing something or shouldn't this just be a library?

They are adding new syntax and keywords, things that you can't really do with a library.

The analog in the JS ecosystem would be typescript. Why isn't it just a library, because they wanted to be able to introduce new syntax and new constructs.

The little editor on the homepage shows the "compile to Python" step if you click the little checkbox. It will list the python that the coconut code gets transformed into. The code is relatively readable (for short snippets) and this is the same approach that typescript took for adding new functionality on top of an existing language.

Re: Coconut: Simple, elegant, Pythonic functional programming

#19
post #5

This is cool stuff, but it's kind of sad that Python doesn't have any of this stuff. Apparently the Pythonic way to do anything is to repeat yourself, type a lot, implement flatten yourself, and cripple lambdas so no one will want to use them. It's a shame, because there's no reason why Python couldn't be an acceptable language for FP, like Julia. It'll never be great at it of course (just like Julia), but good enoug…

You can definitely implement a lot of functional concepts in Python though.

I write Python in a really functional style, and sure I had to define things like `compose` in a module but it works ok.

I find that once code starts getting higher level, you need lambdas less. Ex. You have functions or objects that generate common callbacks you can plug wherever you want.

There's also great functional libraries. Funcparserlib is amazing, and you can wrap sqlalchemy core in a functional way.

Plus there is always Hylang which works perfectly with existing Python code.

You don't have type safety but there's not much stopping you from having a good time with it! At least, in my experience. It's not Haskell though, and never will be.

Post reply on HN