DEV Community

Ben Halpern
Ben Halpern Subscriber

Posted on • Updated on

What language features/concepts do insiders of the language love and outsiders hate?

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?

Top comments (65)

Collapse
 
ben profile image
Ben Halpern

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 of if !thing_is_true is a feature many Rubyists love, but outsiders have a real aversion to.

Collapse
 
evanoman profile image
Evan Oman

Wow, that unless throws me off waaay more than it should.

Collapse
 
ben profile image
Ben Halpern

How do you feel about this:

If I write

[].count == 0

My linter will ask me to change it to

[].count.zero?
Thread Thread
 
evanoman profile image
Evan Oman

wat

Thread Thread
 
6temes profile image
Daniel • Edited

Actually, it your be more idiomatic to write:

[].empty?

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.

Thread Thread
 
ben profile image
Ben Halpern

Yeah, this was a bad example

Thread Thread
 
databasesponge profile image
MetaDave 🇪🇺

But I like #zero?, and have found situations where x == 0 was not "working" and x.zero? was. Don't ask me what it was though – I can barely remember yesterday – but maybe someone can explain that.

Collapse
 
bobbypriambodo profile image
Bobby Priambodo

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.

Collapse
 
databasesponge profile image
MetaDave 🇪🇺 • Edited

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 avoid do_this unless my_model.valid? in favour of do_this if my_model.invalid?.

I think the latter reads much better.

Collapse
 
databasesponge profile image
MetaDave 🇪🇺

if thing_is_false would be better of course.

Collapse
 
val_baca profile image
Valentin Baca

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)

unless has_coffee:
  throw UncaffeinatedDeveloperError()
Collapse
 
blazselih profile image
Blaž Šelih

Coming from Perl, I really miss unless in other languages (I don't use Ruby).

Collapse
 
rpalo profile image
Ryan Palo • Edited
# Python
while True:
    print("4 Spaces, Suck It Braces")
Collapse
 
jacoby profile image
Dave Jacoby • Edited

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.

¯\_(ツ)_/¯

Collapse
 
nektro profile image
Meghan (she/her)

+1 one of the few things I really like about Python

Collapse
 
ghost profile image
Ghost • Edited

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 ;-)

Collapse
 
rickssss profile image
Rick

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

Collapse
 
ghost profile image
Ghost

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.

Collapse
 
theminshew profile image
Michael Minshew

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.

Collapse
 
jacoby profile image
Dave Jacoby

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

@P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{
@p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P[$f^ord
($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&&
close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print

outputs Just Another Perl Hacker is interesting.

Collapse
 
ghost profile image
Ghost

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.

Collapse
 
jakebman profile image
jakebman • Edited

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 with splice. 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.

Thread Thread
 
jacoby profile image
Dave Jacoby

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.

Collapse
 
georgeoffley profile image
George Offley

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.

Collapse
 
promisetochi profile image
Promise Tochi

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:

,,,;

Collapse
 
rickssss profile image
Rick

Who is complaining about Lexical scoping? A bunch of Lisp diehards?

Collapse
 
scimon profile image
Simon Proctor

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.

Collapse
 
promisetochi profile image
Promise Tochi

Lol. No one really. Just necessary to point out what's possible with Prototypal inheritance.

Collapse
 
geoff profile image
Geoff Davis

Love first class functions. I miss that perhaps the most when programming in the other scripting language I use the most: PHP.

Collapse
 
alephnaught2tog profile image
Max Cerrina

...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.:

<?php

$some_function_holding_var = 
        function($inner_arg) 
        { 
            echo "I'm a function saying $inner_arg!"; 
        };

$some_function_holding_var("hello");

// okay, not very random
$random_array = [1,2,3,4];

array_walk($random_array, 
        function(&$number) 
        {
            ++$number;
        });

print_r($random_array);

$pick_func_based_on_time = 
    function ($some_time) 
    {
        $even_function = function () {echo "even";};
        $odd_function = function () {echo "odd";};

        switch ($some_time % 2) 
        {
            case 0:
                return $even_function;
                break;
            case 1:
                return $odd_function;
                break;
            default:
                echo "I broke math...";
                break;
        }
    };

$chosen_function = $pick_func_based_on_time(microtime(true));

$chosen_function();

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.)

Thread Thread
 
promisetochi profile image
Promise Tochi

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

Collapse
 
jfrankcarr profile image
Frank Carr

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.

Collapse
 
ssommerit profile image
Shawn Sommer

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.

Collapse
 
isaacdlyman profile image
Isaac Lyman

LINQ is so elegant. Every time I use it I feel great.

Collapse
 
evanoman profile image
Evan Oman

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 :)

Collapse
 
evanoman profile image
Evan Oman

Followup: Type Inference coming to Java 10 (to be released this year).

Here is the JEP: openjdk.java.net/jeps/286

Collapse
 
restoreddev profile image
Andrew Davis • Edited

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:

<?php

function upper($value) {
    if (empty($value)) {
        return false;
    }
    return strtoupper($value);
}

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:

func upper(value: String) -> String? {
    if value.isEmpty {
        return nil
    }
    return value.uppercased()
}

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.

Collapse
 
einenlum profile image
Yann Rabiller

You can achieve the same now in PHP since PHP 7.1 :)