C# guy driven crazy by what happens in VB when I press "ENTER"

Status
Not open for further replies.

David.Mater.Dei

New member
Joined
Apr 22, 2008
Messages
3
Programming Experience
1-3
In C#, I can start typing something, see the presumed word is correct (auto-complete a line), and hit ENTER, and keep typing on the same line. I don't have to press SPACEBAR or TAB. It's just something I like and am used to...

But I have to code some VB because of a grandfathered project and can't, for the life of me, stop hitting ENTER every bloody time I try to auto-complete a line, which drops me to a new line in VB, necessitating the BACKSPACE key, and including cursing as a side option.

I had my friend in stitches, as he commonly switches between VB and C#, and doesn't have a habit of pressing ENTER.

Anyway - if I can change the behavior of Visual Studio when coding in VB - that would be beautiful.
 
I'm not aware of such option, and see how one could be tempted to press Enter in a option list to confirm a selection. I have the bad habit of using Space key myself *always*, but in many cases it's just one more wasted keypress really. If thinking continuation you see the need for a selection confirmation key as such is redundant. This goes for Tab key and Space key too, when they don't produce anything usable in code (we don't write indentation manually anymore). It must be something inherent in human nature to not really trust the machine, what I mean is, it is more logical to just continue coding by pressing the key that should follow after the selection, and take for granted that what you see currently selected in the intellisense box is what is inserted. For example press
  • = for assignment/comparison
  • . to go deeper into object level
  • ( to get into an item array/collection
  • Space when appropriate in code
  • Enter if the purpose is to finish the code line and start a new one.
Using these five keys appropriately gets you one step ahead in code instead of Tab/Space to stop and wait to see that intellisense really does it's job for every word you start writing. (and it really does do it's job every time, isn't that the funniest thing :)) Getting a better habit of coding may save a lot of time and keypresses.
 
Thank you, John. That's a well-formulated, well-thought reply. You are exactly correct about the proper procedure.

I generally trust Visual Studio 2008's formatting and mechanics - with intellisense, it can spell better than me, remember what properties go with what, and so forth, nevermind the excellent tabbing and indenting of code.

Muscle Memory:
My problem is simply that I press enter, for whatever reason, and that no amount of wanting my brain to act differently seems to work, which is what gave my friend such amusement. I can type fairly fast when I don't think about it, (black keyboard in a pitch-black room illuminated only by the monitor and I can still type with the numbers above the letters) and that's the problem - I'm not thinking about it, it's muscle memory, and you can't really combat that.

Now, it sounds silly of a touch-typist to say "I want to waste a keystroke" because "." or "(" usually follows a recognized word, but really what I'm saying is "I can't combat my muscle memory. I tried it for 4 hours of intense coding and never got it. I just want to stop cursing."

Tools, Options?:
So, I saw that in TOOLS, under OPTIONS, then KEYBOARD I can apply an additional keyboard mapping scheme, but that doesn't help me.

Does anyone have any ideas on telling MVS's editor that, when coding in VB, I want it to behave more like C#?
 
I've always thought, wouldn't it have been better for the C# IDE team to have it work like the VB IDE.

Another extremely annoying thing about C# (C++ and Java too) is those darn semicolons after every line except those rare occasions and the opening/closing brackets thing is the most confusing way to maintain blocks of code. C# would be much more successful if they'd removed the annoying legacy crap.
 
David,

I think this issue you're talking about is actually a new way intellisense works in VS 2008, not a VB specific issue although I haven't tried it in C#. I do know that intellisense works differently in VB 2008 vice earlier versions, I think...
 
Neal, I checked - I thought I was crazy for a moment - but carriage returns in C# developer studio just put you at the end of the line, ready to press "." or "(" or anything you need.
 
I can feel your pain. I switch between c# and VB a bit, but I have never had this problem. I usually just press whatever the next key would be, much like what JohnH pointed out. Ex. if I am doing .ToString(), when intellisense pops up i only type as much is necessary for it to select the tostring like then I just type the () to finish it off.

JB - I actually prefer the {} to how VB does it, lol. I also sometimes prefer how C# uses the semi colon because then I don't have to worry about doing goofy & _ junk to make sure it kicks down to the next line, I can insert a line break anytime I want and just finish it off with a semi colon.
 
In C#, I can start typing something, see the presumed word is correct (auto-complete a line), and hit ENTER

Which i've never done.. I always just typed the next word-boundary character i want to insert (like . ( [ ; etc) and it's been fine; this behaviour is across both ides

But I have to code some VB because of a grandfathered project
I'd convert it to C# ;)

necessitating the BACKSPACE key
Actually, Ctrl-Z will put you right back to the point where you pressed Enter, and you can press space, period etc.. Gradually you will learn and you know what; it'll be a good thing ;)

I did think there was somewhere an option to turn this off, but unfortunately youre hitting the wall that generally VB programmers are regarded as less skilled, more newbie and less interested in power programming/nerdy geeky stuff. As a result, MS make more decisions for them and offer less customization; to whit, the IDE just isnt as nice a place to be as C#. You can see evidence of this in the image below - in C# we have a huge number of options for controlling Intellisense. VB guys do not.

Note btw, that the currently un-ticked tickbox would cause Enter to insert a newline in C#. I presume that VB has this option ticked and hidden by default, so youre really going to have to re-train your muscles



I had my friend in stitches, as he commonly switches between VB and C#, and doesn't have a habit of pressing ENTER.
Mmmhhh... tbh, the way that box is unticked in C# and ticked/hidden/nonoption in VB, i'd say that pressing enter to confirm a selection is "wrong"
As a little anecdote, an IT teacher once watched me doing DTP. I highlighted some text to get rid of and started typing the new text. He said to another IT teacher "you know, it makes sense but i never thought about that before. I always pressed BACKSPACE first to delete the selection, then start typing, but ther eis no need for a wasted keypress.. Just highlight and the first letter will replace the selection.Funny"

Ah, hte habits we pick up

Anyway - if I can change the behavior of Visual Studio when coding in VB - that would be beautiful.
Yeah.. Use the configurable option: C# :)
 

Attachments

  • untitled.PNG
    untitled.PNG
    17.3 KB · Views: 70
I've always thought, wouldn't it have been better for the C# IDE team to have it work like the VB IDE.
You've got to be kidding! The VB IDE is retarded!

If you want to handle an event in C# you do:

object.Event += [TAB][TAB]

and the IDE makes a delegate and an empty method with all the right parameters.. all you have to do is write the code.

What do we do in VB?
Write a sub, though we dont know the event signature:

VB.NET:
Public Whatever Sub MyWhatever() Handles myObject.Disposed

We then do a full compile, and copy the error message:

Error 1 Method 'Public Sub Whatever()' cannot handle Event 'Public Event Disposed(sender As Object, e As System.EventArgs)' because they do not have the same signature. C:\Documents and Settings\cjard.THIMKPAD\Desktop\Software Dev\Local\Visual Studio 2005\Projects\WindowsApplication1\WindowsApplication1\Form1.vb 177 53 WindowsApplication1

and paste the error into the code, deleting the bits we dont want (keeping the bold bit above)

Now we finally have a sub that has the right signature for the event, we can addhandler it.

Woo. Er. Like I say -> retarded.


It would be great if I could get some consistency.. If I position to make a new sub and write "Overrides" i get a list of things to override, choose, press return, and there's my premade method signature! Why can't I write "Handles" and the class is scanned for event emitting objects, or at the least, write "Handles myObj." and get a list of events on myObj to handle..



Sticking with the IDE for a minute.. C# you want to make a private field a property? Cool. Right click it, choose the relevant option from the refactor menu..

Want a new property? type "prop" and press tab, fill in the green fields and youre done. VB, theres some Insert Snippets somewhere, but I cant find it let along navigate the 3 or 4 levels of menu obscuring what I want to do.

In C#, if you write a switch(select) and switch_on an enum for example, then the IDE creates a big block of all the options for you. VB, it inserts an example Select containing Case 1 (integer) and Case 2 and.. er.. that's your lot.

It's not adding up to a very helpful environment is it? Just about the best thing that it does is background compilation so that it can do unboxing/conversion based type checking so that the implied unboxing (yuck) can work at runtime. This is to counter the huge problem raised by option strict where you can write
Dim i as Integer = "1"
or
Dim o as Object = "hello {0}"
Dim s as String = String.Format(o, "world")

Yuck yuck yuck! The only people who will ever take issue with having a sensible amount of precision demanded of them, are those who are incapable of acting with that precision - people who dont know the difference between a string and an integer, or rely on the background compilaiton to unbox the string they just boxed into an object. Some things computers just should not do for us, because thye will get it wrong, or we will forget that they do it and performance will suffer

Another extremely annoying thing about C# (C++ and Java too) is those darn semicolons after every line except those rare occasions and the opening/closing brackets thing is the most confusing way to maintain blocks of code.

Proper indentation is the correct way to maintain blocks of code. In VB, every block of code is delimited by something different. IF delimited by END IF, FOR by NEXT..
C# is clean and consistent and uses fewer characters. Additionally, when we position the cursor near an opening or closing { } the other end of the block lights up so we can see how far it extends. Typing "break" in a for loop causes the statement that will break to light up; handy if you have a select/switch inside a loop

Using semicolons to denote when you have finished typing a line is a good thing, because in this day and age of OO, there are usually a lot of levels to dig through to get the method you want, which means the lines run to huge length and the VB guys have to put line continuations in all the time (if they want to adhere to a "no line of code longer than X characters" rule for readability.

Additionally as a multiline compare, see this:

VB.NET:
string threeLines =
@"This is 
a string split
over 3 lines";

Dim threeLines as String = _
"This is " & Environment.NewLine & _
"a string split " & Environment.NewLine & _
"over 3 lines";

Ya, VB makes things so much easier to read and quicker to type..
Note also that when compiled, these two are very different. The C# just puts a fixed string in. The VB contains a hidden string builder call:
VB.NET:
Dim threeLines as String = New StringBuilder("This is ").Append(Environment.NewLine).Append("a string split ")
.Append(Environment.NewLine).Append("over 3 lines").ToString()
Nice! (note tha tI broke it into 2 lines manually so as not to distort the forum)


Here's another thing, while we're poking at legacy crap. Line continuations must be removed by the IDE before compilation. Why? Because this code works in c# and not in VB:

VB.NET:
myMethod(
  23, //person age in years
  "Johnson", //person last name
  "Joe" //person first name
);

mySub( _
  23, _ 'person age in years
  "Johnson", _ 'person last name
  "Joe" _ 'person first name
)

Oops! The code becomes:

mySub( 23, 'person age in years "Johnson", 'person last name "Joe" 'person first name)

Which won't even compile.

Thanks to semi colons, simple stuff like proeprty sets and gets can be written on one line instead of the 10 or so that VB needs. VB is wordy and has a superfluous syntax, crazy default settings that promote poor quality programming (Option Strict/Explicit anyone) and doesnt offer its best programmers the options it should to really make use of their skills. Too many beards on the VB team I think..

I could go on, (and on) but hopefully I won't need to; (any kind of) basic is something of a language isolate these days, and most languages that are created from scratch or are evolving properly are arguably more consistent than VB is..

C# would be much more successful if they'd removed the annoying legacy crap.

C# is way more successful than VB, and without even getting into discussions over the absolute stupidities of resuing = for assignment/eqaulity or () for array indexes AND method calls, it ought to be clear to see that VB is carrying way more legacy crap from VB6. MS had the chance to clean up everyone's act, but they didnt - they provided libraries to allow MsgBox to continue into the future instead of obsoleting it immediately in order to have VB6 pasted code encouraged to upgrade. C# was the new language, built to a modern spec by ECMA, incorporating the best features from its forbears, java, c++ et al. As a new language it cannot possibly have any "legacy crap"?!
Note that noone is trying to paste old code into it and make it go, unlike all those people that think VB.NET is an upgrade to VB6..
 
Last edited:
The VB IDE is retarded!
I like it, but then again I also like Black Eyed Peas.. :p
promote poor quality programming
Face it, the second biggest attraction to VB for beginners and programmers that doesn't rate quality higher that "either it works" and "the faster done" was typeless development. In this regard an implicit type conversion error is more a design problem than a programming error. Some of this simplicity was "lost" with the introduction of VB.Net, part because now was the time VB was a "proper" programming language, and part because intellisense provided so much more help if you just got the type right. MS is still encouraging this type of behaviour and the 2008 version adds several new features in this direction, one which is called "inferring" the type where you get intellisense help for typeless variables based on return type of assignments.

The dynamic event binding could be better, VB2008 makes this easier when you don't need the parameters (relaxed), but it would be nice to have the signature inserted also. If I need multiple dynamic handlers I usually just WithEvents a variable temporarily and use that variable to generate the structures, backwards but it works fastest.

Does C# really generate switch for all enum options? What annoyance! In many cases one only select a few members, or combinations. VB does popup the enum member list when you case. I've not seen it offer numbers for Integer enums.

With VB you can write multiple statements on a single line delimited by colon, while not a good readability option.

As for code blocks delimiters there luckily exists different languages that suits different people. I favour the VB.Net way.
C# is way more successful than VB
In view of cjard, right? Widespread popularity does however affect which languages are offered, in many years from now perhaps all C/VB are gone and it's all about S% (pron. See More) vs T& (Talk Basic).
As a new language it cannot possibly have any "legacy crap"?!
With the apparent similarities with C-style languages there is nothing new with C# as a language.
Want a new property? type "prop" and press tab, fill in the green fields and youre done.
VB.Net has exactly the same feature for "property", which I answered for you in another thread.
Using semicolons to denote ... no line of code longer than X characters
The X means the width of working area of code view on my monitor... which means I must get a wide screen soon.
VB.NET:
all those people that think VB.NET is an upgrade to VB6
Surely it is!? A big version upgrade with several breaking changes.
paste old code into it and make it go
"make it go", yeah.
 
Now that I've been handed a C# app at my job, I'm starting to understand the real differences between C# and VB.net (of course I still like VB more) but one thing that took me a while to figure out that really annoyed me about C# was that using a Switch on a variable, you can't specify more than one "Case" on the same line like you can in vb and when all the cases fall through to the one that actually has the code, you still have to put a "break;" at the end, wtf is the point of that?

Anywho, the other thing that really annoys me about C# is this:
VB.NET:
try
{

}catch (exception ex){
}

//The top one fails, but the IDE doesn't tell you until you compile

try
{

}catch (Exception ex){
}
Took me quite a while to realize that even though 'exception' doesn't exist, the IDE thinks it does. Even VB capitalizes the first 'e' in 'exception'.

I also agree with JohnH about all of this too.
 
Does C# really generate switch for all enum options? What annoyance!
I like it. I'd rather delete stuff I didnt need than type stuff I did :)


I've not seen it offer numbers for Integer enums.
I chose to Insert Snippet, it put Case 1 and Case 2 in there by default.. An example I guess; it doesnt work the same way as C# "enum[TAB][TAB]" insert

With VB you can write multiple statements on a single line delimited by colon, while not a good readability option.
Handy to know, thanks!

As for code blocks delimiters there luckily exists different languages that suits different people. I favour the VB.Net way.
WEll, i do acknowledge that in some cases such things are useful; you can see whithout cursoring near, what is what:
VB.NET:
    End If
  End While
End Sub

and I do see this:
    } //end if
  } //end while
} //method
Though I generally dont suffer that problem because I avoid huge nests if possible

