Is C# Better?

  • dawalker-1068762 (11/13/2009)


    OK, I've read through tons of comments here that amount to nothing more than opinions regarding syntax and have seen very little that answers the real question aside from the VB advantage with XML.

    The real question was, "Why is C# better than VB?", and I think most of the people referring to the syntax are saying "It isn't, use whichever one you prefer". You should be asking your boss the opposite question--e.g. why does he believe C# is so much better than VB? If he can't answer you then your argument is bolstered. If he CAN, you need to address whatever points he raises on their own merits.

  • paul.knibbs (11/13/2009)


    dawalker-1068762 (11/13/2009)


    OK, I've read through tons of comments here that amount to nothing more than opinions regarding syntax and have seen very little that answers the real question aside from the VB advantage with XML.

    The real question was, "Why is C# better than VB?", and I think most of the people referring to the syntax are saying "It isn't, use whichever one you prefer". You should be asking your boss the opposite question--e.g. why does he believe C# is so much better than VB? If he can't answer you then your argument is bolstered. If he CAN, you need to address whatever points he raises on their own merits.

    Good luck on that. If the boss has already dictated it vs. posing the question to the team and asking for feedback, I doubt he'll be swayed at this point.

  • Steve Jones - Editor (11/13/2009)


    Jeff Moden (11/12/2009)


    Heh... I have an odd personal preference... I don't like languages that require semi-colons or line continuation characters. It seems that they should all be smarter than that. 😉

    I'm there with you, and I'm slightly concerned with the optional additions in T-SQL that we are moving that way in the server.

    I think at some point it will no longer be an option. T-SQL will finally be forced to have semi-colons, which I like. So I look forward to it.

    The "_" for line continuation in VB/VB.NET is a pain. I prefer and appreciate C# syntax but work more in VB.NET.

  • Sql statements belong in a DB class. Advanced C# developers even create classes to hold the data returned by the DB class. Until I see a VB.Net project using these standards

    now, i am a bit confused. in my previous company, i've always trained my developers to move away from placing sql code in the gui, to make a class holding the custom sql data processing.

    ...to get read-only recordsets, but send only new or updated data (from gui to custom class to sql.net to server). much better if sql-statements are placed at the server as stored procedures or functions, away from the application itself.

    isn't this the concept of clearly defining what objects and classes are supposed to do, for optimization or at least, better maintainability?

  • Reading vb or vb.net code makes my eyes hurt. I'd say because vb is too verbose, but that is not consistently true. For me, the curly brace, etc. syntax provides better visual cues and makes code easier to read. True there is a learning curve with the syntax, but once surmounted I think there is a great benefit to anyone that has to read a lot of code.

    For example, I find that the relavant code stands out better in c# than vb.

    VB.NET:

    Sub ValidateColumn(sender As Object, e As DataColumnChangeEventArgs)

    If e.Column.Equals(Me.UnitPriceColumn) Then

    If Not Convert.IsDBNull(e.ProposedValue) AndAlso _

    CType(e.ProposedValue, Decimal) < 0 Then

    Throw New ArgumentException( _

    "UnitPrice cannot be less than zero", "UnitPrice")

    End If

    ElseIf e.Column.Equals(Me.UnitsInStockColumn) OrElse _

    e.Column.Equals(Me.UnitsOnOrderColumn) OrElse _

    e.Column.Equals(Me.ReorderLevelColumn) Then

    If Not Convert.IsDBNull(e.ProposedValue) AndAlso _

    CType(e.ProposedValue, Short) < 0 Then

    Throw New ArgumentException(String.Format( _

    "{0} cannot be less than zero", e.Column.ColumnName), _

    e.Column.ColumnName)

    End If

    End If

    End Sub

    C#:

    void ValidateColumn(object sender, DataColumnChangeEventArgs e)

    {

    if(e.Column.Equals(this.UnitPriceColumn))

    {

    if(!Convert.IsDBNull(e.ProposedValue) &&

    (decimal)e.ProposedValue < 0)

    {

    throw new ArgumentException(

    "UnitPrice cannot be less than zero", "UnitPrice");

    }

    }

    else if (e.Column.Equals(this.UnitsInStockColumn) ||

    e.Column.Equals(this.UnitsOnOrderColumn) ||

    e.Column.Equals(this.ReorderLevelColumn))

    {

    if (!Convert.IsDBNull(e.ProposedValue) &&

    (short)e.ProposedValue < 0)

    {

    throw new ArgumentException(string.Format(

    "{0} cannot be less than zero", e.Column.ColumnName),

    e.Column.ColumnName);

    }

    }

    }

  • You know, for some reason that whole "boss" thing carries more weight than my opinion does! 😉

    Just kidding, he actually is very good at listening to us because he is not a developer himself and has backed off a little on the C# thing. I think he refers to some old article that was written years ago with some C# bias as his proof of superiority. The problem is that decision makers sometimes think that just because it is newer it must be better especially when they don't have the technical experience in the area. We just happen to do a lot of EDI and use BizTalk which only supports C#. I think he takes that as another indicator that MS may eventually just discontinue VB, but I don't think that will ever happen.

  • roger.plowman (11/13/2009)


    Want to know the definition of "professional"? 🙂 It means "someone who is paid for it".

    Notice this does not imply any skill. We've all seen (and had to rewrite) horrific examples of code written by other programmers who wouldn't know a comment if it slapped their sister. And forget maintainability.

    Oh, and structured programming? They've heard of it...

    A good programmer is a good programmer, period. Even in LISP. The longer you do it for a living, the better your code--no matter which language(s) you prefer.

    So avoid the trap of elitism, folks. It makes you look silly and raises hackles.

    Leave that to the OS fanbois. We're professionals, right? 🙂

    Here Here! I applaud that. Pro's vs hobbiest? Hell I've seen some awesome hobby work done with a level of "professionalism" that would teach us all alot. Would you consider a 12 year old a professional or a hobbyist? And using your argument, should one then conclude that jQuery is not beneficial because professionals, hobbyists, and a 12 yr old can use it?

    Five years later, in a new company and still programming in C# (even though I can do VB.NET), I look at some of the legacy apps written in VB6/VB.NET (and some of my old stuff) and realize how awful some of the code looks. Granted, a lot has to do with poor coding practices, but still...learning C# and using it day-in & day-out has made me a better programmer. I've seen bad code in both C# and VB, but it seems that VB allows for sloppier coding. With C#, it almost forces you to write good code. It's not so much of a status thing with me...it's definitely a personal preference. However, the whole "compile time vs run time" issue is a stickler. I've seen that ppl who learn VB.NET first have a hard time grasping C#. BUT those who learn C# first can easily pick up VB.NET - just look at most of the "pro VB.NET" comments on this board and you'll see my point.

    GOOD FOR YOU! I sincerely expect that your work SHOULD have improved over 5 years. As you develop in C# you will continue to improve with that as well. Patterns and practices may also change and be invented that will make what we all do now look like a hack.I attribute sample code in books as being highly influential to how well a person writes code as a beginner. I also see a trend to teach patterns, practice and principles along with syntax these days. I suspect we will see better "new" programmers because of it.

    C# does NOT force you to write "good code". You can ignore things like encapsulation, separation of concerns, programming to an interface, etc just as easily in C# as VB.Net. I have been the guy to fix lots of poorly written "legacy" C#...

    [p]

    From what I've read on these posts, the majority of people made the switch to C# because of these reasons. 1) available source code 2) they heard it was better 3) more job offerings seem to request C# programmers (as though its not synonymous with .Net programmer)

    Most of the other comments highlight minor feature differences. If you are new and trying to make a decision, I think mentoring should play a big role. Consideration of those three points is more important than weighing optional parameters vs xml features. Semi-colons aren't that bad. You get used to it.

    The non English keyboard comment was very valid though. That WOULD suck to have to do chording to type a character you must use THAT often.

    [/p]

  • Steve,

    I started with BASIC many years ago on my Commodore 64, storing programs on cassette tapes and writing data to text files. Later I moved into VBA in Excel and Access 2.0. I checked out several versions of VB as they came out, but didn't find anything worth moving to until .Net. VB.net was obviously the logical choice for me. I thought one of the goals of .Net was to let a developer write the same code in whatever language they are familiar with, so when I see people fighting over one or the other language, it seems a waste of time.

    In the last couple of years I have used C# for new prohects just because I felt I should be familiar with it. I don't yet see much difference between C# and VB.net in terms of what you can do with it. So far, I've been able to do everything I've wanted to with either language.

    I have heard a couple of developers tell me that they can do more with C#, but when I ask them to explain, they describe some very specific situation that I've never needed to code for. They also explained that you can do what they described in VB.net, just not as easily.

    Some noteworthy differences:

    I like saying that I want to continue the line using underscore in the less frequent cases where that is needed rather than having to say that the line is ending by typing a semi-colon.

    The braces kind of bother me. I would like to save a line and have better readbility, but I seem to be fighting the way C# wants to format the code:

    if ()

    {...code;

    ....code;

    }

    I miss being able to put 'Handles' after my subroutine declarations. C# throws the code for handling events into the designer code, so I go and fish it out of there.

    I was liking the My. namespace in VB.net - many commonly used items are made easy to find in there.

    But these are not showstoppers. All in all, I would describe them as the same language (IL) with a choice of syntax: more convenient or more concise.

    Best Regards,

    Mark Lauser

    Sr. Software Developer - RS Medical

  • Dean:

    Yes, the VB.NET you posted is harder to read. It also deliberately avoids general readability standards. Try this:

    VB.NET:

    Sub ValidateColumn(sender As Object, e As DataColumnChangeEventArgs)

    If e.Column.Equals(Me.UnitPriceColumn) Then

    If Not Convert.IsDBNull(e.ProposedValue) AndAlso CType(e.ProposedValue, Decimal) < 0 Then

    Throw New ArgumentException("UnitPrice cannot be less than zero", "UnitPrice")

    End If

    ElseIf e.Column.Equals(Me.UnitsInStockColumn) _

    OrElse e.Column.Equals(Me.UnitsOnOrderColumn) _

    OrElse e.Column.Equals(Me.ReorderLevelColumn) Then

    If Not Convert.IsDBNull(e.ProposedValue) _

    AndAlso CType(e.ProposedValue, Short) < 0 Then

    Throw New ArgumentException(String.Format( _

    "{0} cannot be less than zero", e.Column.ColumnName), _

    e.Column.ColumnName)

    End If

    End If

    End Sub

    Then compare that to:

    C#:

    void ValidateColumn(object sender, DataColumnChangeEventArgs e)

    {if(e.Column.Equals(this.UnitPriceColumn))

    {if(!Convert.IsDBNull(e.ProposedValue) &&

    (decimal)e.ProposedValue < 0)

    {throw new ArgumentException(

    "UnitPrice cannot be less than zero", "UnitPrice");}}

    else if (e.Column.Equals(this.UnitsInStockColumn) ||

    e.Column.Equals(this.UnitsOnOrderColumn) ||

    e.Column.Equals(this.ReorderLevelColumn))

    {if (!Convert.IsDBNull(e.ProposedValue) &&

    (short)e.ProposedValue < 0)

    {throw new ArgumentException(string.Format(

    "{0} cannot be less than zero", e.Column.ColumnName),

    e.Column.ColumnName);}}}

    Now which one is more readable?

    Your post wasn't really a fair comparison, IMNSHO. If you're going to say one is easier to read than the other, it would be best to compare both with more standard layout and readability standards.

    - Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
    Property of The Thread

    "Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon

  • GSquared (11/13/2009)


    void ValidateColumn(object sender, DataColumnChangeEventArgs e)

    {if(e.Column.Equals(this.UnitPriceColumn))

    {if(!Convert.IsDBNull(e.ProposedValue) &&

    (decimal)e.ProposedValue < 0)

    {throw new ArgumentException(

    "UnitPrice cannot be less than zero", "UnitPrice");}}

    else if (e.Column.Equals(this.UnitsInStockColumn) ||

    e.Column.Equals(this.UnitsOnOrderColumn) ||

    e.Column.Equals(this.ReorderLevelColumn))

    {if (!Convert.IsDBNull(e.ProposedValue) &&

    (short)e.ProposedValue < 0)

    {throw new ArgumentException(string.Format(

    "{0} cannot be less than zero", e.Column.ColumnName),

    e.Column.ColumnName);}}}

    :hehe:!

  • dawalker-1068762 (11/13/2009)


    You know, for some reason that whole "boss" thing carries more weight than my opinion does! 😉

    Just kidding, he actually is very good at listening to us because he is not a developer himself and has backed off a little on the C# thing. I think he refers to some old article that was written years ago with some C# bias as his proof of superiority. The problem is that decision makers sometimes think that just because it is newer it must be better especially when they don't have the technical experience in the area. We just happen to do a lot of EDI and use BizTalk which only supports C#. I think he takes that as another indicator that MS may eventually just discontinue VB, but I don't think that will ever happen.

    Good for you! Having a boss that is very good at listening like that is an awesome thing to have.

    If the majority of the team is developing in VB.NET and that's what they're comfortable in and getting the work done, I'd say why mess with a good thing.

    You mention you're doing a lot of EDI and use BizTalk, I can see where maybe an emphasis would be placed on C# so you're supporting a common syntax vs. two. I know there are similarities between C# and VB.NET but having to constantly switch between the both provides the opportunity for basic syntax errors and having to context switch (mentally) between the two which can effect productivity. No doubt there are developers who have no issues working with both at the same time, but there are others (like myself) who would find it frustrating and annoying.

  • Having started out with FORTRAN, then C (I dabbled a little in C++), next VB (4, 5 and 6) and finally VB.NET and C#, I have to say that I prefer C#. Although, in fairness to VB.NET, there really isn't much of anything you can't do in VB.NET that you can do in C#. When I wrote programs in C, I really came to like the look of a C program. When I went to VB4, VB5 & VB6 I loved the speed with which you could write a program, but hated line continuation character that VB forced you to use. Although I never used punch cards, the whole line continuation character thing made me think that VB was strongly tied to the punch card experience. Man, that is so 1970's, why do that if you can avoid it? However, as I understand it, the next version of VB.NET will eliminate the need of a line continuation character, so that will definitely improve VB.NET development experience, IMHO.

    There is only one thing I can think of, that C# can do, which VB.NET cannot do, and that is mark a section of code as unsafe. That way you can program using pointers, for example, which you cannot do in VB.NET.

    VB.NET (and classic VB before it), has a very nice language feature with the With keyword. That helps to cut down on the typing, which is always nice.

    One thing I really like about C# is its intelligence when I'm writing code. For example, if I'm trying to define an instance of a class, let's say the class's name is MyClass, then when I type:

    MyClass myInstance = new

    then C# "knows" that I'm trying to instantiate an instance of MyClass, and it will then put in MyClass(). I love that feature! However, when I try to do the same thing with VB.NET:

    Dim myInstance As MyClass = New

    it is like VB.NET doesn't have a clue as to what I'm trying to do. I'm given just about all object types to select from in Intellisense. I suppose in one way that's better, as I may be trying to instantiate either a parent class object or a child class object, but 99 times out of a 100 I'm trying to instantiate an instance of the class I've already specified in the variable declaration. For me, that's a big deal; big enough to make me prefer C# over VB.NET.

    Kindest Regards, Rod Connect with me on LinkedIn.

  • I'm not so sure it's better. I think my former boss put it best: "I can write bad code in any language." 😀

  • I started out my non-mainframe programming with condensed basic (think TRS80); moved to the Mainframe where I did COBOL / CICS / DB2 / Assembler and numerous other languages and utilities, and moved back to the non-mainframe using VB4 and C. From there I migrated to object oriented programming in the form of C++ --> Java and VB6 --> .Net.

    For me it was never a issue of syntax, yes if you are not too familiar with a language your productivity will go down. For me its always been about the design. I spend most of my time doing the Design and Analyst (60%) and Testing (30%). That leaves a short time to do the grunt work of hammering out the code. As a contractor, I can afford limit myself and my opportunities to any one language. So for me its more of a customer / environment constraint.

    Every once in a while I'll meet someone who snickers and laughs at me for doing VB.Net, to which I reply, "well I do both, don't you?" 😀

  • Florian Reischl (11/13/2009)


    GSquared (11/13/2009)


    void ValidateColumn(object sender, DataColumnChangeEventArgs e)

    {if(e.Column.Equals(this.UnitPriceColumn))

    {if(!Convert.IsDBNull(e.ProposedValue) &&

    (decimal)e.ProposedValue < 0)

    {throw new ArgumentException(

    "UnitPrice cannot be less than zero", "UnitPrice");}}

    else if (e.Column.Equals(this.UnitsInStockColumn) ||

    e.Column.Equals(this.UnitsOnOrderColumn) ||

    e.Column.Equals(this.ReorderLevelColumn))

    {if (!Convert.IsDBNull(e.ProposedValue) &&

    (short)e.ProposedValue < 0)

    {throw new ArgumentException(string.Format(

    "{0} cannot be less than zero", e.Column.ColumnName),

    e.Column.ColumnName);}}}

    :hehe:!

    My point being that you can ruin the readability of any code by doing what he did to that VB.

    - Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
    Property of The Thread

    "Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon

Viewing 15 posts - 91 through 105 (of 176 total)

You must be logged in to reply to this topic. Login to reply