C-style variable definitions suck
Isn't "MyValiable : SomeType" a lot more readable than "SomeType MyVarianle"? This unfortunately ubiquitous convention does't stop to irritate me since I learned C 10 years ago. I was told C borrowed it from Fortran (can anyone clarify?), or some other obsolete language. It makes programs harder to read because variable name usually tells you more than name of its type, and people read left to right. I'm sick if it being dragged to the next, and next generation of programming languages. First to Java, then C#. Pascal, and SQL just get it right, don't they?
Egor
Sunday, April 18, 2004
I guess it makes parsing harder too. Not so sure about it though.
But at least, I can find one useful application for such a syntax.
int first, second, third, fourth;
Can be better than:
Dim first As Integer
Dim second As Integer
Dim third As Integer
Dim fourth As Integer
And what about this?
MyClass object = new MyClass();
Can certainly be better than:
Dim object As MyClass
object = New MyClass
Or about this syntax in C#:
using(SomeClass object = new SomeClass())
{
};
Can't be done in VB.NET :) You have to do:
Dim object As SomeClass
object = New SomeClass()
' Do Whatever
object.Dispose()
I'm sorry I do not know VB, probably I didn't write the syntax properly. But it's similar to this.
Green Pajamas
Sunday, April 18, 2004
I prefer no manifest type definitions at all...
Giovanni Corriga
Sunday, April 18, 2004
I'm no VB-er, but:
Dim first As Integer
Dim second As Integer
Dim third As Integer
Dim fourth As Integer
can be shortened to:
Dim first, second, third, fourth As Integer
And:
Dim object As MyClass
object = New MyClass
can we written as
Dim object As New MyClass
Duncan Smart
Sunday, April 18, 2004
Not a VB'er either :)
Green Pajamas
Sunday, April 18, 2004
Dim first, second, third, fourth As Integer
check the variables type for first/second and third.
blargle
Sunday, April 18, 2004
>Dim first, second, third, fourth As Integer
>check the variables type for first/second and third.
That bug was fixed in VB.NET, by the way. In VB.NET, all four variables will be Integers, just as you'd expect.
As for the original poster's claims about "Name Type" being more readable than "Type Name" -- that's as ridiculous as another debate about tabs vs spaces. Clearly, the more readable one is whichever you happen to be more familiar with, and any attempts to claim one or the other is inherently more readable is just silly.
Sexist
Sunday, April 18, 2004
If there is no word like the "as" in VB declarations to tell you which one is the Type and which one is the Variable, then it doesn't really matter if Type or Variable comes first because you'll just have to know.
However, do you really think that:
FILE File = null;
is better than:
File as FILE = null;
?
The second syntax clearly conveys that FILE is the type and File is the variable.
The second syntax doesn't exist in any language that I know of, however there's no reason that it couldn't be done it that way. Except that snooty C/C++ people would not use the "as" keyword out of contempt.
Wayne
Sunday, April 18, 2004
Also, we should be making computers talk like us, not the other way around.
Wayne
Sunday, April 18, 2004
The problem with the inital post is the suggestion Pascal got something right...
I don't think this makes a great deal of difference. It reminds me of arguments about where you put the braces, or whether there's a space after keywords but not after function names, or whether you neatly tab your declarations so the names match up, or whether your tabs equal four spaces or eight. (Just about the only thing you can say for sure is that indenting with spaces is crazy talk.) How carelessly do your eyes whip over the code, and how little do you pay attention as you're reading, that this is a great problem?
It might beg the question, but the C way is most assuredly the better one, because C and its bastard offspring are more popular than other languages.
Tom
Sunday, April 18, 2004
Oh, someone posted about VB whilst I was composing my masterpiece -- I ignored VB, which I shouldn't have (bet it's more popular than C, even if you include its successors!) but its verbosity -- "as" :) -- makes the type clear. If you just use punctuation to separate type and name, neither is really better than the other, but the C style wins because of its popularity.
Tom
Sunday, April 18, 2004
As if it matters.
hoser
Sunday, April 18, 2004
Oh, hey, why don't you do this:
#define as
Then you can say:
File as FILE = null;
and it will be the same as:
FILE File = null;
And since you hate the C syntax, do
#define BEGIN {
#define END }
And you will be all the bomb with your VB/PASCAL friends.
hoser
Sunday, April 18, 2004
I'm taking a beginner course in Spanish right now and I've discovered something -- of all the languages that I've learned a little bit of, English is the ONLY one in which the words come in the SAME ORDER that you THINK them!
Isn't that weird?
Eric Lippert
Monday, April 19, 2004
Actually that's not true, Eric. You can learn to "think" in Spanish and have the words come out in the same order as you think them, but to get this to work you have to stand on your head.
(If you don't have the necessary agility, a good substitute is having someone else stand on your head.)
Kyralessa
Monday, April 19, 2004
¡Ay, mi cabeza!
El Señor Lippert
Monday, April 19, 2004
Esto es alguna mierda loca!
Jack of all
Monday, April 19, 2004
At least for me, the C style works out:
int x; // an integer called x
char* p; // a character pointer called p
oh well.
Alex.ro
Monday, April 19, 2004
> Isn't "MyValiable : SomeType" a lot more readable than "SomeType MyVarianle"?
No: when declaring a variable the first thing I want to know is the type of variable. It's like saying "homo sapiens" instead of "sapiens homo".
Christopher Wells
Monday, April 19, 2004
- Isn't "MyValiable : SomeType" a lot more readable than "SomeType MyVarianle"? -
No.
Mr Jack
Monday, April 19, 2004
I have a suspicion Eric was making a subtle analogy...
If you start with English, of course that's what you think in. If you live in France for long enough, you might start to "think" in French instead. It's better than thinking in American I suppose :)
"The limits of my language means the limits of my world" -- Ludwig Wittgenstein, Tractatus Logico-Philosophicus (1922)
MugsGame
Monday, April 19, 2004
It actually wasn't so subtle that you needed to explain it to us.
Kyralessa
Monday, April 19, 2004
> It actually wasn't so subtle that you needed to explain it to us.
Except that apparently it was. :)
Anonymous critic
Tuesday, April 20, 2004
Tom stop putting own down C it is the mother of my beloved C++ and I will defend her to the end!!!!!
THE RED MENACE
Tuesday, April 20, 2004
If you dislike specifying your types, then you might like OCaml, which does type inference. The compiler works out the type of your variables, based upon what you do to them. For example:
let my_add a b =
a + b;;
defines a function that adds two integers. OCaml knows that a and b are integers because a floating point addition uses the +. operator. There's a lot more to it than that, and it's a great language.
C Rose
Wednesday, April 21, 2004
Recent Topics
Fog Creek Home
|