The Nightstar Zoo

Nightstar IRC Network - irc.nightstar.net
It is currently Thu Oct 19, 2017 5:47 am

All times are UTC - 6 hours [ DST ]




Post new topic Reply to topic  [ 115 posts ]  Go to page Previous  1, 2, 3, 4  Next
Author Message
 Post subject:
PostPosted: Tue Jan 11, 2005 3:00 pm 
Chalain wrote:
Okay, there's bad code and then there's evil code, and the difference is pretty much whether or not the code wears a stylish cape and has a secret lair.


Greatest quote I've heard all day. Granted, I just got up, but I think this one will stand the test of time.

Chalain wrote:
Anyway, long story short. I fixed the code. But you need to understand something: I'm a right bastard. Here is my replacement code. This program compiles and runs just duckily.


Just an FYI, from the perspective of a maintenance programmer, the code you replaced it with was not an improvement.


Top
  
 
 Post subject:
PostPosted: Tue Jan 11, 2005 6:06 pm 
Offline
Nightstar Graveyard Daemon
User avatar

Joined: Mon Jun 03, 2002 8:30 pm
Posts: 1071
Location: Wouldn't you rather observe my Velocity?
To repeat: I'm a right bastard. :-)

This code serves a purpose: I *want* it to annoy the maintenance programmer that comes behind me. There's a very good chance that said programmer will be the original author, and this code will spark an argument in the break room... which is exactly what I want.

If this code made you wince and say, "Ewww, that's UGLY"... then it served it's purpose. Both the original code and the new code are ugly. My code is just more honest/explicit about it.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 11, 2005 6:45 pm 
Offline
Entertainment
Entertainment
User avatar

Joined: Sat May 11, 2002 7:55 pm
Posts: 867
Location: 59°20'N 18°03'E
If this is a C++ project, why use C-style casts?

foo=static_cast<FOO>(bar=static_cast<BAR>(baz=static_cast<BAZ>(qaz=static_cast<QAZ>(qux=QUX_NONE))));


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 11, 2005 8:50 pm 
Bo Lindbergh wrote:
foo=static_cast<FOO>(bar=static_cast<BAR>(baz=static_cast<BAZ>(qaz=static_cast<QAZ>(qux=QUX_NONE))));


AUUUGGGHH!!! MY EYES!!!!


Top
  
 
 Post subject:
PostPosted: Wed Jan 12, 2005 12:21 am 
*vomit*

While C++ casts are an imrpovement in some ways, the syntax is hideous, and that kind of abuse is simply.... *shudder*


Top
  
 
 Post subject:
PostPosted: Wed Jan 12, 2005 2:25 am 
Schol-R-LEA wrote:
*vomit*

While C++ casts are an imrpovement in some ways, the syntax is hideous, and that kind of abuse is simply.... *shudder*


Which means it'd be even more effective for Chal's purpose! ;)


Top
  
 
 Post subject:
PostPosted: Mon Jan 17, 2005 3:10 pm 
Offline
Nightstar Graveyard Daemon
User avatar

Joined: Mon Jun 03, 2002 8:30 pm
Posts: 1071
Location: Wouldn't you rather observe my Velocity?
Bo Lindbergh wrote:
If this is a C++ project, why use C-style casts?

foo=static_cast<FOO>(bar=static_cast<BAR>(baz=static_cast<BAZ>(qaz=static_cast<QAZ>(qux=QUX_NONE))));


Gentlemen, behold the master.