In view of cjard, right?
As a lame check, C# gets roughly 4 times more hits on google than VB.NET

With the apparent similarities with C-style languages there is nothing new with C# as a language.
Oh, come come.. You cannot possibly argue that because a language shares syntax with another, that there is nothing new about it. C# is very different to C in nearly every way apart from the familiarity of the syntax and keywords.
When Steven King writes a new book, its a completely new book, but he uses an old and familair arrangement of words known as English thereby ensuring widespread appeal.

C# does some thigns and does not do other things that its language similars/syntax peers does. Aside from my argument that it is Java, post -being-successfully-sued-by-sun (because java was an all new language that borrowed a widely used syntax), it really is a new language, ground up.. Not a rehash of an old language to bodge some new features in. Now, it's evolving over .NET FW upgrades so we are starting to see it (and all the .net flavours) acquire features not present in earlier versions.. Generics for example. Again, just a pick of a good feature from an older language
In arguing against the "legacy crap" notion.. i need to point out that if you took away EVERYTHING considerable as "legacy crap" then you wouldnt have anything left. Nothing is truly new any more, in any language.. As such, i didnt literally interpret JB when he said "legacy" - I just cant favour the argument of creating something new and stripping out "legacy crap" because then you'd have something that appealed to noone.. Same for VB.NET; ditch all that crap from VB6, 5, and so on.. You'd get back to a language that doesnt appeal to VB programmers, and is bad marketing!

