top | item 30591023

(no title)

deltaoneseven | 4 years ago

Believe it or not the language you use influences the amount of bugs in the system.

Also your programming technique and style of programming influences the amount of bugs.

Generally to reduce bugs, go with a functional programming style and make sure the language has robust type checking. Functional has a bad connotation in some circles so another way to think about it is to use immutable variables as much as possible. Avoid mutation wherever you can.

This is the first step. The next steps are testing and QA, but most teams have that side covered.

discuss

order

borland|4 years ago

This is true, but not nearly so much as FP advocates make it out to be. Once you reach a halfway decent level of competence in any programming language, most of the bugs that you write will end up being ones where you didn't understand the "requirements" correctly, or where you failed to predict some sequence of actions and account for it correctly. Type systems and immutability provide exactly zero help in situations like this.

It's better to focus on clear and simple code styles and architectures. The goal is that when you're debugging the code or explaining it to someone else, you don't want any situations where things don't make sense, or something happens in a weird order for no apparent reason. Immutability can help here, for sure, but FP is a double edged sword. Sometimes it's fantastic but at others it makes your code into an unintelligible mess.

So yeah: Don't go rushing to rewrite your perfectly functional Java/Ruby/Python app across to Haskell or Clojure. It won't help you much at all. Rather, think about how you might use some of the ideas like immutability and function composition, to make your Java/Ruby/Python app easier to work with.

deltaoneseven|4 years ago

Agreed, but I would go further to say that the type system and immutability helps in the area you describe as well: "or where you failed to predict some sequence of actions and account for it correctly."

Basically immutability serves to create more invariants and reduce complexity of the program such that it is much more predictable.

I'm advocating exactly your conclusion hence the reason why I specified that immutability is the keyword, not monads and other advanced concepts associated with functional programming.