People tend to love programming languages for the very reason others run away with fear. Whether it's out of familiarity, learning curve or other, what are language features that insiders love and outsiders hate?
For further actions, you may consider blocking this person and/or reporting abuse
Top comments (65)
Rubyists love the expressiveness and readability but I've definitely heard people call it unreadable, or lament that they have no idea what's going on. Readability seems to apply less to folks with strong backgrounds in entirely different areas. Things like
unless thing_is_true
as an option instead ofif !thing_is_true
is a feature many Rubyists love, but outsiders have a real aversion to.Wow, that
unless
throws me off waaay more than it should.How do you feel about this:
If I write
My linter will ask me to change it to
Actually, it your be more idiomatic to write:
I do love Ruby for those things. I can write business code in a way that is perfectly understandable the first time I read it.
Yeah, this was a bad example
But I like
#zero?
, and have found situations wherex == 0
was not "working" andx.zero?
was. Don't ask me what it was though – I can barely remember yesterday – but maybe someone can explain that.As a non-native English speaker, when I read an
unless
on a codebase it gives my brain extra work to make sure when the condition will evaluate to true. It's possible that it is due to unfamiliarity, though.Yes, and the same is true for English speakers as well I think.
I like to avoid
#unless
by ensuring that there is an inverse logical test available, just as#any?
and#empty?
are inverses.I think that some Rails developers don't realise that just as you can call
#valid?
on a model, you can also call#invalid?
, so you can avoiddo_this unless my_model.valid?
in favour ofdo_this if my_model.invalid?
.I think the latter reads much better.
if thing_is_false
would be better of course.It depends on context of course, but in general I tend to disagree. Keeping booleans as the "positive" form seems to make things easier.
I really like to use unless for checking state and arguments at the beginning of methods:
(pseudocode)
Coming from Perl, I really miss
unless
in other languages (I don't use Ruby).First time I tried Python, 2000 or so, was given code that did a thing. I didn't need the thing, I just wanted working Python code to see how/if it worked.
It was indented with tabs.
Somewhere along the line, one of the lines went " \t" instead of "\t".
It took me hours to figure that out.
I know that, w/ 2.7 and 3.5, it no longer would do that. I have tested and proven it.
I still hate it. Hate is emotional, not rational.
¯\_(ツ)_/¯
+1 one of the few things I really like about Python
I love Lisp for the parenthesis and prefix notation. I am a math dunce writing programs to create vector and generative art. Lisp is my calculator and math coach. Clear inside-out order with function/operand appearing first to call out what we're doing makes me feel like I'm pretending to be Russell Crowe, pretending to be a great mathematician in a Beautiful Mind ;-)
Here's one for you: I would like lisp if it wasn't for the dynamic scoping. I appreciate the theoretical / math / lambda calculus reasoning behind it but UGH
Scheme then maybe? I believe it's addressed there; I didn't get to far into Structure and Interpretations of Computer Programs.
Seems to make more sense how I gravitated to Ruby & Lisp.
I enjoy php, I think its just because its the first language I had to do real work with and it felt like it worked the way my brain thinks. Which is scary lol.
For my main language, Perl, the common complaint from the outside is
programmable line noise
, which is kinda funny because most programmers today weren't alive to use modems and experience line noise.I like readable code, even if terse, so I don't do that, but knowing that
outputs
Just Another Perl Hacker
is interesting.I first tried to teach myself to program using Perl. It ha(s|d) the most complete documentation with an expansive library of books and tutorials. I learned a lot about learning to program and asking good questions because of Perl.
On a Monday, I was asked if I knew Perl. I replied that I knew several languages it was based on (awk, sed, Bash) but not Perl exactly. They said "Cool. Your interview is this Thursday. Know Perl by then."
I spent three days on perldoc.perl.org to ace that interview, and found the documentation to be equal parts blunt, refreshing, informative, and horrifying.
Case in point: "If any part of
LIST
is an array, foreach will get very confused if you add or remove elements within the loop body, for example withsplice
. So don't do that."It's common knowledge that modifying the list you're iterating over is a bad idea in almost any language. Safe languages have ways to detect this situation and prevent errors (like Java's ConcurrentModificationException). Unsafe languages trust you to know better. Perl... helpfully tells you not to do that.
I've certainly pushed onto the tail end of a looping array in Perl. You just need to be careful.
But I don't do it anymore.
I learned to program with PHP and JavaScript. I hate them know because I know how neat and logical Python is. It's like having to work with Chekov on a project. You love the guy because he trained you but you've been working with Spock for so long that you're no longer used to the haphazard way he does things.
Javascript:
Prototypal inheritance
Lexical scoping and closures.
The fact that you can construct almost any traditional design pattern with the above.
Closures and first class functions are also powerful instruments in functional javascript.
Also:
,,,;
Who is complaining about Lexical scoping? A bunch of Lisp diehards?
Well I'd say Javascript only recently got proper lexical scoping with
let
before that you had global and function level and all the weirdness that brought about.Plus prototypal inheritance is wonderful and it's a damn shame it confuses so many people.
Lol. No one really. Just necessary to point out what's possible with Prototypal inheritance.
Love first class functions. I miss that perhaps the most when programming in the other scripting language I use the most: PHP.
...doesn't PHP have first class functions? I thought first-class functions meant you could use them as arguments or assign them to a variable, e.g.:
I'm honestly just curious as to if there's a meaning of first-class functions I'm missing. (And enjoyed the chance to do ridiculous code stuff.)
That's pretty much it. First class function means you can use functions wherever normal language primitives will go. It can be returned, used in expressions...
In C#, I'd say it's using generics, delegates, lambda and LINQ. I think it throws some people off so they tend to fall back on the classic programming structures written by hand.
Casting even a wider net, I'm always amazed at how many developers seem to have a mental block when it comes to working with SQL, particularly stored procedures and such.
I remember the first time another developer mentioned LINQ to me...he said it would change my life. I wouldn't go that far, but man...when I moved to writing Apex code it was frustrating not being able to pluck a single (or group)of objects from a list with a single query.
As far as stored procedures go...they confused the heck out of me the first time I encountered them. Then I decided to start tinkering with them in some throw away projects to understand them at least a bit better. I still struggle a bit with joins, but honestly, I really haven't needed to use them much thus far so I pretty much chalk it up to lack of real exposure.
LINQ is so elegant. Every time I use it I feel great.
The "verbosity" of Java (or other statically typed languages).
I love knowing exactly what things are and where they are coming from. Plus it is that same verbosity that allows incredible autocompletion -- meaning that I type a small fraction of the the code in my src folder.
All that being said some type-inference à la Scala is nice too :)
Followup: Type Inference coming to Java 10 (to be released this year).
Here is the JEP: openjdk.java.net/jeps/286
I'm becoming more of a fan of static types after using Swift. I used to hate static types because of the complexity and extra code. Once you get used to types though, it's hard to go back. They add an extra level of documentation to your code and peace of mind that a function/class will only be used a certain way. Here's a non-typed function in PHP:
The problem is that anyone using this function can pass anything into the function. It does not have to be a string, it could be a number or a boolean. Plus, we don't know if the function will return a string or boolean.
We could write the same thing in Swift:
Looking at the signature of this function, we know that it can only be used by passing in a string for the value and that it will always return either a string or nil (the question mark says the return value can be nil). The types make the function safer to use and easier to understand.
You can achieve the same now in PHP since PHP 7.1 :)