In summary; i cannot support JB's argument about legacy in any circumstance, and I have my own opinion of what is crap.. It's the crap that should be ditched ;)

Surely it is!? A big version upgrade with several breaking changes.
Naw.. it's a whole new language, using a familiar syntax, with a few extra libraries to allow all the really weird idiosyncratic crap from VB6 to persist.. If anything, That's what should have been dumped: Microsoft.VisualBasic.dll*

*but can I keep the single-instance-via-remoting functionality please? :)
 
Another thing that C# lacks but VB offers is the 'With' statement. C# people tend to be all about less typing is more productive, so why does VB offer a very nice, quick and flexible typing shortcut, shoot it even speeds things up with the intellisense too.


If anything, That's what should have been dumped: Microsoft.VisualBasic.dll*

There's a few other things in there than legacy vb6 wrapper functions. A vb code compiler for example is in that dll.
 
you can't specify more than one "Case" on the same line like you can in vb

True, they go on different lines. Makes em nice and easy to read:

VB.NET:
switch(myVar){
  case1:
  case2:
    //code for case 1 and 2
    break;
  case3:
    //code for case 3
    break;
}
The arguments for and against allowing code fall-through are long, well established and do not need repeating here. If youre falling through and re-using code.. consider making a method. It's very easy with C#.. simply select the codee you want to extract, and choose Refactor>>Create Method
C# will look at the inputs, any necessary outputs, and transport the highlighted code intoa new method, leaving behind a call to it. You can then use this call in multiple cases


