10 ms·
> In a language with less features, you might have to write slightly more code, but the code you write will be more readable to everyone else. I disagree with
by RhodesianHunter 7y ago
> In a language with less features, you might have to write slightly more code, but the code you write will be more readable to everyone else.
I disagree with this, which is precisely why I prefer feature rich languages like Java or better yet Kotlin. It doesn't get much more readable than something like:
users.asSequence()
.filter { it.lastName.startsWith("S") }
.sortedBy { it.lastName }
.take(3)
Now try writing that in Go or Python and compare the readability.
- mehrdadn 7y agoA little off-topic but how does that work? Is 'it' a magic variable referring to the first argument? Never seen magic variables that blend into lambdas like that before... would've expected $1 or something like that.
- kragen 7y agoYeah, a bit of PG’s Arc influence in the wild.
- riffraff 7y agoI believe groovy made this popular rather than arc, and it's likely where kotlin's come from, due to being in the java ecosystem.
- jnordwick 7y agoMost apl deviatives (j, k, q, a) all had implicit arguments for functions that didn't explicitly declare them (up to 3: x, y, and z). Probably before then too.
- kragen 7y agoDyalog APL too, but none of them call the implicit argument "it".
- kragen 7y agoGroovy is from 2003. PG keynoted PyCon in 2003 talking about his progress on Arc: http://www.paulgraham.com/hundred.html http://www.paulgraham.com/hundred.html. He had been talking about Arc online for a couple of years at that point, including in particular the convenience of "anaphoric macros" that defined the identifier "it" as an implicit argument. (He'd also written about that more at length in the 1990s in On Lisp, but many more people became acquainted with his language-design ideas in the 2001–2003 period, thanks to Lightweight Languages and his increasingly popular series of essays.)
- earthboundkid 7y agoBut surely Perl's $_ was way more influential than an obscure PG talk. I was reading PG way back in 2004, and I had never heard of anaphoric macros until now.
- kragen 7y agoWait, you think that, in the context of programming language design, a PyCon keynote is an obscure talk? I don't know what to say about that. It might be possible for you to be more wrong, but it would be very challenging. Anyway, I'm talking specifically about the use of the identifier "it" in Kotlin, not implicitly or contextually defined identifiers in general, which are indeed a much more widespread concept, embracing Perl's $_ and @_, awk's $0 (and for that matter $1 and $fieldnumber and so on), Dyalog APL's α and ω, Smalltalk's "self", C++'s "this", dynamically-scoped variables in general, and for that matter de Bruijn numbering.
- earthboundkid 7y ago> a PyCon keynote is an obscure talk Compared to the existence of Perl, yes. Anyone who does any amount of Perl learns that $_ is the implicit argument ("like 'it'") to most functions. It's pretty much one of Perl's main deals. The talk has about 100K views on YouTube, which is pretty good, but Perl is in another league.
- vorg 7y agoToo bad Apache Groovy itself didn't remain popular after popularizing the name "it" for the much older idea of contextually-defined pronouns in programming languages. Using the names of pronouns in English (like "this" and "it") is easier for an English-speaking programmer to understand than symbols like "$1" or "_". But because of Groovy's bad project management, another programming language (Kotlin) is becoming widely known for introducing the "it" name.
- sls 7y agoThe idea of anaphoric macros[1] is first found in Paul Graham's "On Lisp"[2] and is based on the linguistic concept of anaphora, an expression whose meaning depends on the meaning of another expression in its context. An anaphor (like "it") is such a referring term. I think if you like this idea, you will really like the book. Better still, you can download the pdf for free. [1] https://en.wikipedia.org/wiki/Anaphoric_macro https://en.wikipedia.org/wiki/Anaphoric_macro [2] http://www.paulgraham.com/onlisp.html http://www.paulgraham.com/onlisp.html
- RhodesianHunter 7y agoInside of any lambda that takes a single parameter you can refer to the parameter as 'it'. If you prefer to name your parameters you can do so as well, it's just slightly more verbose: users.asSequence() .filter { user -> user.lastName.startsWith("S") } .sortedBy { user -> user.lastName } .take(3)
- strokirk 7y agosorted(u for u in users if u.last_name.startswith("S"), key=lambda u: u.last_name)[:3] Though I will conceed that I also find the fluent interface variant nicer.
- mehrdadn 7y agoThat doesn't parse :-)
- kragen 7y agoPython is a little more readable, but both Python and Kotlin are perfectly clear in this case: sorted((u for u in users if u.last_name.startswith("S")), key=lambda u: u.last_name )[:3] If last_name is a function, which it often would be in Python, it gets better: sorted((u for u in users if last_name(u).startswith("S")), key=last_name )[:3] However, I think you probably got the sort key wrong if you're taking the first three items of the result. Maybe you meant key=abuse_score, reverse=True, or something.
- elcritch 7y agoI disagree this python version is as readable and here’s why. It’s about as many characters but more complex. The Kotlin version performs several distinct actions, each being clear to its purpose. These actions have the same syntax (eg requires less parsing effort). The Python version mixes at least 4 different language syntax/features, being list comprehension, if special form in the list comprehension, keywords, and lambda functions. On top of the lessened readability, the Kotlin version makes it very easy to add, subtract, or comment out lines/actions which really helps when debugging. The Kotlin version is almost identical in structure to how you’d do it in Rust, Elixir, etc.
- brodsky 7y agoI agree. I don't know Kotlin and am reasonably well versed in Python, yet I immediately grasp the Kotlin example as more readable, while having to squint at the Python one for a few seconds. (this is anecdotal of course, and does not account for the example possibly being contrived)
- HelloNurse 7y agoOne thing that I like more in the Python version is that it contains less names: .asSequence and .take are replaced by operators of much greater generality, while the ugly implicitly declared identifier it is replaced by explicitly deciding that sequence elements are u. It should also be noted that Python would allow a more functional style, possibly leaving out the list comprehension.
- 7y ago
- goatlover 7y agoPretty sure the Go community will be fine with not being feature rich, since simplicity, maintainability and getting new people up to speed matter more for them.
- tonyedgecombe 7y agoThe go community have gone to far the other way for me, the endless repetition introduces its own complexity.
- sooheon 7y agoSimple core languages that are syntactically extensible with libraries have the best of both worlds: https://vvvvalvalval.github.io/posts/2018-01-06-so-yeah-about-clojures-syntax.html#separation_of_concerns:_code_layout_⊥_program_structure https://vvvvalvalval.github.io/posts/2018-01-06-so-yeah-abou...
- andrewshadura 7y agoYou’re doing it wrong :) users.apply { asSequence() filter { it.lastName.startsWith("S") sortedBy { it.lastName } take(3) } (totally untested)