Ask HN: What programming languages produce code most/least prone to bugs? - baccheion
======
mtmail
The relatively new [http://elm-lang.org/](http://elm-lang.org/)
([https://en.wikipedia.org/wiki/Elm_%28programming_language%29](https://en.wikipedia.org/wiki/Elm_%28programming_language%29))
claims "no runtime errors" and the number of compile time checks of variable
types and values is really strict/amazing/well-documented.

That said I tried diving a value by 0 and that threw a runtime error.

~~~
brianwawok
Hah way to beat the system.

No runtime error doesn't make sense. Say your database crashes. Something
should happen...

~~~
deadfoxygrandpa
Well, in Elm you would have to explicitly handle the possiblity of a database
crash and what to do with it. It wouldn't be a runtime error, it would just be
another code path.

~~~
brianwawok
So that was the promise of checked exceptions in Java, and it was TERRIBLE. It
turned into

try { } catch Exception ex { //won't happen }

I am sure elm does better, but at first glance it scares me ;)

------
codygman
Languages such as Haskell which move more logic into the type system are
safer.

A big reason for this is that the errors are more often than not at compile
time.

I'm the real world this means you deal with a bug after trying to compile,
rather than an intern 8 months later trying to fix a runtime error, who is
struggling to understand the codebase, much less make a good bugfix that also
takes backwards compatibility into account.

------
squiguy7
This is an extremely loaded question. With that being said I think it's
obvious that any languages with weak typing and a dynamic runtime will be more
prone to hidden errors. Compilers are getting much more impressive in how they
can catch common errors for static languages.

So those languages that try and protect the programmer the most will generally
produce better code.

------
bbcbasic
Coq. Mathematical proof it works then generates the Haskell. Not exactly a
rapid application development tool though.

------
drallison
WizardlySquid's comment below was greyed out, probably in error. I have
fetched it out of limbo because the point being made is cogent and important.

 _WizardlySquid 1 hour ago [dead]_

 _Languages don 't create bug, people create bugs and there will always be
bugs. Instead of looking for the new hotness just study your chosen language
more, carefully research your problem, spend more time designing your system
to be fault more tolerant and test the system to find the bugs you do have. If
we're talking only about languages introducing bugs it's best to have a mature
language that works best for your problem and that you are proficient at._

I agree. Programming languages are tools. They help structure problem solving.
They provide convenient notations. They have hidden gotchas (sometimes). Some
languages may be a better match to a particular problem than another.
Programming languages are not a substitute for thought, careful design, and
analysis. Language flame wars, endless comparisons, strong assertions of
language goodness, and anecdotal tales of greatness are fun to read, sometimes
provocative, but in the end remain (for me) unconvincing.

------
setra
Haskell, and Rust tend to be pretty safe.

------
bjourne
Essentially every language claims to be that one. Python, Haskell, Scheme,
Java, Erlang, Rust .. There is no true answer yet.

 _MY_ answer though is Factor
([http://factorcode.org/](http://factorcode.org/)). Why? Because the length of
the source code is about half the length of the equivalent program in Python
or Scheme. And I'm absolutely sure (although it is an unproven belief) that
the shorter the code, the less bugs there will be hiding in it.

------
dreamdu5t
Try PureScript! It's type-checked and purely functional (no crashes or runtime
errors) and compiles to JavaScript. You can use it reasily with webpack too.
I'm using it in production and it's amazing. Check out
[http://www.purescript.org](http://www.purescript.org) and build React UIs
using [http://alexmingoia.github.io/purescript-
pux](http://alexmingoia.github.io/purescript-pux)

------
hacknat
I'm surprised Rust hasn't been mentioned. Its borrower memory management
pattern, and its requirement of declared mutability prevent most of the most
severe security bugs that C, et al, fall prey to.

------
WizardlySquid
Languages don't create bug, people create bugs and there will always be bugs.
Instead of looking for the new hotness just study your chosen language more,
carefully research your problem, spend more time designing your system to be
fault more tolerant and test the system to find the bugs you do have. If we're
talking only about languages introducing bugs it's best to have a mature
language that works best for your problem and that you are proficient at.

~~~
stonemetal
>Languages don't create bug

No but they allow certain classes of bugs to be written.

>people create bugs and there will always be bugs.

To true, but I take that to a completely different place. Some languages
require super human amounts effort to avoid bugs that are easily machine
checkable, or the language could offer tools that don't even make such
situations possible. Picking a safer language allows you to spend some of your
bug avoidance effort in a more profitable way.

~~~
AnimalMuppet
> >Languages don't create bug

> No but they allow certain classes of bugs to be written.

True. And, for some categories of bugs, there are other languages that do not
allow those categories of bugs to be written. But be careful not to read too
much into that. Those languages may _also_ allow _other_ categories of bugs to
be written, or to be written more easily.

Do not assume that avoiding the previous generation of bugs means that your
code is safe.

