On the Benefits of Learning Multiple Languages
Developers of VB and C# can learn a lot from the similarities -- and differences -- between the two.
I recollect that the Polish sci-fi novelist Stanislaw Lem once joked that everyone in the world, wherever they lived, could read Spanish. The same might be said to be true of Visual Basic (at least for English speakers), with its natural language syntax. And if you can read VB, reading C# typically isn't much harder. C# and VB.NET share a common framework and many common features; they are far more alike than different, and likely to become more alike than different going forward, according to some of the details released by Microsoft at its latest Professional Developers Conference.
This is no great insight, of course. The languages are similar enough that you can write code in one language and run that code through a translator to get usable code in the other language. I highlight this similarity partly to highlight something that gets less attention: the languages' differences.
In fact, the similarities and differences of C# and VB aren't unlike those of written and spoken languages. Citizens of the United States are notorious for speaking only our native English. Sure, it's possible to get by doing this, as long as you don't leave the country's borders, and even then (outside of Paris) you can probably get by quite well relying on the kindness of strangers. But the advantages of speaking another language are compelling. Apart from the gratification that comes with speaking another language fluently, one of the most important advantages of learning another language is that it tends to teach you much about your native tongue.
The same is true of programming languages. Learning other programming languages can make you more fluent and give you a better understanding of the language you depend on primarily. This is true even of languages as similar to each other as VB and C#.
This is significant because it's not uncommon for developers who use primarily VB or C# to find themselves using the other language for a special project, and sometimes the subtle differences between the two languages can trip developers up. Think of it as the programming-language equivalent of the "false cognate." A false cognate is a word that's similar on the surface to a word in another language, but means something decidedly different. For example, an English speaker might hear the Spanish word embarazo and conclude the speaker was referring to embarrassment; in fact, the speaker would be referring to pregnancy. Or, turn it around and imagine telling someone how pregnant you are when your intent is to describe your embarrassment. In the right (or wrong) circumstances, the miscommunication could be funny or potentially worse.
Such examples abound, whether you're referring to programming languages or spoken and written ones. This issue features a departure from our usual practice where the articles exist independently of one another: Kathleen Dollard and Bill Wagner both touch on the similarities and differences you encounter when programming in VB as a C# developer, and vice versa.
Kathleen Dollard writes about the programming-language equivalents of false cognates in her Ask Kathleen column, when she says:
"There are some annoying inconsistencies between VB and C# in recent features. VB propagates nulls in nullable comparisons the same way TSQL does, while C# returns a non-nullable Boolean type and considers a comparison of something else with null false. Immutability of anonymous types is also different with VB's Key keyword."
In a similar vein, Bill Wagner writes about the differences in how C# and VB.NET enact and support lambdas and closures in his column.
As Dollard and Wagner explored the similarities and differences worth noting in C# and VB, they found enough information to fill out not just their columns for this month, but enough information for follow-up columns, as well. Be sure to check out this month's columns on tips and suggestions for getting the most out of C# and VB, and to watch for future columns that revisit this topic.
Talk Back: What do you think of the announcements related to Visual Studio 2010? Tell me at [email protected] or [email protected].
Patrick Meader is editor in chief of Visual Studio Magazine.