Syntax Stupid Idea

I’m a big fan of English-like programming syntax. I love that Ruby has an unless operator and that both it and if can be put after the statement, like

do_this if this


do_this unless that

. I also like Javascript’s this word. I’d like to see all the prepositions in English utilized. How about a neither … nor expression syntax?

Okay, so the thing I want at the moment is demonstrative pronouns. We’re always testing a variable and then doing something with that variable. That sounds like that. How about this, then?

if hash[:key][:another_key] == "some value"
  puts hash[:key][:another_key] 


if hash[:key][:another_key] == "some value"
  puts that 

Granted, you could just assign the long value lookup to a variable, which gives more readable code. In fact, hell, you should always do this. I still want this construct. I can be talked out of it, though. What I’m more hot for is this construct:

$variable = $blah["key"]["another_key"] ? $blah["key"]["another_key"] : "default value";

# vs.

$variable = $blah["key"]["another_key"] ? same : "default value";

Cuz repeating the tested variable in a ternary just feels stupid, even when you’re using a well-named variable, amiright?

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s