Hi,
I would like to know which one do you prefer? Why? Is there any difference besides the syntax?
I know one can do the same, or almost, in both language, have just been wondering this for a while.
Thanks.
Printable View
Hi,
I would like to know which one do you prefer? Why? Is there any difference besides the syntax?
I know one can do the same, or almost, in both language, have just been wondering this for a while.
Thanks.
Found this in Wikipedia, I think it's pretty specific and, apparently, many of the difference between both will be (rather were corrected) "corrected" in 4.0. Anything else?
The only genuinely significant difference between the two is that C# supports pointers and VB doesn't. That can make C# code run orders of magnitude faster in specific situations. Those situations are in very much in the minority though. I've never once used unsafe code in C#.
Other than that, the differences are minor and getting less significant as time goes on. The main point is whether you feel more comfortable with C# syntax or VB syntax. To a large degree that can depend on what you've used before. If you were a VB6 developer then you'll likely feel more comfortable with VB. If you used Java, C++ or any of the many other C-based languages then you'll likely feel more comfortable with C#. That's not the only factor though. I learned to program in C and I worked in C++ for two years before, and I hated VB6, I actually feel slightly more comfortable with VB than C#. It's only marginal though, and I'm happy to work with either and do spend about half my time in each.
Like jmc says the two languages are becoming closer and closer together. If I had continued on learning programming from when I first became interested in it back in 2000 then I would probably still be coding in Visual Basic. Although, being at a technical school that focuses on where business is going with their needs and wants the course was changed to C# instead of VB.
I actually feel comfortable with both, just wanted to know if there were any significant difference. It appears though, it comes down to personal preference. Guess I'll learn both.
I don't really prefer either language, but I do prefer the VB editor in Visual Studio, mainly due to the automatic indenting and stuff. I find that I have to go back and use 'format selection' in C# way more often then in VB (and before I knew about 'format selection' I did it manually!). The C# does have some automatic indenting, but mainly when you type a closing brace or parentheses. In VB, it's pretty hard to actually get it to miss-align something even if you try!
I do prefer VB's syntax over C# in most of the newer features such as
Not sure why but I feel it's easier to read, as with most of VB since it's much more "wordy" then the minimalistic C#.Code:messageTarget = Function(s) ShowWindowsMessage(s) 'VB
messageTarget = s => ShowWindowsMessage(s); // C#
The only thing I dislike about VB's syntax is the Dim statement :( It looks so ugly! I don't think using C#'s syntax for declaring variables is too minimal, and it would work well for VB too:
I think it looks ok, better then 'Dim' at least... Ugh.Code:String s = "Test"
Private Integer i = 3
Protected List(Of Integer) numbers = New List(Of Integer) From {1, 2, 3, 4, 5}
' "modified" For Each
For Each Integer int In numbers
MessageBox.Show(int.ToString)
Next
' "normal" For Each could still work too, but may be confusing as the order is reversed now suddenly
For Each int As Integer in numbers
...
Next
What I do like about C# is that it enforces rules such as when the use parentheses much better. In C# for example, when you declare a new instance of a class you must use parentheses:
Whereas in VB you can leave them out if you want. I like consistency so I always try to write 'C# style' in VB, using parentheses where it would be required in C# even though I'm using VB.Code:Button btn = new Button();
So....you have a dim view of variable declaration in VB?
There are a couple minor places where the VB syntax appears more clear to me, such as events, but the two are pretty similar. I started in C/C++, so I can read the C syntax pretty well, though I notice that I am getting kind of rusty at it. The thing that mostly bothers me with C is that the typing is so doggone hard to do, but I've flogged that horse in the past, and it is still dead. The point is just that good typists will have an easier time with VB than with C.
While I agree with all of this, the one thing I really like about VB is: Private MyClass As New Class, it bugs me that c# makes you type the class twice just to make a new instance of it. That's just a peeve of mine, nothing worth arguing over. The only other thing about c# is the curly braces, they get to be very hard to read since you use them to close everything. Other than those I like c# just as equally as vb.net, though I use vb.net much more often mostly because I came from vb6 and vb6 so...
Since I'm studying programming in college reading C code isn't as hard as it used to be, I just wanted to know if there were any differences, apart from those described in Wikipedia, but it seems to come down to personal preference since the discrepancy between both language is almost null.
I see what you mean, but I actually like C#'s way better, mainly because the 'New' keyboard is easy to miss if you're not carefully reading the code. The difference between
is huge whereas there's only 3 letters difference.Code:Dim btn As Button
Dim btn As New Button
In C#, the difference is much more obvious
In my opinion, much easier to see quickly whether you're assigning a new instance or not.Code:Button btn;
Button btn = new Button();
And I do dislike typing the name twice, but you can always use 'var' instead. Also, I'm not sure about this, but I think if you type "Button btn = " then Intellisense will provide you with " new Button()" already. If it doesn't do that then that was probably ReSharper helping me out, but it was useful :)
That's the language bias coming through. Had you been studying VB, you would have said that the discrepancy between both languages is almost Nothing.
MS is trying to merge the features of the two languages, and 2010 with the 4.0 framework was supposed to be a solid step in that direction, but not a final step in that direction. There is yet more convergence to come.
The important thing that you need to learn is the framework. You need to know what classes you need to use, for instance, to read and write to a text file, you need to become familiar with the classes in the System.IO namespace. Once you know that, the implementation of it is just syntax.
Gary
I think perhaps many here should try to appreciate what is available now. My programming experiences goes back to late 1987. Things were really "primitive" back then. There were no GUI's and nice development environments.
One of my class requirements in college was ANSI C. It was intimidating to say the least. All I had was a blank screen with a menu at the top. Afterward, I tried C+, but didn't have a lot of luck with it.
I've looked at several C# online tutorials and how-to's. Those things were very good and easy to understand. I didn't stick with it because my learning experience was BASIC, QuickBASIC, and onto VB.
There have been times with I thought BASIC really should be called "ASIC". I don't know if this is still taught now or not, but one of the first things I learned is the meaning of the acronym BASIC: Beginner's All-Purpose Symbolic Instruction Code. If someone has never written any application before, then perhaps it is a "beginners" code, but it has grown way beyond what it meant at the start.
So, appreciate what you have now! It could be a lot more difficult.
I like BASIC/VB/VBA/VB.NET type language more than the C/C++/C#/Java type languages just because you can concentrate more on your programming logic rather than handling the compiler's stupid requirements.
I heard this too often from my teachers in my childhood:
"BASIC is a smart language and C is a dumb language. The power of C comes from its dumbness."
The C compiler though powerful at processing, was awkwardly stupid on the programmer. It was hard to handle.
Messed up due to case sensitivity
You missed that () after the function name
You missed the ; at the end of line
You missed the } or put it at the wrong place and now you are searching for the culprit.
Usually the problem was at some line and it reported the problem 100 lines after that. So if you committed a mistake, you had to spend a lot of time debugging it as the exact problem line was seldom pointed out by the compiler.
Also, in VB the structures were (still are) much more clear and distinct. e.g. End If, End While, Next X etc. distinctly tells you what ends where. While in C if you missed one closing braces, it would take more than an hour to figure out the right place to put it (unless the code is well indented and well commented).
Now however as the technology advanced and the IDE and compilers got smarter and smarter the difference is reduced way too much to choose one over the other due to any of the reasons I mentioned above. I still like VB over C#, but that's much of a personal preference than due to language differences.
Personally, due to the fact that I do a lot of web development, to me it makes much more sense to use C#, because there are a lot of similarities in the code structure when using JavaScript, so you don't have to think in two different mind sets and flip between VB.Net and JS.
At the end of the day though, it is personal preference. I have got to the point that I am happy to converse in either language, and now concentrate on getting to know the framework, and what it contains.
Gary
Also go with what you need. I moved away from VB because idustry did (in my area) and as a contractor (or ex contractor) I had to code in what I was told and that was always C#. Never seen any VB in web apps.
I like VB.NET's straightforwards names (apart from Dim, which feels natural but makes no sense because, really, couldn't you choose a better word than "dimension"?); C# is sort of strange.
NotInheritable vs. sealed
MustInherit vs. abstract
I also like VB.NET's capitalization, the automatic checking for Nothing/null in event handlers, etc. What bugs me about VB.NET is that you have to put square brackets around GoSub and Let. C# also has a more versatile for loop. VB.NET has a more logical initialization sequence (base class-level initializers, base constructor, class-level initializers, constructor). I can't even remember C#'s. You can also use Declare instead of the longer System.Runtime.InteropServices.DllImport, and you don't have to include "ref" on variables passed by reference (although it does give you a good heads-up).
GoSub doesnt exist in VB.net, does it?
If it does i'm pretty sure you shouldnt be using it :)
According to this it does! However, I may have misunderstood what the article is referring to.
I do like c/c++/Java/c#'s way of declaring a variable more than vb's, what bugs me is in c# do declare something as an object and create an instance in one line means you have to type out the object's class twice (or use the var and let Infer do it's thing, which I don't like)Things like GoTo, GoSub, Exit... all shouldn't be used and Let hasn't been needed since QBasic (1985) even though they still have it in VB today.
VB.Net and C# support all of the same loops, so saying C# has a more versatile For loop doesn't make sense, both languages have the For...Next and For Each loops, there isn't any other For loop. Both support the While loop, etc....
C# and VB.Net default to passing things around ByVal (which is only of use for Integer, Longs, Short, Decimal, Double, Single; Classes passed ByVal have the pointer passed, which is what ByRef does). C# doesn't show anything (that I know of) when something's passed ByVal (VB inserts the keyword for you, unless you specify ByVal/ByRef yourself) and if you want to pass an Integer into a sub by reference then in C# you have to specify it (the ref keyword) yourself.
And it didn't secretly add it back without you seeing? :p In my experience it will add it back whenever it gets the change... Strange. I thought it was a requirement.
I've always pictured programming languages in "Levels".
Assembler is pretty much as low as it gets - Machine Code with mnemonics.
I think of C (in the old days) as a Medium level language. Human readable language but still quite close to the hardware so you needed to understand your hardware and clean up your own mess when you're done.
Then Basic (in the old days) is a high level language. Very human readable and not much requirement to know much about the hardware because you didn't have much access to hardware anyway. The only way to get near the hardware was to go down a level to something like C.
I mentioned "In the old days" because things have changed and Basic (which was once considered to be a "Beginner's All Purpose Symbolic Instruction Code" has gotten very powerfull so we can do pretty much anything we want with VisualBasic (Don't let then C nerds tell you otherwise) and we don't really need lower level languages anymore.
C# ? It's a high level language just like Basic - I once heard it referred to as Basic with "SemiColons".
I'd say it's "Visual Basic for C nerds"
If you're a C nerd please don't be offended - I'm one too.
Yea, when you type something like Private Sub YourSub (YourParam As Type) then press enter it'll insert the "ByVal" for all of the params that don't already have ByVal/ByRef typed in. You know that already..C# can use pointers directly, which vb.net cannot do. So I guess one could say c# is a little lower level than vb still, but it's all a moot point.
After pressing Enter, if you don't like the changes made by the IDE automatically, press CTRL+Z immediately after that and the changes will revert back.
So doing the above, and removing all "ByVal" I see that it compiles good. Also ByVal is assumed by default, when nothing is not specified.
GoSub and Let don't do anything, but you can't use them as property/method names without brackets.
Microsoft's c# 2005 Step by Step by John Sharp has a page or so about pointers in c and c++ explaining how they're used and the kind of problems they can cause if not used correctly.
It then goes on to say:-
So I reckon what that is saying is that c# 'can' use pointers in similar syntax to c/c++ but you really shouldn't. You should use the same 'reference variables' just like you'd do in VBCode:Reference Variables were added to c# to avoid all these problems.
If you really want to, you can continue to use pointers in c# but you must
mark your code as unsafe.
It then shows a couple of examples of using the unsafe keyword.
It then goes on to say ... unsafe code has a bearing on how memory is managed:
objects created in unsafe code are said to be 'Unmanaged'.
That's what LockBits is for. And you can use graphic APIs, too.
(Well, I guess there's a problem there, too: in my Vista Forms, the thing that's taking the longest is actually locking the bits of the image in the first place.)
Lockbits is unmanaged, unsafe code!
In a managed wrapper, though. 100% safe.