func foo(b bool) {
if b {
return
} else {
return
}
}
func bar(b bool) int {
if b {
return 100
} else {
return 200
}
}
func baz(b bool) int {
if b {
return 100
}
return 200
}
func qux(b bool) int {
if b {
return 100
} else {
return 200
}
panic("?")
}
// Error: function [bar] ends without a return statement"Here's this issue in Go bug tracker: https://code.google.com/p/go/issues/detail?id=65
I don't know, maybe I'm just weird, but when I see a comment replied to with a single link patterns suggest that it's a link disproving something. So I got confused until I had read the full page.
For example, I do not see PL/I's choice to make none of its keywords reserved names (IIRC, defended on the argument that one cannot expect anybody to know all the reserved words) repeated much anymore in Algol-like languages.
As another example, IDE/language pairs such as Eclipse/Java have learned us the advantages of languages that are easy to parse and where there is little ambiguity even in incomplete or incorrect programs (it makes syntax coloring easier, and allows for refactoring tools that are somewhat reliable on non conforming source code)
[1]: http://commandcenter.blogspot.com.au/2012/06/less-is-exponen...
You get the point I hope.
I think Go was designed with this in mind? Also, Haskell's type system guards against this. On the other hand C does nothing to prevent you from shooting yourself in the foot and C++, while improving some things, makes it overall worse because of sheer amount of constructs in the language.
Ruby and JS are better in that they run on VMs and so won't segfault (that often), but other than that they do very little to help avoid making mistakes (implicit undefineds passed to functions in JS...).
Anyway, languages are not created equal and one thing a language designer can optimize for is to reduce the probability of programmer making mistake. That's only one of the variables however and sometimes it's the other goals that are more important and then we get languages like C++. That's not to say it's bad, it's just optimized for different things.