and when all the cases fall through to the one that actually has the code, you still have to put a "break;" at the end, wtf is the point of that?
Because case fall-through is not allowed, and if you dont put a break, you dont demonstrate to the compiler that you understand this fact

For microsoft's statement on this, see here:
http://msdn.microsoft.com/en-us/vcsharp/aa336815.aspx

Some very wise beards got paid a lot of money to have this as the final say. Whatever our opinion of their edict, we must simply read, understand and obey.. All life is like that


Took me quite a while to realize that even though 'exception' doesn't exist, the IDE thinks it does.
No, the IDE doesnt bother to look whether it exists or not, because the IDE is not doing constant background compilation unlike the VB IDE.

Even VB capitalizes the first 'e' in 'exception'.
You really need to appreciate that C# is a case sensitive language, and "exception" might well refer to something other than the type "Exception" - it's possible, legal and allowable (though not recommended in CLS because of the quirk that VB is insensitive and using members whose names differ only by case thus means that VB has a hard time dealing with the code) to have:
Exception exception = new Exception();

If you type ex[CTRL+SPACE] then intellisense will insert the correct case for you. If you type "try[TAB][TAB]" then the IDE will insert a try{}catch(Exception){} block for you.

Case issues are a common complaint from VB programmers, but honestly, it's just because they arent used to working with the requisite precision that C# demands. Give it a few weeks, and you'll automatically start casing things properly (i.e. coding fewer errors into your code) ;) and it will enhance in your mind, the separateion between Types and instances, ClassNames, MethodNames and privateProperties (or _privateProperties)

