DEV Community

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

Ben Halpern on February 06, 2018

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?

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

Collapse
 
mortoray profile image
edA‑qa mort‑ora‑y

C++ Templates: Simply the most powerful language feature of any language, nothing else comes close. Just requires a few sacrifices to Cthulu to fully understand.

Collapse
 
twof profile image
Alex Reilly

Optionals in Swift.

When I first started learning the language, I didn't understand at all why I'd want to decide if a value could be nil or not. It just felt like extra unneeded complexity, but after writing Swift for over a year, it's soooo much easier to reason about code when you can be sure you don't have to think about an entire set of fail cases.

It's also fantastic when you can take an optional, unwrap it at one level, and never have to worry about it being nil again no matter where you pass the value.

Collapse
 
evanoman profile image
Evan Oman

I'm assuming they are similar to Option in Scala and Optional in Java? If so, they are amazing.

Collapse
 
twof profile image
Alex Reilly

Yup! Exactly that, but they're supported at the language level and every variable is, by default, not optional.

So if I write var foo: Int = 0, I can be sure that foo will never be nil, because if I write code that even places foo at risk of being nil, my program won't compile! Pretty awesome stuff.

Collapse
 
francisco profile image
Francisco M. Delgado

I also like the guard statement in swift.

Collapse
 
maestromac profile image
Mac Siri

Ruby's Block, Proc, and Lambda are funky things. Took me a while to understand them and I still barely use it.

Collapse
 
kspeakman profile image
Kasey Speakman • Edited

Functions are so central to functional programming that they get their own operators. This demonstrates function piping and composition:

-- basic version of a function with 3 steps
-- takes in a string which is supposed to be numeric
-- and creates a list of integers up to that number
createRange str =
    List.range 1 (Result.withDefault 0 (String.toInt str))

-- the problem above is that it reads inside-out
-- this piped equivalent reads just like my brain thinks of the steps
createRange str =
    str
        |> String.toInt
        |> Result.withDefault 0
        |> List.range 1

-- composed "point-free" equivalent
createRange =
    String.toInt >> Result.withDefault 0 >> List.range 1

The last one is considered hard to understand at first. >> takes the output of the first function and provides it as an input to the second. Basically welding the functions together into one.

Collapse
 
rickssss profile image
Rick

People who learned Ruby or JS as their first languages they really knew mostly love to use the standardjs-style trait of no-semi:

console.log('I KNOW ASI EDGE CASES AND REFUSE TO USE THE CURSED ½: !!!!')

Also, I think Haskell is the most beautiful language ever but lots of folks thinks its unreadable. I really don't get this. I always tell them: just treat it like you're reading math functions. I figured it would help but no one really knows what a math function is.

On the other hand, there is so much weird stuff in Swift that I hate, I imagine it is leftover from the Objective-C heritage. Some things that might be syntax sugar for old awful Objective C syntax might be lovely to old-hand devs but not me.

Collapse
 
perttisoomann profile image
Pert Soomann

For PHP the way isn't (wasn't) very type strict, and you could implement your own handle logic, based on method return value:

$result = $myClass->save();

if (is_array($result)) {
    // Validation errors!
    // Warnings are returned in structured array, where indexes are class attributes
    // Example:
    // $result['firstname'] = 'First name is required'
    // $result['email'] = 'Email address must be valid' 
} elseif (is_numeric($result)) {
    // New record created!
    // Method returns newly created database row ID
} else {
    // Record updated!
    // Method returns TRUE
}

I have to admit I've kind of converted to returning TRUE or FALSE, and implementing another method to get errors, if save failed using $errors = $myClass->getErrors(), but it was still nice shortcut, purely because PHP didn't enforce explicit return types.

Collapse
 
stoicperlman profile image
Sam Kleiner • Edited

Python variable scope inside an if statement.

if True:
    var = “something”
print(var)

This runs just fine. No need to declare outside of if block. Complete opposite of the verbosity of Java.

Collapse
 
evanoman profile image
Evan Oman

But var doesn't exist on line 3!! I know different rules for different languages, but allowing this would drive me crazy (esp. if you are just saving an explicit var = null statement)

Collapse
 
idanarye profile image
Idan Arye

Then you'll love this:

with open('foo.txt', 'w') as f:
    f.write('hello world\n')
f.write('also hello world\n')  # f is closed by still in scope!

Thing is, with dynamic languages this doesn't really matter - it's not like if it had stricter scoping rules it'd fail to compile...

Collapse
 
dfockler profile image
Dan Fockler

Using functional style shorthand blocks { |i| puts i } in Ruby to make really nice one-liners to manipulate data structures.

I haven't used them very much but, Rust's traits are a really interesting way of building interfaces that are composable and clean.

Collapse
 
cess11 profile image
PNS11

S-expressions and dynamic binding.

They say "parentheses" but they mean the equivalence of code and data. They also say "unsafe" but they mean that they aren't used to decide themselves how and when and why evaluation happens, or to lock down the application by formal design.

Sometimes there's also a performance argument, usually it doesn't take development time into account or assumes the product will run forever without further work ever again.

Probably logic inference too, the original 'lazy generator both ways evaluating' programming style, that is used to query the database.

With great expressiveness comes great power and great responsibility, but also freedom.

picolisp.com

Collapse
 
6temes profile image
Daniel

Guys, please, don't use Metaprogramming in business logic.

Extract it to a library and put it behind a clear abstraction.

Collapse
 
shuzootani profile image
shuzo • Edited

I think Ruby is like natural language that I can communicate with ruby instead of natural language on a daily life.

after all, all my friend become able to write ruby or only rubist is your friends ?
That's why I am learning Javascript.

 
6temes profile image
Daniel

Sad but true.

Or you can view it from the other perspective: a good developer who can write clean code will never have problems to find good jobs. ;)

Collapse
 
alainvanhout profile image
Alain Van Hout

Java: the inherent verbosity. Or as I see it: the increased difficulty against making dense and inscrutable code.

Collapse
 
xngwng profile image
Xing Wang

everything in scala

Collapse
 
andrewchou profile image
Andrew Chou

I like explicit error-handling in Go, and I'm not as annoyed by the lack of generics in the language as most people are.

Collapse
 
hrmny profile image
Leah • Edited

Always rust

Generics and actually explicit error handling

Collapse
 
idanarye profile image
Idan Arye

explicit error-handling

Is that how they marketed their C-style errors?

Collapse
 
crazy4groovy profile image
crazy4groovy

Groovy has operator overloading. Oh, and metaclass overrides. Powerful but dangerous! Love it

Collapse
 
rbanffy profile image
Ricardo Bánffy

Python for the whitespace. Ruby for the irregular but expressive syntax. C for the bare-bones language. Smalltalk for the language merged with IDE merged with OS and the underlying VM.

Collapse
 
xowap profile image
Rémy 🤖

Ruby. The whole thing.

Collapse
 
rhymes profile image
rhymes
  • Python's lists comprehensions
  • Javascript as a whole :-D
  • Erlang syntax
Collapse
 
blouzada profile image
Bruno Louzada

Groovy no return in last method line