Coffeehouse Thread

26 posts

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

What's the best bit of code you have ever written?

Back to Forum: Coffeehouse
  • User profile image

    It's the eve of Developer Developer Developer Day II UK and I'm thinking about coding (as one may do whilst visiting these here pages  at the knightly Channel 9 me duff think?)

    ... and I had a bit of a nostalgia kick think about the kick-arse programs and code I've written in my time, so I thought this would be a good opportunity to share some of our stories which is what C9 is best for.


    Anyway I wrote an Easter egg inside a program that would display a different message after a random amount of time of using the program of why the program really hated this particular person (I did it because I really hated him) then the machine would perform some random act which I coded as well such as a reboot, or the screen go black and white, or change the res, or email pictures of the bosses head on a goat from his account. Loads of fun! I spent a month writing the program and two months writing the Easter Egg and I could auto configure it remotely so I could continue to add more fun!

    As this program was one he would use everyday, he just didn't figure it out.

    The thing that makes me laugh is that i didn't switch the program off before I left, that was nearly eight years ago!

    Childish yes! Very, and I do regret it, it's not big or clever. But at the end of the day he did drive into the back of my new car and then drove away (he boasted about it)... and stole my girlfriend in the same week!

    You know ... Coders could rule the Earth if we didn't stop fighting amongst ourselves over which OS or language is best.Sad

  • User profile image

    Why are you returning EXIT_FAILURE?  Plus you shouldn't use a constant char \n, you should use a constant defined by the header on the platform you're compiling for.

    PS - Sometimes I'm an * too! Tongue Out

  • User profile image

    if a != b then goto END

    print "What the f*** are you doing!"

  • User profile image

    This is the 1st piece of code I wrote, and for sentimental reason, the best:

    20 PRINT "YOUR NAME IS "; A$

  • User profile image

    I don't know about the best, but the most fun was back in my mainframe CICS days. We had a "SHOW" transaction that took different paramters to perform difference functions eg "SHOW PERFORMANCE" or "SHOW TRANSACTIONS". I took the code with me when I went to work for a hospital in the Middle-East and wrote a new "SHOW SCREEN, screenid" option that stole the 3270 buffer area of a work colleague and showed it on my screen, so that I could spy on my colleagues and say things like "Editing your CV again, Keith?" when my Canadian colleagues were using a hacky editor under CICS to edit personal stuff with the screen only visible to themselves.

    They soon cottoned on so a new "SHOW" option was called for called "CONTEMPT" - this replaced the targeted screen with my own selection of a blocky graphics of two fingers with the caption "Up yours Wally". Fun days!

    Reminded me of my first job at IBM Hursley working in "Product Assurance". I used to work in a test lab with another graduate who wasn't being given enough work to do. So he invented a simulator for IBM's VM system that captured people's passwords if they used the screen he'd set it up on. One guy was very unpopular so his password was captured and every time he logged on he sent the lab a message saying "MY security is lousy" and then wondered why he'd suddenly get a ton of replies saying "Why are you telling me your security is lousy George?". The same guy introduced the classic Adventure game to the mainframe and wrote his own Space Invaders game. He nearly got fired the afternoon he spoofed a VM id so that everyone at Hursley got a message from "BIG BROTHER" that said "I'm watching you". Luckily he got a reprieve. The guy's name was Mike Cowlishaw and he went on to invent REXX which became pretty important within IBM. Last I heard he'd become one of IBM's youngest fellows. I often wonder what would have happened if he hadn't had one of the lab's strongest managers to defend him during the times he was bored and being underutilised.

  • User profile image

    Mine would have to be the first project I did professionally after getting my degree.

    I wrote a debugger for a proprietary 'BASIC'-like language. It behaved just like the one in the compiler I was writing it with, too, very cool.

    I used a state transition table and the OWL user interface library compiling with Borland's 3.1 C++.

    I got it done in 5 weeks and got promoted to lead developer on an extended programming job in Irkutsk, Siberia.

    What a reward... though it did change my life for the better, being an ignorant American at that time...

    Later.   Cool

  • User profile image

    An awful remainder from the time when things had to be screen scraped. Years ago I thought it was the best but now I wish I never wasted time on it. Smiley


  • User profile image

    androidi wrote:
    An awful remainder from the time when things had to be screen scraped. Years ago I thought it was the best but now I wish I never wasted time on it. Smiley


    Oh my GAWD! What the hell is that! You could go blind debugging that!

  • User profile image

    I think the best piece of code you can write is the code you don't have to write or the code you are able to delete. Simple, elegant solutions tend to have less code. And one goal of refactoring is getting rid of redundancies and thereby reducing the amount of code. In fact, it's a healthy sign on software projects if the LOC decrease at the end of a development cycle. It shows that developers have a better understanding of the code and the problem and are therefore able to reduce code complexity.

  • User profile image

    I think the most rewarding of mine was when I was about 15 I wrote an SMTP and POP3 client using the winsocks control in whatever the version of VB was then.

    I got a real buzz out of pressing a button and an email appearing in my inbox.  Done a lot since, but nothing has made me grin as much as that did!

  • User profile image

    I love the bits of code where you make something everyone says is impossible in language X or operating system Y happen.

    Like, "you can't write a NT service in Visual Basic!" (been there, done that) or "you can't write a DirectX program in Visual Basic!" (been there, done that).

    My bits of code that are like that happen to be in Visual Basic, because it, like Rodney Dangerfield, gets no respect.

  • User profile image

    I was pretty pleased with my raw Win32 app in Visual Basic. I re-created the C header as a module and copied a C basic Window example, it took almost a week. Worked just like any C application would have, except with crazy hacks all over....

    I think I remember that app in a special way because *so* many people told me it was "impossible".

  • User profile image

    Mine is a very short life of writing actual program (couple of years as software dev now), but the best (most fun I had) app I wrote was a an automated build system that's currently being used at my company.

    It started as an internship project, took 4 months. There was no real specs or feature list, just "build us an automated system, that should do x,yz, projects, multi-user, etc, etc". Funny part was I took my basic client-server app in Java and wrapped it around a SQL-database, JSP pages, some build machine queue logic, security, and building scripts at the client side...and there I had it - a fully automated system that can be extended (adding new projects) in ones sleep. The project currently builds over 15 different products (about 30+ projects). Next step for me and the Build team is virtualizing this!

  • User profile image

    I was (heck, still am) quite proud of something I wrote in 1989.

    The DOS product I was working on needed to print letter quality copy onto 9 and 21 pin dot matrix printers as well as HP LaserJet compatible printers.  Most of the product was a Clippper based DB type app written by another dev, and I wrote the printing system in C and assembly.

    This was back in the 640K, 20 or 40MB hard drive days.  The Clipper code was huge, leaving me precious little memory to work with.  Some relief was provided by using the BLINKer linker to provided overlayed memory management.  Anyone from that era remembers working with this stuff.

    The print preview system was EGA and VGA video drivers, straightforward stuff.  That was fun to write, but also old hat by 1989. 

    The part I was proud of was the code that did the printing.  Essentially it took the HP soft fonts and laid out the line by blitting each character's bitmap into memory at the right position with the right kerning, leading, etc, at full 300DPI resolution.  It used multiple fonts, of course, at different sizes, etc.  There was a caching system to keep various bits of the HP soft fonts loaded, etc.

    After a line was assembled, it was time to scale the line to either EGA, VGA, 8 pin, or 21 pin printer resolution and send it to the device.  

    That's a lot easier said than done, because if you recall 21 pin printers, you didn't really get full resolution - the printhead pins were a lot bigger than the physical positioning capability of the device.  The code took that into account to position pixels, so you wouldn't get aliasing problems and the "scaled jaggy look".

    The entire font loading and converting code was C and x86 assembly language running in about 40K, IIRC. 

    Printing on a 21 pin printer could be darn slow, but it looked great.  No aliasing, no kerning problems, looked like native fonts. 

  • User profile image

    Best bit of code?

    Back in 2002 when I was getting outa the military and lived in the barracks temporarilly. I was broke and didn't have a way to get off post and no alarm clock. My neighbor was throwing out an old Zenith Data Systems laptop so I took it from him and wrote an alarm clock so I wouldn't be late to work the next morning.

    BTW: Knowing how to program a clock and alarm on a computer older than what most people even know existed got me laid as well Smiley Sometimes it's good being a geek.

  • User profile image

    The best bit of code I have writte contained also the worst.
    I once had to write a software that could simulate a specific  rapid prototyping robot.

    It was cool since it could simulate the behavior of that robot pretty well.

    It sucked because its visualisation had to be done completely via VRML, wich is very limited. The renderpath was a collection of ugly hacks and workarounds.

  • User profile image
    Dr Herbie

    Ooh, probably the project I wrote for my masters degree -- my first real Windows application.  A copy of Petzold's 'Programming Windows 3.1', a student's license for Borland C++, a brand new 25MHz  386 with a maths co-processor, an oscilloscope, and nothing else to do for three months.

    I had to write an app to capture the oscilloscope traces as EMF files, display them on screen and allow the user to adjust the oscilloscope's settings.  All communications through a serial port in the oscilloscope's ASCII text language.

    I liked the idea of controlling another machine from my code. I wrote all the code with pen and paper before typing it in (I wasn't a good typist back then).
    I didn't use MFC or OWL, I wrote it all in 'raw' Windows API code.  I re-used the serial communications code in my first professional programming job (this time to control electronic scales).

    My project supervisor used this software for several years in his day-to-day research and there was only ever one bug (an integer overflow in the graphics co-ordinate system -- I just changed the x and y co-ordinate variables to be unsigned integers and the bug was fixed).

    I wish I was still that enthusiactic and still had that amount of time to write really, really solid code. Embarassed

  • User profile image

    Beer28 wrote:
    BruceMorgan wrote: Essentially it took the HP soft fonts and laid out the line by blitting each character's bitmap into memory at the right position with the right kerning, leading, etc, at full 300DPI resolution.

    Wow, that sucks. So basically, you were rastering the fonts in the memory to output the lines as lines of pixel bits to the device?

    Thank god for reusable print libraries!
    I guess the technology wasn't around back then. I remember printing stuff out looked horrible. Nothing was preportionately spaced, and on my old printer lower case letters were flush bottom with upper case, like the lower part of a "g" would start on level with all the other letters.
    It wasn't around back then is right.  DOS did hardly anything for printing, so you had to do it yourself.  Sure you could buy printer libraries from the back of Dr. Dobb's, but the quality varied and so that just gave you a head start at best.  And if you had something special to do (like I did), then you're on your own.  And of course, it had to work on a 640K PC and distribute on floppies.

    You had to know the codes you want to send to the printer to enter graphics mode, print bits, etc.  By 1989, most printers used one of about 7 sets of codes - three or four code sets for 8 pin dot matrix (most were Epson MX80 compatible), two for 24 pin dot matrix (Panasonic KXP1124 used a common set), and HP PCL. 

    For this product, I had a set of printer driver codes in a table loaded from a data file.  Lots of complexity.

    For HP PCL compatible laser printers, I didn't rasterize; I downloaded the softfont.  The trick then was making the print preview match what the printer would produce.

    Apple's LaserWriter had all the cool rastering technology but used Postscript and very few DOS programs supported it.  We didn't.

    Beer28 wrote:
    EDIT: oh, oh, i bet there wasn't DMA back then either, so you had to IN/OUT everything directly like on a microconroller chip?
    Was the bus synchronized or did you have to deadloop IO send/recv for a millisecond like on an 8051? for data sends?

    EDIT2: was there even driver logic back then, and virtual devices?
    Or did the word processing program take full control of the device and manually send it the IN/OUT through the port for each printer type?
    Then you'd have to buy the word processing program that supported your printer?

    DOS didn't have standard printer drivers and didn't do much to support printing.  You printed to COM1: or LPT1: and called it a day.  LPT was pretty straightforward because the hardware had one method of flow control,  but for COM ports you had to let the user specify flow control (hardware or software with XON and XOFF), bits, parity, etc. 

    Printing wasn't easy with DOS apps.  Users needed to make sure before they bought some software if it would work with their printer.  Products like WordPerfect came with a stack of driver disks, as did many products.  You had to configure each one to work.

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.