10 Reasons Why Visual Basic is Better Than C#

  • (2 Pages)
  • +
  • 1
  • 2

23 Replies - 17831 Views - Last Post: 25 June 2013 - 09:08 PM Rate Topic: -----

#16 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2271
  • View blog
  • Posts: 9,499
  • Joined: 29-May 08

Re: 10 Reasons Why Visual Basic is Better Than C#

Posted 12 January 2013 - 07:33 AM

vb.net has more advanced events system then C#, in vb.net you can do stuff that is triggered when the events are wired up or removed.
AddHandler
RemoveHandler 


What I mean
  Public Class Worker 
 
    Public Delegate Sub WorkDone(ByVal completedWork As Integer ) 
    Private handlers As New ArrayList() 
Public Custom Event WorkCompleted As WorkDone 
 
      AddHandler (ByVal value As WorkDone)
 
        If handlers.Count <= 5 Then 
 
          handlers.Add(value)  
        End If  
      End AddHandler 
      RemoveHandler(ByVal value As WorkDone) 
        handlers.Remove(value)  
      End RemoveHandler 
      RaiseEvent (ByVal completedWork >As Integer) 
 
        If completedWork > 50 Then  
          For Each handler As WorkDone In handlers  
            handler.Invoke(completedWork)  
          Next  
        End If  
      End RaiseEvent  
    End Event 



Public Sub DoWork() 
 
      For completedWork As Integer = 1 To 10  
        System.Threading.Thread.Sleep(1000) 
        RaiseEvent WorkCompleted(completedWork * 10) 
        Console.WriteLine(completedWork) 
 
      Next  
    End Sub  
  End Class


Not that I've this capability often (if at all).

Public Module Main2
  Rem /* WithEvents  */

  Dim WithEvents xx As New example
  Public Sub Main()
    Console.WriteLine("Start")
    xx.Test1 
    Console.WriteLine("End")
  End Sub
 
  Private Sub xx_a() Handles xx.a
    Console.WriteLine("Foo")
      xx.Test2
  End Sub
  
  Rem /* wiring up multiple events to the same event handler. */
  Private Sub xx_b() Handles xx.a,xx.b
    Static i As integer
    i +=1
    Console.WriteLine("Bar{0}",i)
  End Sub
End Module 

Public Class example
  Public Event a
  Public Event b

  Public Sub new()
  End Sub

  Public Sub Test1()
    RaiseEvent a
  End Sub
  Public Sub Test2()
    RaiseEvent b
  End Sub     
End Class



The With keyword to reduce the amount of code written. Base
With Me.Elements
    .PropertyA = True
    .PropertyB = "Inactive"
    ' And so on for several more lines
End With



Better LINQ Query support

Dim sm = Aggregate xr In From x In Enumerable.Range(0,100)
                         Where (x Mod 3 = 0) OrElse (x Mod 5 = 0)
                         Order By x Descending
                         Take 10
         Into Sum



Try comparing implementing an Interface in vb.net and c#, and you'll prefer vb.net automatically writing the method signatures for you.

This post has been edited by AdamSpeight2008: 12 January 2013 - 07:49 AM

Was This Post Helpful? 0
  • +
  • -

#17 tlhIn`toq  Icon User is online

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5676
  • View blog
  • Posts: 12,194
  • Joined: 02-June 10

Re: 10 Reasons Why Visual Basic is Better Than C#

Posted 12 January 2013 - 07:58 AM

View Postandrewsw, on 12 January 2013 - 06:08 AM, said:

View PostRyano121, on 12 January 2013 - 04:57 AM, said:

You can do the same in C#

int[] x = {1, 2, 3};


I should have chosen a different example :)/>/>. Although this is still not as easy to read.


Isn't this following the same pattern we all learned in math and algebra?

Quote

X = 14
y = 47
Plot it on a graph

A = 45
B = A + 5
Solve for B


The only thing added for programming was the type.

I agree its all the same, only different. But to say that the C# way of variable declaration is hard to read is just plain silly since it is the way we all learned first then VB turned it all on its head - like doing math in Reverse Polish Notation.

This post has been edited by tlhIn`toq: 12 January 2013 - 07:59 AM

Was This Post Helpful? 0
  • +
  • -

#18 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2271
  • View blog
  • Posts: 9,499
  • Joined: 29-May 08

Re: 10 Reasons Why Visual Basic is Better Than C#

Posted 12 January 2013 - 08:19 AM

View PosttlhIn`toq, on 12 January 2013 - 03:58 PM, said:

Isn't this following the same pattern we all learned in math and algebra?

Quote

X = 14
y = 47
Plot it on a graph

A = 45
B = A + 5
Solve for B


Nope = in algebra means equality which something different to the programming concept of assignment.
You can rearrange the formula like so.
0 = 45 - A
0 = (A + 5) - B
Solve for B

:= would be the correct mathematical symbol to use for define as or assignment.

A := 45
B := A + 5

Is B defined to be the result of the expression A + 5 or the actual expression itself?

This post has been edited by AdamSpeight2008: 12 January 2013 - 08:20 AM

Was This Post Helpful? 0
  • +
  • -

#19 tlhIn`toq  Icon User is online

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5676
  • View blog
  • Posts: 12,194
  • Joined: 02-June 10

Re: 10 Reasons Why Visual Basic is Better Than C#

Posted 12 January 2013 - 09:02 AM

So often I tell rookies to read the code out load, or at least in your had like a sentence. Just doing this helps it make sense and not seem like gibberish.

I think of = as 'equals' or 'Is set equal to' - a verb. The act of setting one to the other.

