Skip to content

Instantly share code, notes, and snippets.

@tomassedovic
Created February 13, 2012 10:01
Show Gist options
  • Save tomassedovic/1815639 to your computer and use it in GitHub Desktop.
Save tomassedovic/1815639 to your computer and use it in GitHub Desktop.
Optional semicolons -- more common than generally thought
// optional semicolons in Go
package main
import "fmt"
func greet_with(name string) {
fmt.Println("Hey there,", name);
};
func greet_without(name string) {
fmt.Println("Hey there,", name)
}
func main() {
greet_with("Thomas");
greet_without("Thomas")
}
// optional semicolons in JavaScript
function greet_with(name) {
console.log("Hey there, " + name);
};
function greet_without(name) {
console.log("Hey there, " + name)
}
greet_with("Thomas");
greet_without("Thomas")
# optional semicolons in Python
def greet_with(name):
print("Hey there, {}".format(name));
def greet_without(name):
print("Hey there, {}".format(name))
greet_with("Thomas");
greet_without("Thomas")
# optional semicolons in Ruby
def greet_with(name);
puts "Hey there, #{name}";
end;
def greet_without(name)
puts "Hey there, #{name}"
end
greet_with("Thomas");
greet_without("Thomas")
# optional semicolons in Bash
function greet_with {
echo Hey there, $1;
};
function greet_without {
echo Hey there, $1
}
greet_with "Thomas";
greet_without "Thomas"
;; "optional semicolons" in Clojure
(defn greet-with [name];
(println "Hey there," name));
(defn greet-without [name]
(println "Hey there," name))
(greet-with "Thomas");
(greet-without "Thomas")
;; Yes, this does in fact constitute cheating ;-)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment