The most ugliest code yet
In your carreer as professional developer you come across some ugly code, many would not believe if you told them. Once on a project (hi Ernst) I saw some pretty ugly code in one line. It was C# and was something like this:
public void DoSomething()
{
Order order = new Order();
}
This code can be your thing, but I really dislike this kind of coding and always name my objects in a more readable style. For example, take myOrder or completeOrder or anything else thats more appropriate for the object. But I never use the name of the class and change some capital and use it as a name for my object.
Until yesterday, when I give class with another collegue to some other collegues who weren’t that familiar with .NET. Then I saw the most ugliest code in my life, crammed togehter in one line.
Public Function DoSomething()
Dim Order as Order = new Order
End Function
Here we have something even worse, the name of the class and the name of its instantiated object have exactly the same name! I didn’t even know this was possible.
Maybe we shall have us a little contest. If you can provide me with code in one line that’s even more ugly then this, I’ll give you a free copy of… of… Oh, I don’t have anything to give away. Nevermind, we’ll have a contest with the prize : everlasting fame, or something…
Anyway, just had to let you know this… š
Well i like the VB part better but that is off topic.
I didn’t know the c# people cared about readabillity of the code…..
I saw this piece of text a few days ago on wasabi……
?:, ++, — Operators
C# includes ?: (conditional assignment), ++ (increment) and — (decrement) operators.
Verdict: I’ll give this one to C#, but given that these operators increase brevity at the cost of readability, you can make a case that their lack in VB.NET should really represent a win for VB.NET.
well i actually do like the
+=
-=
etc operators that do a lot for me in term of less things to type = less errors.
The annoying part of the ++ and — operators is that:
i++ != ++i
Which ofcourse is nice more power but also an increased chance for seeing errors popup.
public virtual AbstractDomainEntity DoLazyLoad(AbstractDomainEntity obj, DataRow dr)
{
try
{
((Batch)obj).ID = dr["bat_BatchId"].ToString();
return obj;
}
catch(ArgumentException ex)
{
throw new FailedToLoadEntityException("Failed to load batch entity from row data.", ex);
}
}
Iām blushing š