Log In

Matt Briggs

"Not all code needs to be a factory, some of it can just be origami." - _why, the lucky stiff

How To Freak Out Static Language Users

programming
by Matt Briggs on 12/09/09

I have worked professionally for several years in both Java and C#. Enough time to get to know the quirks of each community, and get an understanding of the languages. One thing that always irked me in Java that I found refreshingly not there in C#, is this hatred of anything new. There has been discussion about introducing closures for years in the java world, but people just don't want to see it. They say the whole anonymous class thing they do now means they don't need a feature like that, while completely ignoring all the things that closures can be used for which anonymous classes won't work on.

By contrast, MS goes on stage at a PDC and introduces something like LINQ, which is a pretty invasive change into the language, and everyone cheers. To go back to the closures example, they already had function pointers, but the introduction of lambdas was met with great joy. In fact, it is hard to think of a single language feature or library that people didn't fall head over heels for (even when it was already implemented better elsewhere, or just plain sucked), until Anders started messing with types.

Don't you dare touch my types

It started with .net 3.5, with the introduction of the var keyword. For those who don't know C#, var is some extremely basic type inference, a concept that has been around at least for 30 years now. The idea is that in cases where the compiler can figure out the type at compile time, don't force developers to pedantically write it out. Static languages tend to be very verbose, so this kind of thing is pure gold. It will shorten something like this

Dictionary someContrivedVariableName = new Dictionary();

into

var someContrivedVariableName = new Dictionary();

Granted, this is a contrived example. But in what world is the first more clear then the last? You would think that it is something that would only upset people who enjoy pointless typing. But that didn't happen, the same people who loved LINQ, freaked the hell out at var. As Phil Haack put it, it was something along these lines

"My friend used the var keyword in his program and it formatted his hard drive, irradiate his crotch, and caused the recent economic crash. True story."

When I saw var I was like, "Man, why couldn't they have done inference for method signatures or properties?", everyone else was freaking the hell out.

Bad vs Unfamiliar

I think this is the real problem. Even in a community that is willing to accept change, something like the type system is a fundamental part of how you read and write code. It's not some new library, it changes the way you think about things. Because of that, people look at things like var (and now dynamic), and see something they can't read the same way. Since they have a high proficiency in their language of choice (and little to none in others), they fall into the blub programmer trap

"As long as our hypothetical Blub programmer is looking down the power continuum, he knows he's looking down. Languages less powerful than Blub are obviously less powerful, because they're missing some feature he's used to. But when our hypothetical Blub programmer looks in the other direction, up the power continuum, he doesn't realize he's looking up. What he sees are merely weird languages. He probably considers them about equivalent in power to Blub, but with all this other hairy stuff thrown in as well. Blub is good enough for him, because he thinks in Blub."

New Languages

I have no idea who said it, but there is sort of a meme going around that programmers who want to improve their craft should try to learn a new language a year. Each time you do this, it will force you to think about code in a new way. Each time you do that, it becomes easier to evaluate language features and libraries based on their merit, rather then on their familiarity.

Back to var

Back to the var keyword, it is very easy to find examples that are obvious improvements to code readability. The other side of the argument often brings up

var thing = DumbName.GetSomething();

vs

Person thing = DumbName.GetSomething();

In the second case, it is obvious what is happening, and the first case removes that clarity. What I say to that is that if you cannot tell what is going on from the call or the variable name, then you are using the type name as a crutch, and you need to use better names for things. It is possible to come up with an example where var will directly lead to a reduction in clarity, but those cases should be considered failures in inspiration or architecture, not the norm.

my code blog.

what I am reading

Sidebar_clean_code

the people I follow

  • 24 ways
  • ABtests.com - Learn. Share. Improve your conversions today.
  • Ajaxian » Front Page
  • Alex Young
  • BEST IN CLASS
  • briancarper.net (λ)
  • Carbonica Blog Feed
  • Catalog Living
  • Clients From Hell
  • Clojure/core Blog
  • code is code
  • Coding Horror
  • CSS-Tricks
  • Daily Vim: Text Editor Tips, Tricks, Tutorials, and HOWTOs
  • David Chelimsky
  • dean.edwards.name/weblog
  • DHTML Kitchen News
  • disclojure: all things clojure
  • Edge Rails.info
  • End of Line
  • English - AkitaOnRails.com
  • Err the Blog
  • Evil Monkey Labs
  • Extra Cheese
  • Extra Cheese
  • For A Beautiful Web
  • Francis Hwang's site
  • Free Ruby and Rails Screencasts
  • Giles Bowkett
  • Hacker News
  • has_many :bugs, :through => :rails
  • Higgins for President
  • HTML5 Doctor
  • Information Is Beautiful
  • It's an all-you-can-leet buffet !
  • Jay Fields' Thoughts
  • JGUIMONT>COM
  • John Barnette
  • John Resig
  • K. Scott Allen
  • Katz Got Your Tongue?
  • Kirby's Dreamland
  • Kotaku
  • Kotka
  • Lambda the Ultimate - Programming Languages Weblog
  • Lazycoder
  • Loud Thinking by David Heinemeier Hansson
  • LukeW | Writings on Digital Product Strategy and Design
  • mir.aculo.us
  • MongoTips by John Nunemaker
  • Moonbase
  • No Strings Attached
  • Nuby on Rails
  • Official jQuery Blog
  • ones zeros majors and minors
  • opensoul.org by Brandon Keepers
  • Painfully Obvious
  • Painfully Obvious
  • Particletree
  • Paul Irish
  • Perfection kills
  • Plataforma Tecnologia Blog » English
  • Rails on PostgreSQL :
  • Railscasts
  • RedFlagDeals.com - Latest Deals
  • Relaselog | RLSLOG.net
  • remy sharp's b:log
  • Riding Rails - home
  • RightJS News
  • rmurphey
  • Room 101
  • Rubinius Blog
  • Ruby Best Practices
  • Ruby Inside
  • Ruby Quicktips
  • Ruby treats women as objects
  • RubyFlow
  • Signal vs. Noise
  • Slash7 with Amy Hoy - Home
  • Smashing Magazine Feed
  • Snail in a Turtleneck
  • Software Craftsmanship – Katas
  • St. on IT
  • Stevey's Blog Rants
  • Technomancy
  • Tender Lovemaking
  • Test Obsessed
  • Zed Shaw
  • The CSS Ninja
  • The GitHub Blog
  • The MongoDB NoSQL Database Blog
  • The Napkin ~ A Blog By Highgroove Studios
  • The UX Booth
  • The Word of Notch
  • the { buckblogs :here } - Home
  • Thoughts From Eric
  • Uncle Bob's Blog
  • VIM Tips Blog
  • Virtuous Code
  • Web Designer Wall - Design Trends and Tutorials
  • Wow! eBook - Great ebook, great site!
  • #<Mongoid::Criteria:0xb38bcc8>
profile for Matt Briggs at Stack Overflow
Feed
atom 1.0

mattcode.net stack

Rightjs
Rails
Mongo
Dropbox