To quote Strong Bad, "Now THAT'S what I'm talking about! It's... I'm... you... hibbita... jiggaba... hub... I'm buying you a pizza!"


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 20, 2005 7:02 pm 
Code:
void CTestApp::SleepAndPoll(DWORD dwms) {
  while(dwms>100) {
    sleep(90);
    MSG msg;
    while(PeekMessage(&msg,0,0,0) {
      if(!GetMessage(&msg,0,0,0)) {
        PostQuitMessage(0);
        return;
      }
      TranslateMessage(&msg);
      DispatchMessage(&msg);
    }
    dwms-=100;
  }
}


This is called by my test suite any time it has to wait for the video software to do something before the next part of the test.

Why does this code bother me? Because it had to be written.

Why did it have to be written? Because the last line in InitApplication() is SendMessage(WM_RUNTESTSUITE), a message which, when handled, causes the entire test suite to run (sequentially) on the thread that called it. Once the suite has finished running, it returns through the handler, SendMessage() returns, and then InitApplication finally returns control to WinMain.

At this point, WinMain formally enters its message loop. However, the only message remaining is the quit message. The whole test suite has completely run before WinMain enters its message loop.

And if this doesn't bother you, then you're not a Win32 API programmer.


Top
  
 
 Post subject:
PostPosted: Fri Jan 21, 2005 7:30 pm 
Pi wrote:
Code:
void CTestApp::SleepAndPoll(DWORD dwms) {
  while(dwms>100) {
    sleep(90);
    MSG msg;
    while(PeekMessage(&msg,0,0,0) {
      if(!GetMessage(&msg,0,0,0)) {
        PostQuitMessage(0);
        return;
      }
      TranslateMessage(&msg);
      DispatchMessage(&msg);
    }
    dwms-=100;
  }
}


This is called by my test suite any time it has to wait for the video software to do something before the next part of the test.

Why does this code bother me? Because it had to be written.

Why did it have to be written? Because the last line in InitApplication() is SendMessage(WM_RUNTESTSUITE), a message which, when handled, causes the entire test suite to run (sequentially) on the thread that called it. Once the suite has finished running, it returns through the handler, SendMessage() returns, and then InitApplication finally returns control to WinMain.

At this point, WinMain formally enters its message loop. However, the only message remaining is the quit message. The whole test suite has completely run before WinMain enters its message loop.

And if this doesn't bother you, then you're not a Win32 API programmer.


I'm not a Win32API programmer and it bothers me.

Constructors are there to put it together so it can run elsewhere, they aren't there to run the whole darn thing. :P


Top
  
 
 Post subject:
PostPosted: Fri Jan 28, 2005 11:05 am 
Offline
Nightstar Graveyard Daemon
User avatar

Joined: Mon Jun 03, 2002 8:30 pm
Posts: 1071
Location: Wouldn't you rather observe my Velocity?
I will admit that I took this from the page on how to write unmaintainable code, but this code *does* compile under MSVC. I was feeling kinda punchy today and decided to mess with my coworkers.

No, I did not check in the code. It was enough to ask Matt to review my code and watch his diaper fill with bricks. For clarity, the first three lines of the loop are what it should be, and what I checked in. The second set of three are what I showed my coworker.

Code:
   for(int i=0; i<NUM_PORTS; ++i)
   {
      m_baHOButtonEnabled[i] = false;
      m_baLPMLightsEnabled[i] = false;
      m_baEnableAutoUnclamp[i] = true;

      m_baHOButtonEnabled[i] = false;
      *(m_baLPMLightsEnabled + i) = false;
      i[m_baEnableAutoUnclamp] = true;
   }


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 08, 2005 8:08 pm 
Offline
Nightstar Graveyard Daemon
User avatar

Joined: Mon Jun 03, 2002 8:30 pm
Posts: 1071
Location: Wouldn't you rather observe my Velocity?
Found this little gem in our *production* codebase today.

Code:
void CClass::Foo(void) {
    operator->()->Bar();
}


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 08, 2005 10:58 pm 
Chalain wrote:
Found this little gem in our *production* codebase today.

Code:
void CClass::Foo(void) {
    operator->()->Bar();
}


...what?


Top
  
 
 Post subject:
PostPosted: Wed Feb 09, 2005 9:45 am 
Offline
Entertainment
Entertainment
User avatar

Joined: Sat May 11, 2002 7:55 pm
Posts: 867
Location: 59°20'N 18°03'E
Equivalent to
Code:
void CClass::Foo(void) {
    (*this)->Bar();
}
or even
Code:
void CClass::Foo(void) {
    this[0]->Bar();
}

but longer. As for clarity, they all lose....


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 09, 2005 11:51 am 
Offline
Safari Exhibit
Safari Exhibit
User avatar

Joined: Mon Feb 07, 2005 3:48 am
Posts: 151
Location: Durban, South Africa
I don't have an example handy (fortunately the offending code is long dead) but I was once given some GUI code (fltk on a PDA running linux) to update. The code read a bunch of GPS coordinates from a file of test coordinates and displayed them on the screen. My job was to modify the display code to read real GPS coordinates from the shared memory my driver wrote them to.

Five thousand lines of C++ (mostly machine generated)
One file
Two comments, both commenting out code
Random indentation (even on the machine generated code)

The code that read from the file segfaulted as soon as I tried to get data from anywhere else. It was calling all sorts of functions all over the place, creating and destroying objects left, right and centre and generally behaving badly. After a week of trying to trace execution flow (reindenting the relevent sections, printing the lot out with syntax hilighting, drawing arrows all over it, etc.) I gave up and rewrote the code from scratch. The rewrite took me a little under a week, come to about 500 lines and worked.

The original code was written as a final year design project for an electronic engineering degree. The student passed. Kind of makes me wonder what my degree is worth, now...


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 16, 2005 3:20 am 
If anyone needs any more grist for this mill, take a look at the jaw-droppers listed here. It's hard to believe some of these 'IT Professionals' are capable of breathing unassisted, never mind coding.

Dear Goddess, some of those stories are appalling. A 1.47M VB class with 309 instances of dead code (not counting two or three thousand lines of commented out code)? A 230-line Java method with a CCM of 150? A Java package named "mrpd.mrr"? A FORTRAN function with 292 arguments? I think I'm going to be sick again...

And if those aren't bad enough, check out The Daily WTF and Coding Horrors for some more true atrocities.


Top
  
 
 Post subject:
PostPosted: Wed Feb 16, 2005 11:52 am 
Schol-R-LEA wrote:
If anyone needs any more grist for this mill, take a look at the jaw-droppers listed here. It's hard to believe some of these 'IT Professionals' are capable of breathing unassisted, never mind coding.


Quote:
$q1 = "an SQL query";
$q2 = "another SQL query";
...
$qn = "the nth SQL query";
.
.
.
for ($i = 1; $i < 9; $i++) {
$qi = "q$i";
$q = $$qi;
query($q);
}


Apparently this fellow was not familiar with arrays.


AAAAAAAAAAAAAAAAAAAAAHHHHHHHHHHHHHHHHH!!!


Top
  
 
 Post subject:
PostPosted: Wed Feb 16, 2005 12:25 pm 
Two months ago, I made the mistake of walking into a quagmire, and of my own free will at that. On the Dev Shed Java forum, someone had posted a request for help in converting a C++ program to Java. The 'programmer' only posted a short section of code initially, but it was clear from it that he knew little C++ and even less Java. Still, I figured that I'd give some general advice, and that he would be able to go on his way.

I asked him to post the full existing code, which he did, both the original C++ code and the attempted Java conversion. Even a quick look at the code made my heart sink. This was an utter disaster!

The program was intended to create viewable web pages from existing chromosome data. It read the data from a DMBS table and generated two output files, one in HTML and the other in a format called FLY. There were 8 main fields in the table, which the program(s) read into separate variables helpfully named para1, para2, ... para8 sigh.

The program logic was a mess; most of it was in one huge function, and the logic of the data reading, data checking and file generation were all tangled together. Much of the code was repetitive and naive, such as this set of 25 successive string writes with only a single change in each string (from the original C++ code):
Code:
   //write the name out
   out<<"string 10,1,1,25,60,small,CHR1"<<"\n";
   out<<"string 10,1,1,60,60,small,CHR2"<<"\n";
   out<<"string 10,1,1,95,60,small,CHR3"<<"\n";

     // ... code repeats itself like this

   out<<"string 10,1,1,95,60,small,CHR25"<<"\n";


Even worse were the huge switch ctatements and extended if() blocks for what were effectively table crossreferences:

Code:
         switch(geneTwoSeqNO)
         {
            case 1: para6="112",para7="128",para8="144";
               break;
            case 2: para6="100",para7="149",para8="237";
               break;
            case 3: para6="0",para7="255",para8="127";
               break;

         // again, the code repeats through 25 sets of values

            case 25: para6="176",para7="48",para8="96";
               break;
         }


and

Code:
            if(hchr=="chr1")
            {
            out<<"string 10,1,1,5,25,small,CHR1"<<"\n";
            out<<"rect 40,20,1070,40,10,10,10"<<"\n";
            }
            else if(hchr=="chr2")
            {
            out<<"string 10,1,1,5,25,small,CHR2"<<"\n";
            out<<"rect 40,20,1060,40,10,10,10"<<"\n";
            }
            else if(hchr=="chr3")
            {
            out<<"string 10,1,1,5,25,small,CHR3"<<"\n";
            out<<"rect 40,20,875,40,10,10,10"<<"\n";
            }

             // repeats 21 times, followed by two
             // exceptional cases for the sex chromosomes

            else if(hchr=="chr22")
            {
            out<<"string 10,1,1,5,25,small,CHR22"<<"\n";
            out<<"rect 40,20,250,40,10,10,10"<<"\n";
            }

            else if(hchr=="chrX")
            {
            out<<"string 10,1,1,5,25,small,CHRX"<<"\n";
            out<<"rect 40,20,685,40,10,10,10"<<"\n";
            }

            else if(hchr=="chrY")
            {
            out<<"string 10,1,1,5,25,small,CHRY"<<"\n";
            out<<"rect 40,20,140,40,10,10,10"<<"\n";
            }


These were just the trivial problems; the real problem with the program was the ad hoc control flow, and the complete lack of modularization. Eventually, I decided to simply re-write the damn thing for the poor bastard as best I could, despite the fact that I didn't have all the information needed to do so and couldn't test the final results. While I felt pretty good about the final result (though I probably overdid it; I ended up with 7 classes), it was a real challenge trying to puzzle through just how the program was supposed to work.


Top
  
 
 Post subject:
PostPosted: Fri Feb 18, 2005 3:57 pm 
Today's Daily WTF once again demonstrates that no matter how simple the task, someone will find a way to make it ridiculously complicated.


Top
  
 
 Post subject:
PostPosted: Fri Apr 08, 2005 6:58 pm 
All of these examples came from the same project, written by the same programmer. Program A is the main program for the project. Program B is a data-viewer type app that can either be run from Program A, or stand alone. The actual code is long dead, so I'm reconstructing it from memory as best I can.

  • Example One, Program A launching Program B.

    Program A:

    Code:
    AlterProgramINI()
    Shell("progb.exe", 1)

    <big snip>

    Sub AlterProgramINI()
        Open "progb.ini" For Output As #10
        Print #10, filename
        Close #10
    End Sub


    Program B:

    Code:
    Sub LoadFile()
        Open "progb.ini" For Input As #2
        Get #2, filename
        Close #2
        LoadDataFile()
    End Sub


    For those who don't read VB: Rather than passing the file name on the command line, program A would write the name to a text file, then program B would open and read that file to find the actual name of the data file. To make things worse, neither program would delete the text file once it was done.
  • Example Two, viewing text data from Program A:

    Program A:

    Code:
    Shell ("C:\Windows\Command\edit.com " + datafilename, 1)


    That's right. A hard-coded path to an external text editor.
  • Example Three (the best one in the bunch), Program B doing some graphics.

    Program B:

    Code:
    Public index as Integer
    Public coordIndex as Integer
    Public fromX as Integer
    Public fromY as Integer
    Public toX as Integer
    Public toY as Integer

    <big snip>

    For index = 1 to count
        DrawDataAtIndex()
    Next index

    <big snip>

    Sub DrawDataAtIndex()
        For coordIndex = 1 to rawdata(index).coordCount - 1
            fromX = rawdata(index, coordIndex).X
            fromY = rawdata(index, coordIndex).Y
            toX = rawdata(index, coordIndex + 1).X
            toY = rawdata(index, coordIndex + 1).Y
            pBox.Line(fromX, fromY) - (toX, toY)
        Next coordIndex
    End Sub


    The entire program was like this. Not a single local variable or argument in 10,000+ lines of code.

    EVERY SINGLE VARIABLE AND FUNCTION ARGUMENT WAS A GLOBAL VARIABLE!

    That was the point that I decided to rewrite it from scratch.


This was all production code.

<edit>Accidentally put some C syntax in my VB. I'm more used to C, and like I said, I'm reconstructing this from memory.</edit>


Last edited by SomebodyElse on Sun Apr 10, 2005 3:56 pm, edited 1 time in total.

Top
  
 
 Post subject:
PostPosted: Sat Apr 09, 2005 12:35 am 
SomebodyElse wrote:
The entire program was like this. Not a single local variable or argument in 10,000+ lines of code.

EVERY SINGLE VARIABLE AND FUNCTION ARGUMENT WAS A GLOBAL VARIABLE!

That was the point that I decided to rewrite it from scratch.
[/list]

This was all production code.


I hope you disposed of the original programmer in a humane manner.


Top
  
 
 Post subject:
PostPosted: Sat Apr 09, 2005 11:25 am 
SomebodyElse wrote:
Example One
[...]
For those who don't read VB: Rather than passing the file name on the command line, program A would write the name to a text file, then program B would open and read that file to find the actual name of the data file. To make things worse, neither program would delete the text file once it was done.


As sad and ugly as this is, it's not quite so inexcusable as the other two, as many VB programmers (at least for versions before .NET) were unaware that VB programs could take command line arguments (and some probably didn't even know what those were). It's still pretty awful, but not, sad to say, a surprise.

SomebodyElse wrote:
Example Two, viewing text data from Program A:

Program A:

Code:
Shell ("C:\Windows\Command\edit.com " + datafilename, 1)


That's right. A hard-coded path to an external text editor.


What I find amusing, aside from the basic WTF involved in using a hardcoded path, is that fact that it's shelling out to the MS-DOS editor... at least, I'm assuming that you took that more or less from the original.

SomebodyElse wrote:
Example Three (the best one in the bunch), Program B doing some graphics.
[...]

The entire program was like this. Not a single local variable or argument in 10,000+ lines of code.[...] EVERY SINGLE VARIABLE AND FUNCTION ARGUMENT WAS A GLOBAL VARIABLE!


facepalms This sort of thing makes me want to weep, it really does.

SomebodyElse wrote:
That was the point that I decided to rewrite it from scratch.


No one could blame you, no one at all.

SomebodyElse wrote:
This was all production code.


I truly wish I could say that this was a surprise...


Top
  
 
 Post subject:
PostPosted: Sun Apr 10, 2005 4:10 pm 
gwalla wrote:
I hope you disposed of the original programmer in a humane manner.


Humane? Humane!? Oh, no, I was very... um... "inhumane."

Or at least I would have been, had the programmer in question not been long gone.

Schol-R-LEA wrote:
SomebodyElse wrote:
Example Two, viewing text data from Program A:

Program A:

Code:
Shell ("C:\Windows\Command\edit.com " + datafilename, 1)


That's right. A hard-coded path to an external text editor.


What I find amusing, aside from the basic WTF involved in using a hardcoded path, is that fact that it's shelling out to the MS-DOS editor... at least, I'm assuming that you took that more or less from the original.


Yes, that's correct. To make matters worse, the lead on this project is an "old school" engineer, who automatically assumes change == bad, until proven otherwise (and requires a great deal of proof). Ergo, the default for that program is still the MS-DOS editor. At least it's user-configureable now.


Top
  
 
 Post subject:
PostPosted: Fri May 06, 2005 12:20 am 
Offline
Nightstar Graveyard Daemon
User avatar

Joined: Mon Jun 03, 2002 8:30 pm
Posts: 1071
Location: Wouldn't you rather observe my Velocity?
I made up a saying years ago. "Perl is loose, but PHP is a slut."

PHP lets you create classes, and even does some simple inheritance. To write a constructor, you simply write a function that has the same name as the class:

Code:
class A {
    function A() {
        print "Hello from A's ctor!";
    }
}

$a = new A();


This very reasonably outputs the string "Hello from A's ctor!".

Okay. So I read something in the PHP manual that got me thinking, and I wrote some code to test my hypothesis, and it made me go $#!@!!!, and so of course I have to post it here.

Here's the thing. When PHP creates an inherited class, it creates a function table of the parent class functions, then overlays the child class functions into the same namespace. This means that A::foo() and B::foo() get written to the same place in B's function table (much like a virtual method in C++). This is okay. The part that is not okay is that PHP makes no distinction between A's methods and B's methods. They are all just considered to be B's methods.

This means that you can put a child's ctor in the parent class.

If the child then writes its own explicit ctor, it overrides the parent's method and all is well. But if A writes it and B omits it....

Code:
class A {
    function A() {
        print "Hello from class A's constructor!";
    }
    function B() {
        print "Hello from class A's method B!";
    }
}

class B extends class A {
    function C() {
        print "Hello from class B's method C!";
    }
}

$b = new B();


You get this output: "Hello from class A's method B!"

:: boggle ::


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 20, 2005 1:33 am 
Offline
Safari Exhibit
Safari Exhibit
User avatar

Joined: Mon Feb 07, 2005 3:48 am
Posts: 151
Location: Durban, South Africa
I'm spending a lot of time this week marking programming assignments, which generates a lot of really bad code. Most of it is just newbie mistakes, but every now and then I get something LARTworthy. This one is a design choice. Well, not so much a design choice as a "whose code shall I copy?" choice.

The assignment was to use the Newton-Rahpson method to take a square root. (The only relevent detail is that it's an iterative process.) The students were required to provide both a manual "one iteration at a time" evaluation method and a partly automated "do N iterations for me" method. The standard way of doing this is having two text boxes (one each for the operand and the number of iterations to automate) and two buttons (one for a single iteration, one for N iterations).

One particular student had these two text boxes and both buttons. The "manual" button worked fine. The "automatic" button threw up an input dialog asking for the operand, ignoring the operand already given in the text box. Then it threw another input box asking for the number of iterations.

As far as I can make out he copied the manual code from one person and the automatic code from someone else. After marking this steaming pile of excrement, I went on to the next student -- who had exactly the same code (down to the typos and bad grammar in the interface) but randomly commented.

People, if you're going to steal code, steal code that *works*!


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 23, 2005 1:53 pm 
jerith wrote:
The assignment was to use the Newton-Rahpson method to take a square root. (The only relevent detail is that it's an iterative process.) The students were required to provide both a manual "one iteration at a time" evaluation method and a partly automated "do N iterations for me" method. The standard way of doing this is having two text boxes (one each for the operand and the number of iterations to automate) and two buttons (one for a single iteration, one for N iterations). [emphasis added - Schol]


If you don't mind me asking, why go to the trouble of having a GUI interface for something like this, especially in a beginning class? IME, focusing on UI when studying algorithms usually a) confuses the topic at hand, with the result that the students focus on the UI (even if it is a minimal, standard one) and not on the function they are supposed to write, and b) results in convoluted, ugly code where the UI and the operational code are tangled up together.

Of course, I don't know the circumstances of the course, so I can imagine cases where using a GUI is easier than using text-mode; I would expect that in such cases, the student assignment would be to write a function f() with such and such parameters and such and such results, which the GUI would then automatically call. I know that this is done with much of the practice code in How to Design Programs, for example.

OTOH, if you are using a GUI because the system in question doesn't have a text mode - VB 6 for example - well, that's a poor choice of development tool. Trying to teach good programming habits in VB6 is like trying to teach good hygiene in a sewer - the environment you are in fights the effort every step of the way.


Top
  
 
 Post subject:
PostPosted: Tue May 24, 2005 12:37 am 
Offline
Safari Exhibit
Safari Exhibit
User avatar

Joined: Mon Feb 07, 2005 3:48 am
Posts: 151
Location: Durban, South Africa
Schol-R-LEA wrote:
[Much good stuff]


Yes, VB6 is the development environment of "choice". I've been trying to get the lecturer to change to something else since I took the course myself five years ago. It looks like they might be switching to Java sometime, which is a step in the right direction, but not a big enough step. Something like Python where
Code:
print "Hello World"
is a valid program and things can be introduced one step at a time with the voodoo mindset ("Ignore all this boilerplate for now...") is far better IMHO.

Fortunately, this afternoon is my final marking session. Next semester I get to try to undo all the damage VB has done when they learn C.

An aside: Yesterday, of the five people I assisted or marked, one had properly indented code and two hadn't even bothered to try. Of the four problems, three of them were misplaced or missing "End If" statements. Why do I even bother any more?


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 24, 2005 11:17 am 
jerith wrote:
Schol-R-LEA wrote:
[Much good stuff]


Yes, VB6 is the development environment of "choice". I've been trying to get the lecturer to change to something else since I took the course myself five years ago. It looks like they might be switching to Java sometime, which is a step in the right direction, but not a big enough step. Something like Python where
Code:
print "Hello World"
is a valid program and things can be introduced one step at a time with the voodoo mindset ("Ignore all this boilerplate for now...") is far better IMHO.


Very agreed. Of the current languages, I would say the best ones for beginners are Python and Ruby(though I don't know very much about Ruby to be honest). While I also like Scheme as a beginner's language (as you may have already guessed), it is a bit too far out of the mainstream - if the students are familiar with other languages already, they are likely to find it confusing. Most compiled languages are terrible for beginning programmers, because they have a certain fixed overhead (which usually gets handwaved with some kind of boilerplate code, as you point out - with the result that the student doesn't really understand what they are doing). Also, having a listener available for typing in and running snippets of code interactively gives the students a sense of immediacy that is lacking in compiled code, and alllows them to see how pieces of a program work without having to write the whole thing. While the default Python listener is a bit spartan, combined with a nice, simple editor/interpreter environment like Dr Python (which is patterned after one of my all-time favorite IDEs, Dr Scheme)


Top
  
 
 Post subject:
PostPosted: Tue Jun 14, 2005 12:07 am 
Once again, today's Daily WTF has a picked a winner. PHEER T3H HARD-KODE|> SQUEEL KOOCIE!


Top
  
 
 Post subject:
PostPosted: Wed Jun 15, 2005 8:58 pm 
JESUS GOD

It's a fucking COOKIE. An entire ginormous SQL query in a COOKIE.


Top
  
 
 Post subject:
PostPosted: Mon Jun 20, 2005 2:01 am 
Some of the most frightening code I've ever seen was written by me (many years ago, of course.) I'm fairly active in a game called Furcadia (hush you, yes it's furry, no I'm not) and one of the more popular tech support requests is info on making "bots" (mostly equivalent to NPCs for users' maps.) I took it upon myself to write a scripting language for such bots that was designed similarly to the scripting language used in the actual game for animating maps and such (my language would run in an external bot application.) An example of this language is as follows:

Code:
(0:1) When somebody speaks,
    (1:6) and [TRIGGERING_MESSAGE] contains {damn},
    (1:50) and the current time is before 21:00 on a twenty-four hour clock,
    (2:6) whisper {It's too early to swear in this dream. Wait until 9:00 PM.} to the triggering person.
    (2:22) eject the triggering person from this map.


Wonderful. Works like a charm. Surprising that it works well at all, considering the part of code that turns all that into actual executed code is one ginormous SELECT CASE block. And here's the clincher: it's not selecting the case of the numbers at the start of each line (as one would expect); it's selecting the case of the two numbers concatenated as a string by a single period, turning what could have been a simple jump table into IF/ELSEIF/ELSEIF/ELSEIF/ELSEIF/ELSEIF...

Code:
Select Case Lines(i).nClass & "." & Lines(i).nID
    'cases cases cases

    Case "1.50"
        If Not CDate(Hour(Time) & ":" & Minute(Time)) < _
        CDate(thesevars(1).Value & ":" & thesevars(2).Value) Then Exit For
    Case "1.51"
        If Not CDate(Hour(Time) & ":" & Minute(Time)) = _
        CDate(thesevars(1).Value & ":" & thesevars(2).Value) Then Exit For
    Case "1.52"
        If Not CDate(Hour(Time) & ":" & Minute(Time)) > _
        CDate(thesevars(1).Value & ":" & thesevars(2).Value) Then Exit For
    Case "1.53"
        If Not Date < _
        CDate(thesevars(1).Value & "/" & MonthName(thesevars(2).Value) & "/" & thesevars(3).Value) Then Exit For
    Case "1.54"
        If Not Date = _
        CDate(thesevars(1).Value & "/" & MonthName(thesevars(2).Value) & "/" & thesevars(3).Value) Then Exit For
    Case "1.55"
        If Not Date > _
        CDate(thesevars(1).Value & "/" & MonthName(thesevars(2).Value) & "/" & thesevars(3).Value) Then Exit For

    'cases cases cases
End Select


I look back on that code (since entirely rewritten, far faster, and far more powerful) and ralph all over the rug. It's times like these I wish I hadn't started programming with QuickBasic and am glad I no longer code in any BASIC variant on any regular basis.


Top
  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 115 posts ]  Go to page Previous  1, 2, 3, 4  Next

All times are UTC - 6 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group