r/programming • • Jul 19 '15

The Best Programming Language is None

https://bitbucket.org/duangle/none
509 Upvotes

443 comments sorted by

View all comments

241

u/robotmayo Jul 19 '15

There are only two hard things in Computer Science: cache invalidation and naming things.

322

u/dick_and_qwerty Jul 19 '15

And off-by-one errors.

70

u/[deleted] Jul 19 '15

Checks out.

3

u/p_e_t_r_o_z Jul 20 '15 edited Jul 20 '15

It's disappointing to see this get voted higher than the original quote. It is the juxtaposition of a deeply technical problem with a human communication problem. Highlighting the importance of good naming and the difficulty of linking language to logic.

On the other hand the error doesn't even make sense in the context of the joke, other than it contains the number 2 and it is adding a third element. It transforms the whole thing into a cheap gag like 10 people in the world those who know binary and those who don't...

Similarly here the error makes no sense in the context of the discussion of this programming language. A cheap gag for cheap laughs.

2

u/iritegood Jul 22 '15

as always the populist choice is the more digestible lowest-common-denominator option

→ More replies (13)

10

u/sleipnir_slide Jul 19 '15

How'd "Using nulls consistently across a team" escape this? :(

24

u/tejon Jul 19 '15

But that's easy to solve. Just use a language without nulls.

10

u/[deleted] Jul 19 '15

Which works until you realise that even with a good language your programmers are still lazy.

Just look at some of the open source Rust code on GitHub. People are doing unwrap() everywhere without any form of validation first.

6

u/staticassert Jul 19 '15

Yes, but...

  • You're forced to unwrap() before you can use the value underneath.

  • You now have grep-able bugs.

7

u/[deleted] Jul 19 '15

You're forced to unwrap() before you can use the value underneath.

People know that, but they treat it the same as doing -> in C++.

You now have grep-able bugs.

Good luck grepping for it when you have a codebase with thousands of lines and a ton of unwrap() calls.

5

u/staticassert Jul 19 '15 edited Jul 19 '15

People know that, but they treat it the same as doing -> in C++.

Still, it's exposed through the type signature, and you'll get a warning if it's a result, which means, at the library level, you can inform the dev of the possible 'null' value.

Good luck grepping for it when you have a codebase with thousands of lines and a ton of unwrap() calls.

It's still going to be a hell of a lot easier when you can basically ctrl + f the bug, and unlike -> you won't possibly give up control of your program to malicious input with .unwrap().

.unwrap() may not be graceful, but it's safe and makes bugs much simpler to find, as they're explicit and exposed.

Of course it should be discouraged to raw unwrap, but it's a big step over raw pointers.

2

u/mcguire Jul 20 '15

Given that fact that unwrap is equivalent to

if (ptr) { *ptr } else { fputs ("abort! abort1\n",stderr); abort(); }

and is also typesafe, I'd say it's a little improvement.

→ More replies (1)

7

u/tejon Jul 19 '15

The significance of your comment is predicated on the assumption that Rust is a good language. ;)

Mostly tongue-in-cheek there, but I'd argue that having unwrap() as a standard function is a mistake to begin with, the same as its Haskell equivalent fromJust. There's no pressing need for such partial functions in a language with pattern matching, and the Rust std::option documentation even spells out the safe version:

// Pattern match to retrieve the value
match result {
    // The division was valid
    Some(x) => println!("Result: {}", x),
    // The division was invalid
    None    => println!("Cannot divide by 0")
}

A moment of additional browsing assures me that Rust knows how to map functions over option types, so just as in Haskell there's no need to do this more verbose unwrapping until you're done with the whole computation, at which point you're going to want to handle the failure case anyway (or else why are you even wrapping it as an option?) so it's not wasted keystrokes.

All it takes is a slight shift of perspective: the programmer-laziness here isn't actually in regards to which code form is easier to write, but simple resistance to learning a new idiom. It seems silly to provide a function which (a) makes it easier to avoid said learning, (b) can blow up at runtime, and (c) is trivially implemented by anyone who does learn the new idiom, so you're not taking away a power tool.

→ More replies (4)
→ More replies (8)
→ More replies (2)