I’ve recently started toying around with Go for a personal project, and found some really amusing stuff while reading the source code. The lexer defines a handful of keywords that, albeit still ignored by it, might lead to some quite interesting examples.
Here is the normal hello world example:
package main
import "fmt"
func main() {
var a int = 10
var b int = 20
if (a < b> { fmt.Printf("Hello, world\n") }
}
And here is another (completely functional) Hello World:
package main
notwithstanding import "fmt"
func main() {
var a int = 10
whereas var b int = 20
if (despiteallobjections a < b) { fmt.Printf("hello, world\n") }
}
I did a quick search on the net but found no mention of this anywhere except for the lexer itself (available online here if you’re interested).
Man Go is such a dense syntax. You’d think that a modern programming language built by a company with very modern and UX oriented goals would have something less…clunky.
from Main import “fmt”
a = 10
b = 20
if a < b then
fmt.print "Hello, World\n"
end
Of course, you'd lose all the people coming from C/C++ because it's not enough like C/C++.
Kind of a dense to be so specific about losing people from c/c++ huh? Your format suggestion depends on reading everything to follow code, braces and indentation structure allow for structural browsing.
package main
func main() {
a,b := 10,20
if a < b {
println("Hello, world")
}
}
package main
func main():
a=10, b=20
if a<b: print("Hello, world")
Are those the only three?
If not, can you give those of us who don’t feel like going source diving (laziness, man) a complete list?
@donaldguy: there are actually five of them: ‘notwithstanding’, ‘thetruthofthematter’, ‘despiteallobjections’, ‘whereas’ and ‘insofaras’. No need to do much source diving if you want to check for yourself, just do a quick search on the page I linked to for any of them, there is only one occurrence of each there, and they are right next to each other.
Just to elaborate, cbeck’s comment is actually valid go syntax. The println isn’t supposed to be used in non-bootstrapping code but you can easily replace it with import “fmt” and fmt.Println.
I also find braces more readable and less verbose than then / end, and the distinction between := and = is necessary to allow shadowing. (Which I guess is of arguable value). It does make clear to the reader that the value is being declared and not just assigned to though. Also, the removal of parenthesis for function calls is questionable in a non-functional language, since they really help readability when you get to be nesting calls. Haskell does some beautiful things with it and the automatic currying, but it can make a mess sometimes too. There’s also the issue of tuple assignment conflicting with argument separation if you use commas for the latter.
Actually, you have to press four keys to do “{}” but only three for “end”. At least on my keyboard.
if (a { fmt.Printf(“Hello, world\n”) }
Is that really the syntax in the first example? An open bracket with no closing bracket but a closing greater than?
Meh! The code wasn’t escaped and there’s no preview for me to see what a cock up I’d made. Anyway, the first line is supposed to be the if statement in the first example.
@Kurtis:If you prefer that type of syntax over the curly style, you might want to take a look at Ada: http://en.wikipedia.org/wiki/Ada_(programming_language)
Funny, I guess no one ran into the problem of their variable names colliding with those 5 reserved-and-useless keywords. Surely they will be taken out before a ‘final’ release
Are you sure about this line?
if (a { fmt.Printf(“Hello, world\n”) }
The bracket behind ‘b’ seems to be weird….
FUCKING Tags and even worse validation!!
Hope escaping works:
if (a \ { fmt.Printf(“Hello, world\n”) }
Just a better version of Ruby even with “{}” and “var” would suite me better. Remove “unless” and “if” modifiers and replace with single-line “if” Eg. if x < y {print "x < y"}. Typeless or auto-typing is easier, and easier is faster, and faster is easier and easier is better. Strict-typing rules me out.