Thus x = 14 reads as "x equals 14" (or x is set equal to 14 if you like the verbose)
Since these assignments are resolved on the right side of the = sign first it still works for
0 = 45 - A reads as '0 equals 45 - A' so you have to resolve the right side first to make the statement true.

I think of == as 'is equalTo' - a condition
if (x == 14) DoQuitMethod reads as 'if x is equal to 14 Do quit method'

= .. One symbol, one word: "Equals"
== Two symbols, two worlds: "Is EqualTo" {a little loose on the definition of two words, but it makes a good mnemonic}
Was This Post Helpful? 0
  • +
  • -

#20 CodingSup3rnatur@l-360  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 992
  • View blog
  • Posts: 972
  • Joined: 30-September 10

Re: 10 Reasons Why Visual Basic is Better Than C#

Posted 20 January 2013 - 11:46 AM

Quote

in vb.net you can do stuff that is triggered when the events are wired up or removed


You can do that in C# also. Your example written in C# could look something like:

    public class Worker {
        public delegate void WorkDone(int completedWork);
        private readonly List<WorkDone> handlers = new List<WorkDone>();

        public event WorkDone WorkCompleted {
            add {
                if (this.handlers.Count <= 5) { 
                   this.handlers.Add(value); 
                }
            }
            remove {
                this.handlers.Remove(value);
            }
        }

        public void DoWork() {
            for (int completedWork = 1; completedWork <= 10; completedWork++) {
                Thread.Sleep(1000);
                this.OnWorkCompleted(completedWork * 10);
                Console.WriteLine(completedWork);
            }
        }

        private void OnWorkCompleted(int completedWork) {
            if (completedWork > 50) {
                foreach (WorkDone handler in this.handlers) {
                    handler.Invoke(completedWork);
                }
            }
        }
    }



However, one thing VB.NET does do that C# doesn't is, in normal circumstances where the event is implemented with a delegate backing field, it allows you to raise an event, even if there are no subscribers. This is because the VB.NET compiler inserts a null check on the event's backing field, where as in C# you have to write that null check yourself.

EDIT:

Quote

Try comparing implementing an Interface in vb.net and c#, and you'll prefer vb.net automatically writing the method signatures for you.


I'm not sure what you mean by this. In C#, if you type (in Visual Studio):

class MyClass : IMyInterface


and then Ctrl + . and then hit Enter, all the members are created for you, with the correct signatures.

This post has been edited by CodingSup3rnatur@l-360: 20 January 2013 - 01:25 PM

Was This Post Helpful? 0
  • +
  • -

#21 vks.gautam1  Icon User is offline

  • D.I.C Regular

Reputation: 17
  • View blog
  • Posts: 317
  • Joined: 21-March 08

Re: 10 Reasons Why Visual Basic is Better Than C#

Posted 19 June 2013 - 06:00 AM

cool discussion is going on. is there much similarity between c++ and c# ..i am fan of c++ . I like that much because my basic are strong in c++ but not in vb.net
Was This Post Helpful? 0
  • +
  • -

#22 andrewsw  Icon User is online

  • It's just been revoked!
  • member icon

Reputation: 3818
  • View blog
  • Posts: 13,533
  • Joined: 12-December 12

Re: 10 Reasons Why Visual Basic is Better Than C#

Posted 19 June 2013 - 11:05 AM

View Postvks.gautam1, on 19 June 2013 - 01:00 PM, said:

cool discussion is going on. is there much similarity between c++ and c# ..i am fan of c++ . I like that much because my basic are strong in c++ but not in vb.net

You are likely to find the transition from C++ to C# much easier than from C++ to VB; the letter C is a clue ;).

There is a comparison table between C++ and C# here, although it is more of a cheat sheet than an overview. A better overview is here at wikibooks. [C# is much closer to Java than it is to C++, but this point is irrelevant if you don't use Java :) ]

I might pause to ask why you are considering moving from C++ to C#? If you are just looking at exploring another language, then you might consider one that is noticeably different. C# is excellent, of course, but it might be more of a challenge/more interesting to leave your comfort zone. But, hey, this is just a passing suggestion.
Was This Post Helpful? 0
  • +
  • -

#23 vks.gautam1  Icon User is offline

  • D.I.C Regular

Reputation: 17
  • View blog
  • Posts: 317
  • Joined: 21-March 08

Re: 10 Reasons Why Visual Basic is Better Than C#

Posted 19 June 2013 - 09:51 PM

View Postandrewsw, on 19 June 2013 - 11:05 AM, said:

View Postvks.gautam1, on 19 June 2013 - 01:00 PM, said:

cool discussion is going on. is there much similarity between c++ and c# ..i am fan of c++ . I like that much because my basic are strong in c++ but not in vb.net

You are likely to find the transition from C++ to C# much easier than from C++ to VB; the letter C is a clue ;)/>.

There is a comparison table between C++ and C# here, although it is more of a cheat sheet than an overview. A better overview is here at wikibooks. [C# is much closer to Java than it is to C++, but this point is irrelevant if you don't use Java :)/> ]

I might pause to ask why you are considering moving from C++ to C#? If you are just looking at exploring another language, then you might consider one that is noticeably different. C# is excellent, of course, but it might be more of a challenge/more interesting to leave your comfort zone. But, hey, this is just a passing suggestion.

hahahaha :red_indian: i understand what you are saying now but right now im still searching job for my profile . im working but in different feild. whatever i learned till now i have learned from internet except c++ which i learned in my institute 6 years ago.
Was This Post Helpful? 0
  • +
  • -

#24 marrisa  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 6
  • Joined: 25-June 13

Re: 10 Reasons Why Visual Basic is Better Than C#

Posted 25 June 2013 - 09:08 PM

Personally, i prefer VB to C#.
Just because i am more familiar with VB, LOL.
just a joke... :red_indian:
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2