Though I've become agnostic about the utterly meaningless non-choice between VB.NET and C#, the inherited syntax of C leaves a lot to be desired, in my opinion. And not just in the case sensitivity department. Daniel Appleman, in his excellent e-book, VB.NET or C#, Which to Choose?, concurs:
Here I risk stepping on some toes, because language syntax is very much a religious issue with many programmers. Certainly we all tend to prefer the language syntax we are familiar with, and C++ and Java programmers will certainly find a great deal that is familiar in C#.It should also be clear from this section that the differences between the two languages in this area really are minor. Both have virtually the same functionality.
Nevertheless, on the subject of object syntax, I must give the win to VB.NET. Just look at the inheritance declarations:
public class BClass: AClass, Iint Public Class BClass Inherits AClass Implements IintLook at the words used to control inheritance:
abstract, sealed, virtual MustInherit, NotInheritable, Overridable, Overrides, ShadowsWhen it comes to looking at code and understanding what it does -- especially later on when the original developer has left and some young programmer right out of college has to figure out what it does quickly to solve some obscure bug or add a new feature, which one is going to be easier to understand? Visual Basic .NET.
Although I do agree with Appleman on this point-- void is for sci-fi geeks; nothing is for human beings-- in the big scheme of things, it's barely relevant. If the success or failure of your project hinges on the minor syntax differences between two virtually identical .NET languages, you have much deeper problems than choice of language.
Although the tradeoff between verbosity and succinctness is worth considering, there are other risks here. Computer languages, however verbose you make them, shouldn't try to become proxy versions of spoken languages. I've never worked with AppleScript before, but it fell into this trap in a big way. Here's a sample bit of AppleScript code to illustrate:
tell application "Mori"
tell front document
set a to first item of selection
set b to second item of selection
set a's note to (a reference to a's) note & (a reference to b's note)
end tell
end tell
Looks almost like a paragraph, doesn't it? John Gruber calls AppleScript the English-Likeness Monster:
The idea was, and I suppose still is, that AppleScript's English-like facade frees you from worrying about computer-science-y jargon like classes and objects and properties and commands, and allows you to just say what you mean and have it just work.But saying what you mean, in English, almost never "just works" and compiles successfully as AppleScript, and so to be productive you still have to understand all of the ways that AppleScript actually works. But this is difficult, because the language syntax is optimized for English-likeness, rather than being optimized for making it clear just what the f**k is actually going on.
This is why Python and JavaScript, two other scripting language of roughly the same vintage as AppleScript, are not only better languages than AppleScript, but are easier than AppleScript, even though neither is very English-like at all. Python and JavaScript's syntaxes are much more abstract than AppleScript's, but they are also more obvious. (Python, in particular, celebrates obviousness.)
AppleScript's natural language metaphor turns out to be more of a curse than a blessing.
Some languages are arguably more readable than others, of course, but keeping the goal of clarity front and center is far more important than bickering about relatively meaningless language choices. You can write FORTRAN in any language, so choose whatever language you're most comfortable with and optimize for making it clear what the f**k is going on.
(I thought about letting the f-bomb drop in this post for emphasis, but my fireball isn't quite as daring as John Gruber's.)
i've never used AppleScript, either, but if it's not COBOL in lower case; it's hard to imagine what else could be. gad.
buggyfunbunny on September 3, 2006 7:28 AMYeah, but in some languages writing FORTRAN-style code is considered the epitome of good practice.
Assembler?
APL?
Intercal?
Brainf*ck?
Tyrannicus on September 3, 2006 8:51 AMI have some experience with AppleScript, and it's as bad as it seems. But.
The problems of AppleScript are not inherent in the fact that it tries to mimic natural language. It does so poorly and incompletely and with ill-defined boundaries, and that makes it look bad. It has other, more serious, problems; the specific one I remember is that support for it is application-dependent; application developers are (or were - it's been a long time) required to define their own dictionaries and implement language support themselves. Some, needless to say, did a better job than others.
What was tantalizing and mind-blowingly frustrating about trying to use AppleScript is how much it looked like HyperTalk - the successfully English-like language of HyperCard. HyperTalk really did read, on occasion, like poetry. It was entirely application-specific, and the only classes were predefined. It was interpreted and occasionally confusing. And it drew a lot of amateur programmers in and they wrote a lot of amateur programs. But on the whole I have to say it was a genuine success as a language.
Carl Manaster on September 3, 2006 8:57 AMI don't see what's not clear, or verbose enough, about the following. It's concise.
public class BClass: AClass, Iint
The VB.NET version is like the above but with comments:
// BClass Inherits from AClass and Implements Iint
public class BClass: AClass, Iint
Which is completely unnecessary and too verbose. Just like the VB.NET syntax. It's like the rule of not commenting exactly what the code is saying:
i = i + 1; // add one to i
"Though I've become agnostic about the utterly meaningless non-choice between VB.NET and C#, the inherited syntax of C leaves a lot to be desired, in my opinion."
C (as you'll know) never had inheritance or interfaces. I don't see why it wouldn't have been possible to make C# be more verbose, like the VB.NET style inheritance/interface syntax. I think C++ is the guy you'll want to point a finger at. :)
The inheritance syntax is one area where I wish C# had ripped of Java a little more.
On the other hand, in this age of AJAX development, sticking with the mostly-consistent JavaScript/C# syntax actually makes a lot of sense.
Kevin Dente on September 3, 2006 10:30 AMRead a funny post on VB/C# by Rob Howard a while back, and he pullod out a quote I just love from Rocky Lhotka of CSLA fame:
"Basic was designed specifically to cater to the way people think. C-style languages were designed specifically to cater to the way machines work"
Interesting! You can read more of Rob's post here:
http://weblogs.asp.net/rhoward/archive/2005/12/07/432579.aspx
I use C# simply because the structure of it is easier to navigate, mostly because I don't READ code, I see it in my mind (blond... brunette... readhead) as patterns of execution. Your point about language is spot-on: coding is instruction, not prose. Though the fusion of both would be pretty damn cool :).
The flaws in AppleScript's english-like syntax are obscured by its many other flaws, such as the compiler that not only *changes your source code* (as if that wasn't bad enough), but *changes it in a way that no longer compiles*.
http://girtby.net/articles/2005/05/05/automated-bug-generation
In general though I take your (and Gruber's) point. The although the word "nothing" is more common in natural language, it does not by any means capture the sematics of what we programmers call void - so having a separate word for "void" is a good thing. Computer languages are different to human languages because they are used to describe different things.
You know, this post reminds me of someone I heard once who actually believed that COBOL was the only true, high-level language because it was the most English-like... absolutely ridiculous.
David on September 4, 2006 2:35 AMIn the UK, at least, many (most? not sure) of the higher end of the old VB community, of which I was a member since VB 1 was released, have migrated to C# through choice, despite the obvious superiority of VB.NET in places, including those you already mentioned.
I think a possible reason for this is that they (we) just kept tripping up over the .NETty aspects of the new VB, to the extent that they (we) were frustrated by the differences. C# on the other hand, was sufficiently different - and so much more accessible than C++ - that we (they) started out slower and found that paradigm assimilation was less painful that way.
Having said all that, after 6 months away from VB6 I do find myself hankering for automatic casing. I wonder if it's time to go home?
Mike Woodhouse on September 4, 2006 2:52 AMJust because you write End If or End Class, it does not make your code more readable. If you write a huge software solution, you are probably going to have several methods and classes, so a little End X will not save you. And if you have done your coding correct, I don’t think it is important to tell yourself or somebody else, what a class is. The important is to highlight what is important in your code, and if everything is text with words, it can be difficult in a quick glance to separate what you yourself have written and what is required from the language.
Speaking of vb.net, maybe you think that the "AndAlso" and "OrElse" bitwise operators are very readable, but as a programmer I find them very ugly. And I can still be confused when I try to do bitwise operations in my “if” statements, how does vb.net calculate it, because it is not like csharp. And why stick on to the sub/functions, when they still are converted to methods, at least in terms of dotnet reflection.
No matter how much human language you are trying to make your code look like, I still think that programming should be focused on Mathematics.
Peter Palludan on September 4, 2006 3:11 AMC# reads pretty much the same as VB.NET, you just have to replace the symbols with words as you read. As with anything, this becomes second nature after a while and then you have the bonus of a visual distinction between code semantics and variables.
Which is easier to tell where the variables are and whats going on at a glance?:
if number1 is more than number2 then let number3 equal number4 otherwise let number3 equal number5
if ( number1 number2 ) { number3 = number4 } else { number3 = number5 )
I know it's an extreme example, but it's a lot easier and clearer to see what is going on in the second version once you know what the basic operators and symbols mean, yet you read it like the first.
"Speaking of vb.net, maybe you think that the "AndAlso" and "OrElse" "
This was to "fix" the lame way that VB's expression evaluation would not short circuit. Now you've got this garbage of AndAlso, OrElse etc.
http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=88311
I like where it says "Resolution: By Design" Yeah, bad design.
Diego on September 4, 2006 5:16 AMJon, I always preferred:
if (filesProcessed) {}
If we put good forethought in coming up with variable names, the above should be extremely obvious, and the extra "== true" is really redundant. Here we get the best of both worlds -- it reads like English only where it truly makes sense to.
Mark Freedman on September 4, 2006 9:59 AMThe highest level language is what's used to order another poor sap to write the code. ;)
Dim svc As New System.Windows.Forms.IDataGridColumnStyleEditingNotificationService
vs.
System.Windows.Forms.IDataGridColumnStyleEditingNotificationService svc = New System.Windows.Forms.IDataGridColumnStyleEditingNotificationService;
Even assuming Forms is referenced and is unnecessary, which is kinder on the eyes? ;p Of course, it's only an extreme example of where syntax can make one's life easier.
Foxyshadis on September 4, 2006 10:09 AMI like case sensitivity because it forces you to have a consistent naming convention. CamelCase, PascalCase or underscore notation for private variables, public variables and methods? No matter what you use if you are forced to use the same case throughout it helps identify the scope of the variables.
[ICR] on September 4, 2006 10:31 AMI am accustomed to working in both VB and C#. When it comes down to getting work done I always find VB to be faster to type. It may be more verbose but my fingers and wrists don't mind typing a short word instead of stretching to enter more brackets or parenthesis.
I also prefer Pepsi over Coke.
audaxpowder on September 4, 2006 12:25 PMI'm currently in the process of generating more or less ISO SQL. SQL is a typical exemple of the evil of english language like syntax.
The "new" inner join syntax for instance forces you to pay attention on the order of declarationof your tables, for something that is SYMETRIC :
from A inner join C on (B.c = C.c) inner join B on ( B.c = A.C)
won't work. The equivalent "where" syntax rightly does not pay attention to the order of tables in the from clause.
Aaron: "The syntax in C# is an adaptation from Delphi, and carries over the coding convention that interfaces should always start with an "I" (but drops the "T" in front of classes)"
The convention regarding interfaces actually comes from the original implementation of COM, so it's from C++, not Delphi. Delphi just followed.
Diego on September 5, 2006 5:42 AMMark Freedman: My preferred version of that statement is as follows:
if (filesAreProcessed) {}
A variable name like filesprocessed doesn't tell me anything about whether or not its value must be true or false. Throwing "Are" in the name does. *That* obviates it for me.
A variable like filesprocessed could be a number--the total number of files processed, for instance--in which case it might break that nifty if statement above.
Camel case alone isn't sufficient to make the code clear. The names of the variables themselves have to be clear.
In any case, VB.NET or C# is suitable for language choice. I use both. But in whatever lanugage you choose, that's only the start of the battle. The coder is responsible for making sure that the portion he or she writes is as clear as can be. An effective strategy for naming variables, classes, methods, properties, and fields, goes a long way towards accomplishing this.
And then of course, there's the golden rule: Refactor, refactor, refactor.
Mike Hofer on September 5, 2006 9:55 AMYou know, I wouldn't mind VB so much if it weren't for all the "End KEYWORD" constructs. Really now.
How readable would this paragraph be if instead of using punctuation COMMA I ended everything with "END SENTENCE" END SENTENCE It isnAPOSTROPHEt an issue with typing since the IDE handles that for you COMMA but readability END SENTENCE
Haacked on September 5, 2006 10:00 AM"A variable name like filesprocessed doesn't tell me anything about whether or not its value must be true or false. Throwing "Are" in the name does. *That* obviates it for me."
Good point, Mike. You caught me not putting enough forethought into it myself ;-)
Mark Freedman on September 5, 2006 11:03 AMHow readable would this paragraph be if instead of using punctuation COMMA I ended everything with "END SENTENCE"
The whole point of this post is that rules that work for English don't work at all for programming languages. The further you go down that particular rabbit hole, the worse things get.. eg, AppleScript.
Jeff Atwood on September 5, 2006 11:08 AMthe most frightening thing about COBOL is that it was created so that MANAGERS COULD WRITE THEIR OWN PROGRAMS! scary...
MOVE 10 TO MYNUMBER
ADD 4 TO MYNUMBER
I personally prefer C like languages. I learned how to program before i knew any english, so for many of us that english isnt our first language, vb or applescript or whatever dont really offer that much advantage.
I know many of you Americans will say: Everyone in the world speaks english, at least they should.
I think is all about how the syntax is structured, how easy is to achieve something with it and more importantly what company is behind it.
I once heard of a programming language in that the sentences were based in the spanish lang. But it didnt succeed. No one would want to use it.
Nowadays programming is far from human language, and thank god coz my job for that matters would be at risk.
PS Excuse any orthographic mistakes, its my firts post in english.
MTZMLZ on September 6, 2006 3:33 AMYour English is quite good!
Everyone in the world speaks english, at least they should.
I wouldn't say that, but it's clear that if you are a programmer, you'll be writing programs using English keywords..
Jeff Atwood on September 6, 2006 3:53 AMFoobar, your linguistic claims about English and Korean are silly, and spelling is irrelevant unless you want advocate using Korean keywords.
Matijs van Zuijlen on September 6, 2006 6:15 AMI prefer VB.NET. I especially like the "End *" syntax. In the C style syntax, the same character means end of class, end of method, end of if, end of while, end of for, or if I want to have a block of code I want to segment out, I can just put in { } anywhere I please. If I am writing a While loop with alot of conditional logic in it, and the top of my loop is off the top of my page, I want to be able to scroll down and immediately find the end of the loop I'm working in. When I've written programs in Java and C++, I found myself doing the following:
} //end if
}//end while
Well, most people get AppleScript wrong ;-), it's major flaw is that its Java-like syntax (optimized for coding) was not released.
AS (the english representation) is designed to be easily readable,
but its that easy to write. The fundamental concept is nice, and its absolutely not english-dependent there are japanese and french representations of applescript (and the Java like one that did not appear) an applescript is the (semantic) parse tree of one of this representations, thats why the scripteditor will somtimes do wired things to the sourcecode when the semantics are not so well defined (as with the POSIX file ":example", but actualy you would see what's wrong when the compile retranslates to "the englisch version" (or whatever language you want, english is just the defacto standard)
The only big flaw in applescript is that one never knows which variable names are free for use because there are many "reserverd words"
Edsger W.Dijkstra
On the foolishness of "natural language programming".
http://www.cs.utexas.edu/users/EWD/transcriptions/EWD06xx/EWD667.html
Jeff Atwood on March 15, 2007 11:37 AMWHOA what are the odds we both comment within 12 hours of eachother on the same post from a post over 2 years and 11 months ago! NUTS!
also, are you having difficulty pronouncing Dijkstra? is it.. dih-juh-kuh-stra? that is hard.
abel on July 22, 2009 10:06 AMIt's interesting that the line between terse elegance and explicit verbocity is so subjective. I'm most comforatable at the level of abstraction of C# right now. I personally find the "elegance" of Python and Ruby to be a poor trade - you save a few lines of code, but the code requires more mental parsing. I can understand how some folks who spend most of their time in VB feel the same way about C# - why do I need to parse this end brace to an "End If"? Why not just write "End If" if that's what you mean?
I guess there are tradeoffs to be made. Investing time in training your mind to precompile the code entails a learning curve (for all developers who will work on the code, not just the author). Some of these may offer gains that are only apparent after several years.
Jon Galloway on February 6, 2010 9:52 PMThe case sensitive part of C# is a little annoying which I never cared for. But once you get used to it, its not that bad, although it makes things a little harder.
I think you can make a program a little easier to read with a liitle forethought on variable names, but functionally it would be the same.
Example:
if (pf) {}
if (processedfiles) {}
if (processedfiles == true) {}
Which one is better? From a machine standpoint, they are all equal, from a human standpoint the last one if the most verbose and probably the clearest for the intentions of the program.
Jon Raynor on February 6, 2010 9:52 PMVB.NET has the upper hand with its "Dim ... New" syntax. And possibly XLinq, at least in its present stage. Other than that, C# tends to be less verbose, and any other differences are essentially cosmetic in nature.
The syntax in C# is an adaptation from Delphi, and carries over the coding convention that interfaces should always start with an "I" (but drops the "T" in front of classes). So when you see "public class SomeClass : ParentClass, ISomeInterface", the meaning really is quite obvious to any OOP programmer. And if someone isn't familiar with OOP, how are the words "Inherits" and "Implements" going to help them anyway?
It's a Coke vs. Pepsi debate indeed. Mr. Appleman is using some pretty flimsy logic suggesting that VB.NET's syntax is "easier to understand" in any significant way. It may be easier for rank amateurs, but contrary to popular belief, VB.NET is not a language designed to be used by neophyte programmers, so using this hypothetical dumb-dumb as a benchmark is disingenuous at best. It's almost as if he's suggesting that source code should be readable by an end user, which is baloney.
Personally, I prefer the term "abstract", which is a description of the class itself, than "MustInherit", which sounds more like an instruction to *me*. But would I really care if I had to write in VB.NET instead of C#? No, not at all, and it's almost funny that someone wrote an entire book about it.
Aaron G on February 6, 2010 9:52 PMI prefer if (processedfiles) {} as well as this tells me that processedfiles is a bool(ean). It can be of no other type. The compiler will not take a non-boolean value for this type of statement.
For Example:
int testthis = 1;
if (testthis)
MessageBox.Show("Must be true.");
Try to compile:
Performing main compilation...
c:\documents and settings\jraynor\my documents\visual studio projects\threadingexample\form1.cs(250,8): error CS0029: Cannot implicitly convert type 'int' to 'bool'
If it were a number, one could use Convert.ToBoolean(fileProcessed), but this statement would be better:
if (filesProcessed 0) {}
I think that would meet everyone's needs.
Jon Raynor on February 6, 2010 9:52 PMThe comments to this entry are closed.
|
|
Traffic Stats |