Linked by Thom Holwerda on Tue 15th Jan 2013 21:24 UTC
General Development "I was really excited to write this article, because it gave me an excuse to really think about what beautiful code is. I still don't think I know, and maybe it's entirely subjective. I do think the two biggest things, for me at least, are stylistic indenting and maximum const-ness. A lot of the stylistic choices are definitely my personal preferences, and I'm sure other programmers will have different opinions. I think the choice of what style to use is up to whoever has to read and write the code, but I certainly think it's something worth thinking about. I would suggest everyone look at the Doom 3 source code because I think it exemplifies beautiful code, as a complete package: from system design down to how to tab space the characters." John Carmack himself replies in the comments.
Thread beginning with comment 548985
To view parent comment, click here.
To read all comments associated with this story, please click here.
RE: Good article
by henderson101 on Wed 16th Jan 2013 10:39 UTC in reply to "Good article"
henderson101
Member since:
2006-05-30

IMHO, having a terminating statement like 'END IF' is a lot more elegant than having braces all over the f**king place.


No, no it's not. You try to maintain someone else's VB.Net app... "End If"'s (and "End ..." blocks in general) are complete crud. Braces are only complicated if you don't line them up correctly.. but most modern IDE's don't even make that hard. I far prefer '}' to working out which flavour of 'End ...' is missing in a VB method that some idiot made span 3 or 4 screens. Dometimes life is too short to not refactor, and moving VB code to C# is not all that hard. In fact, the last time I did that I fixed about 3 or 4 obscure bugs that VB introduced due to it's utter shit syntax (and this is with Option Explicit and Option Strict on.)

Having come from a Pascal background (but having done a lot of C++ in my BeOS days, ADA at university and BASIC before that), the "begin .. end" block teaches you much better practices than C's braces. There are plenty of places I will use a block where other programmers will not, mainly because it saves time in the long run.

And don't even get me started on semi-colons ;)


The semi-colon is a fairly unambiguous end of statement marker. If that is hard to understand, you are pretty much doomed.

Reply Parent Score: 2

RE[2]: Good article
by Treza on Wed 16th Jan 2013 12:09 in reply to "RE: Good article"
Treza Member since:
2006-01-11

I use both punctuation (C) and verbose (ADA) languages and tolerate both well.

The solution is a syntax colouring editor with very different colours for keywords and plain identifiers (not black and dark blue...)

The begin/end stuff becomes colorful patches surrounding black code.

Reply Parent Score: 1

RE[3]: Good article
by henderson101 on Wed 16th Jan 2013 12:31 in reply to "RE[2]: Good article"
henderson101 Member since:
2006-05-30

I use both punctuation (C) and verbose (ADA) languages and tolerate both well.


With ADA (83) we always had a "BEGIN" and an "END xxxx;" for all constructs, save possibly the "REPEAT... UNTIL ...", though it's been a good 20 years since I did any ADA and I don't remember it well. Same with Pascal (Object Pascal; Delphi.) With VB you don't. You get this:


If X Is Nothing Then
Something
Somethingelse
Elseif Blah = "Give up" Then
Somemore
Else
ShootYourself(DateTime.Now)
End If


Compare that to the C#


if (X == Null)
{
Something();
Somethingelse();
}
else if (Blah == "Give up")
{
Somemore();
}
else
{
ShootYourself(DateTime.Now);
}


Or Pascal


if (X <> Nil) Then //Or is it "X is nil"? I forget
begin
Something();
Somethingelse();
end
else if (Blah = 'Give up') Then
begin
Somemore();
end
else
begin
ShootYourself(DateTime.Now);
end;


The beauty Pascal is that the entire If is one statement with compounds, the beauty of the C# is that it is not (really.) Both have advantages.

EDIT: remembering to add the actual point: The blocks make it easy to see what belongs where, where as with VB and other non block delimited languages, it's all about context.

The solution is a syntax colouring editor with very different colours for keywords and plain identifiers (not black and dark blue...)

The begin/end stuff becomes colorful patches surrounding black code.


Yeah, that's kind of okay. But again, when the code spans 3 or 4 screens (bad coding practice, horrible to maintain) it's more about refactoring to a sane state initially. Syntax highlighting has come a long way. The first editor I used on a daily basis was Delphi 1 and the syntax highlighting was very simple and the code insight did not exist. You had to actually know what to type - a skill lost by many recent CS graduates.

Edited 2013-01-16 12:35 UTC

Reply Parent Score: 2

RE[2]: Good article
by lucas_maximus on Wed 16th Jan 2013 13:15 in reply to "RE: Good article"
lucas_maximus Member since:
2009-08-18

Normally most formatting problems can be sorted with the IDE.

TBH a lot of the problems you describe are more to do with the way the applications have been written and not the language itself. I am sure I can point you to some of the atrocities I have seen in C# (my favourite being the INullObject interface I recently found).

Personally I like VB.NET, while the syntax is odd you can write code pretty quickly. My main issue with the language is that it is difficult to see the difference at a glace between an array and a procedure/function.

A lot of newer developers especially those coming from Python or Ruby find the use of a semi-colon slightly arduous. There was recently a flame war between Douglas Crockford and one of Twitter Bootstrap developer over whether you should make of the JavaScript semi-colon insertion mechanism.

Edited 2013-01-16 13:16 UTC

Reply Parent Score: 3

RE[3]: Good article
by Nelson on Wed 16th Jan 2013 16:05 in reply to "RE[2]: Good article"
Nelson Member since:
2005-11-29

Ugh, that NullObject b.s is the kind of ridiculous over abstraction that you see from Java Programmers who move on to C#.

It is incredible the amount of gunk that Java programs have. Seriously. I'm convinced Java is just a collection of terrible design patterns looking for a problem.

Reply Parent Score: 2

RE[3]: Good article
by henderson101 on Wed 16th Jan 2013 16:38 in reply to "RE[2]: Good article"
henderson101 Member since:
2006-05-30

Personally I like VB.NET, while the syntax is odd you can write code pretty quickly.


Oh jesus.. no it's not! Here is an example:

Define a class and on that class create a public event


Public Class Whatever
  ...
  Public Event MyEvent(ByVal SomeValue As String)
  ...
  Public Sub RunHack(ByVal whatever as String)
    MyEvent(whatever);
  End Sub
End Class

Then in another class try this:


Public Class TwatFace
  ...
  WithEvents myHack as Whatever
  ...
  ...
  Public Sub ABadIdea(ByVal whatever as String) handles myHack.MyEvent
    MsgBox(whatever)
  End Sub
  ...
  Public Sub LetsBreakEventHandling()
    Dim fcukit As New Whatever
    myHack = fcukit
    myHack.RunHack("Shoot yourself now...")
  End Sub
  ...
End Class


What happens if we call LetsBreakEventHandling? Well, it should never compile... it does. It should probably freak out and crash, but you'll see a message box happily telling you "Shoot yourself now...". And I know all of this because the fcukwit programmers, on contract from India, that we used before I took over didn't know about "AddHandler Xxxxx, AddressOf Yyyyy".

Even with option explicit and strict on, you can do this:


Dim X as Integer
X = 99
Dim Y as Boolean ''uninitialised, so compiler decides

Select Case X
  Case 1, 2
    Something()
  Case 3, 4
    Somethingelse()
  Case Y
    WhatThef--kDoesThisEvaluateTo()
End Select


VB is dangerous, plain and simple and there's nothing you can do in VB that can't be done in a safer .Net language at a similar speed.

Edited 2013-01-16 16:43 UTC

Reply Parent Score: 2