loads of useful information, examples and tutorials pertaining to web development utilizing asp.net, c#, vb, css, xhtml, javascript, sql, xml, ajax and everything else...

 






VB vs C# experiment - Random shift generator for your employees

by naspinski 4/20/2008 4:54:00 PM

Some random programming in both C# and VB, using lists, objects, ternary operators, etc.

Now normally, I would never write anything in VB, it kind of annoys me.  But I was bored this last weekend (nothing to do in Kuwait) and I was helping someone out on Experts-Exchange (it's something I do when I am bored) when I came across a problem that looked kind of fun:  The guy had a bunch of employees, three shifts (24 hours) and weekends were in no way tied to any specific day.  He wanted to randomly generate a schedule (I am assuming this would be to eliminate the idea of favoritism/complaining).  Either way, I was bored and this sounded interesting - it was a request in VB, but since I hadn't done VB in a while, I figured brushing up wouldn't hurt.  I wrote it first in C#, then translated to VB.  Here are the two programs in action (not that there is any functional difference):

 

Shift Shuffler in C#

Shift Shuffler in VB

 

I did originally write it in C#, then translated to VB, though some things are a bit different in each, so don't expect a one-for-one comparison, though the logic is the same.   One thing I was really surprised at was the fact that my VB code was considerably shorter (86 vs. 116 lines) than my C# despite my C# being a lot more concise and cleaner.  For example I used ternary operators in C# as opposed to if-thins in the VB which are a lot longer (1 line as opposed to 5).  I did have a 10 line summary in C#, but it was still surprising.  Looking at this, I figured it was due to {'s and }'s as I like to have them on their own lines, but at least half of those could be directly compared the 'End' statements of VB.

 

I found that the Dim statements in VB got do me a little annoying, and the whole byVal, As, and all that redundant junk seemed to be unnecessary.  I also found it hard to kick the old habit of ending every line with my trusty semi-colon as well.  And I noticed it took about 5 minutes to change 'modes' in my head from one language to the other, but overall, they are really the same thing and knowing one basically means you know the other. 

 

Either way, I still like my C# better, but doing an exercise like this helps keep even the best programmers sharp, as knowing cross-language translation and even being able to read the 'other' language is often helpful when searching for solutions or helping out a co-worker that has gone to the dark-side. If you ask me C# is better!  It's my site, and what I say goes.

 

Anyways, here is the code if anyone is interested, it requires you set up your own data access (I used Linq) or just manually add in employees.  It's not perfectly balanced with smaller groups of people, but it does a pretty good job.



Currently rated 5.0 by 2 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: ,

c# | steal some code | vb

Related posts

Add comment

Name*
E-mail* (Gravatar)
Website
Country   Country flag

Comment* [b][/b] - [i][/i] - [u][/u]- [quote][/quote]




Live preview

5/12/2008 3:50:14 AM