If youre learning to flick your mind between VB and C# then I hope you'll find this as invaluable as I did:
http://www.harding.edu/fmccown/vbnet_csharp_comparison.html

(and on the case note, ahh.. the number of times i've come back from VB, only to write:
String s = NewsStyleUriParser ...

)
 
Last edited:
Another thing that C# lacks but VB offers is the 'With' statement.
With is ugly as sin, and because things can be "re-Withed" you end up with:

VB.NET:
With whatever
 .whatever
 With another
  .somethingElse
  With this
    With that
      .thing
    End With
 .thing4
 End With
 .some pages later
End With

Comes a point you havent got a CLUE what youre actually WITHing when you press ., without chasing up and down code, looking at indent levels.

If you really want to save yourself some typing, Dim a temporary 1 character variable, so you at least still give some meaning to what youre dotting:

VB.NET:
  Dim dt as MyDataTableColumnCollection = Me.MyDataSetInstance.MyDataTable.Columns
  dt. blah
  dt. blah2

I have never seen a professional programmer use With..

Does tickle me that C# will be attacked for not having a "with" because VB guys want to save some typing in dimming a sensibly named local variable.. But they are perfectly happy to type End With, End For, End Function, End Try, End... Yada! How many cahracters did you have to type with all those End XXX when in C# we just type }



C# people tend to be all about less typing is more productive,
I personally find "fewer words on screen = more readable" - I dont really make any claims about productivity of programmers because from what I see, I can believe that the industry average productivity is indeed the touted 20 lines per day

so why does VB offer a very nice, quick and flexible typing shortcut, shoot it even speeds things up with the intellisense too.
Dude, you make out like C# doesnt have those things, when its intellisense goes over and above what is offered in VB, it's more customisable, shows you more entries, can be used to autoinsert more things and it's way faster to insert snippets in C# than VB.. If youre having some trouble finding the options I'm talking about, then by all means ask.. If your employer provided C# with IS turned off, then i genuinely feel for you and I'll help you turn it on right away..
 
Status
Not open for further replies.
Back
Top