Epic coding moments

A place to discuss the implementation and style of computer programs.

Moderators: phlip, Moderators General, Prelates

User avatar
The Hyphenator
Posts: 791
Joined: Mon Nov 19, 2007 2:16 am UTC
Location: The Shades, Ankh-Morpork

Epic coding moments

Postby The Hyphenator » Wed Apr 23, 2008 1:49 am UTC

What are your best coding moments, the times when a piece of code just does something completely unexpected (in a good way)?

My first one is when I was coding a pi calculator. I had written my own bignum class, which was excruciatingly slow, and had just implemented a new algorithm. My previous record for most number of digits was about 10 or 20 with the old algorithm. I started the program and went upstairs for a few minutes. When I came back down, 100 digits of pi were waiting for me on the screen. :shock:

My second one, which is what inspired me to create this topic, happened today. I made a program, created two classes for it, and wrote most of their functions, without compiling. Finally, when I compiled: No errors, no warnings. I hope finishing the rest of this program will be that easy.
The image link changes whenever I find a new cool website.
Spoiler:
Image

EvanED
Posts: 4330
Joined: Mon Aug 07, 2006 6:28 am UTC
Location: Madison, WI
Contact:

Re: Epic coding moments

Postby EvanED » Wed Apr 23, 2008 2:04 am UTC

I had a great bit when I was working on an assignment for compilers class. We were writing part of the back end of a compiler, so I don't know of any good way to test it besides taking C source, compiling it with both GCC and our compiler, then comparing the result. This was failing, and the only evidence I had was very indirect: this malfunctioning test program. Because we didn't emit any debugging information, running it in the debugger was a PITA.

I had exhausted everything else I had thought of for figuring out what was going on, so fell back on debugging by stepping through assembly instructions, trying to infer what variables were in which registers, etc., and manually tracing through what the C code did. Oh, and did I mention that I started this about 5am? And that the test program that was breaking was written in K&R C? Anyway, so I was stepping through for an hour and a half or so, and finally figured out why the code I was producing was wrong. 5 minutes or so later I had fixed the bug, and another 5 minutes later had built the new version, all the test programs, and verified the test programs' correctness.

It was a little bit of a stupid mistake, but it was awesome to figure out.

User avatar
quintopia
Posts: 2906
Joined: Fri Nov 17, 2006 2:53 am UTC
Location: atlanta, ga

Re: Epic coding moments

Postby quintopia » Wed Apr 23, 2008 7:28 am UTC

Every time I finish a LISP program. With the sort of error messages it gives, and the sort of logic errors possible, it shouldn't be possible.

User avatar
TomBot
Posts: 228
Joined: Sun Jul 29, 2007 1:17 am UTC
Location: Illinois (UIUC)
Contact:

Re: Epic coding moments

Postby TomBot » Wed Apr 23, 2008 9:04 am UTC

Things working on the first try is fun. You should try OCaml - its type inference system basically means that if it compiles, then it works. Sort of like in physics, where if the units work out, then you can only ever be off by a constant factor.

User avatar
Berengal
Superabacus Mystic of the First Rank
Posts: 2707
Joined: Thu May 24, 2007 5:51 am UTC
Location: Bergen, Norway
Contact:

Re: Epic coding moments

Postby Berengal » Wed Apr 23, 2008 12:12 pm UTC

I had just started teaching myself pygame, and was trying to make tetris. I spent a day wondering how to best rotate pieces (while programming the other parts), but hadn't figured out a good way to do it by the time I went to bed. When I woke up, I had the phrase "who am I?" in my head, and then I remembered python has built-in support for complex numbers.

And also the time, very early in my programming education, when I wrote a prime-finder. It spent much too long, not finding even the first million in five hours. I stopped it, looked at my algorithm for 30 seconds, changed nextPossible += 1 to += 2, checked only against previously found primes (not every number), and only up to the square root. It found the first million primes in less than a second.
It is practically impossible to teach good programming to students who are motivated by money: As potential programmers they are mentally mutilated beyond hope of regeneration.

User avatar
headprogrammingczar
Posts: 3072
Joined: Mon Oct 22, 2007 5:28 pm UTC
Location: Beaming you up

Re: Epic coding moments

Postby headprogrammingczar » Wed Apr 23, 2008 12:42 pm UTC

I had written an applet to demonstrate blur effects with a simple color-shifting visual. It ran excruciatingly slow at 100x100 pixels. It turns out that showStatus() is a morbid CPU hog. I was using it to locate crash-points because I was working on a computer with no IDE. I took it out and instead of 100x100 at 5fps, I could do 200x200 at 30fps, on an old Win98 sitting in the lab.
<quintopia> You're not crazy. you're the goddamn headprogrammingspock!
<Weeks> You're the goddamn headprogrammingspock!
<Cheese> I love you

User avatar
Xanthir
My HERO!!!
Posts: 5281
Joined: Tue Feb 20, 2007 12:49 am UTC
Location: The Googleplex
Contact:

Re: Epic coding moments

Postby Xanthir » Wed Apr 23, 2008 3:26 pm UTC

Berengal wrote:And also the time, very early in my programming education, when I wrote a prime-finder. It spent much too long, not finding even the first million in five hours. I stopped it, looked at my algorithm for 30 seconds, changed nextPossible += 1 to += 2, checked only against previously found primes (not every number), and only up to the square root. It found the first million primes in less than a second.

Honestly, I had that exact same moment.

Now, my program didn't find a million in less than a second, but that was because it was being run on a TI-83. I would run it until it filled up a list (with 9999 entries, iirc) then manually change it to add to a clean list and restart it. Probably ran it about 5 hours total and it got up to the sixth or seventh list.
(defun fibs (n &optional (a 1) (b 1)) (take n (unfold '+ a b)))

EvanED
Posts: 4330
Joined: Mon Aug 07, 2006 6:28 am UTC
Location: Madison, WI
Contact:

Re: Epic coding moments

Postby EvanED » Wed Apr 23, 2008 4:24 pm UTC

TomBot wrote:Things working on the first try is fun. You should try OCaml - its type inference system basically means that if it compiles, then it works. Sort of like in physics, where if the units work out, then you can only ever be off by a constant factor.

"The difference between something that can go wrong and something that can't possibly go wrong is that when something that can't possibly go wrong goes wrong it usually turns out to be impossible to get at or repair."

At least that's my experience with SML. I would have a let clause with like 10 cascading assignments and it would produce the wrong result overall, and it was next to impossible to figure out where it was going wrong. OCaml supposedly has a good debugger (time-traveling!) so would probably be way easier because you could see the value of the separate let components.

User avatar
scowdich
The Hedgehog
Posts: 771
Joined: Tue May 22, 2007 4:55 am UTC
Location: University of Illinois (Urbana-Champaign)
Contact:

Re: Epic coding moments

Postby scowdich » Wed Apr 23, 2008 8:52 pm UTC

I had a similar experience with a prime-finder...started with +1, up to half the number, and it was somewhat inefficient. Eventually wised-up to +2 and square root; I still couldn't figure out why this program was outputting each and every prime number to the screen so slowly. My dad suggested that the output was throttling things; I conditioned it to output only one prime for every million candidates, and was reduced to just sputtering for the next few minutes. "But...I...it...thanks."

User avatar
The Hyphenator
Posts: 791
Joined: Mon Nov 19, 2007 2:16 am UTC
Location: The Shades, Ankh-Morpork

Re: Epic coding moments

Postby The Hyphenator » Wed Apr 23, 2008 9:28 pm UTC

Xanthir wrote:
Berengal wrote:And also the time, very early in my programming education, when I wrote a prime-finder. It spent much too long, not finding even the first million in five hours. I stopped it, looked at my algorithm for 30 seconds, changed nextPossible += 1 to += 2, checked only against previously found primes (not every number), and only up to the square root. It found the first million primes in less than a second.

Honestly, I had that exact same moment.

Now, my program didn't find a million in less than a second, but that was because it was being run on a TI-83. I would run it until it filled up a list (with 9999 entries, iirc) then manually change it to add to a clean list and restart it. Probably ran it about 5 hours total and it got up to the sixth or seventh list.

I did that too a while ago, but got bored after it filled the list. My algorithm was probably pretty bad; it took half a day to fill the list.

Now I'm trying to make a program editor emulator with the program editor. It will be truly epic. And then, of course, I'll write a program editor emulator with the program editor emulator, etc.
The image link changes whenever I find a new cool website.
Spoiler:
Image

User avatar
Berengal
Superabacus Mystic of the First Rank
Posts: 2707
Joined: Thu May 24, 2007 5:51 am UTC
Location: Bergen, Norway
Contact:

Re: Epic coding moments

Postby Berengal » Wed Apr 23, 2008 10:00 pm UTC

The Hyphenator wrote:Now I'm trying to make a program editor emulator with the program editor. It will be truly epic. And then, of course, I'll write a program editor emulator with the program editor emulator, etc.

Couldn't you just run the program emulator in the program emulator?
It is practically impossible to teach good programming to students who are motivated by money: As potential programmers they are mentally mutilated beyond hope of regeneration.

coppro
Posts: 117
Joined: Mon Feb 04, 2008 6:04 am UTC

Re: Epic coding moments

Postby coppro » Wed Apr 23, 2008 11:00 pm UTC

There was a problem with a template instantiation that shouldn't exist being created. In order to trace it, I specialized the class to have none of the necessary members. As a result, GCC gave me an error that included the instantiation location, allowing me to determine the error!

User avatar
Strilanc
Posts: 646
Joined: Fri Dec 08, 2006 7:18 am UTC

Re: Epic coding moments

Postby Strilanc » Wed Apr 23, 2008 11:33 pm UTC

Learning about new concepts always feels 'epic' to me. When you're teaching yourself to program using a help file, variables and arrays are amazing concepts. More recently I've fallen in love with generics and background compiling.
Don't pay attention to this signature, it's contradictory.

User avatar
Xanthir
My HERO!!!
Posts: 5281
Joined: Tue Feb 20, 2007 12:49 am UTC
Location: The Googleplex
Contact:

Re: Epic coding moments

Postby Xanthir » Thu Apr 24, 2008 2:40 am UTC

The Hyphenator wrote:
Xanthir wrote:
Berengal wrote:And also the time, very early in my programming education, when I wrote a prime-finder. It spent much too long, not finding even the first million in five hours. I stopped it, looked at my algorithm for 30 seconds, changed nextPossible += 1 to += 2, checked only against previously found primes (not every number), and only up to the square root. It found the first million primes in less than a second.

Honestly, I had that exact same moment.

Now, my program didn't find a million in less than a second, but that was because it was being run on a TI-83. I would run it until it filled up a list (with 9999 entries, iirc) then manually change it to add to a clean list and restart it. Probably ran it about 5 hours total and it got up to the sixth or seventh list.

I did that too a while ago, but got bored after it filled the list. My algorithm was probably pretty bad; it took half a day to fill the list.

Now I'm trying to make a program editor emulator with the program editor. It will be truly epic. And then, of course, I'll write a program editor emulator with the program editor emulator, etc.

A further "epic calculator coding moment" (these things cause the best epic moments, because you're usually *learning* programming on them...):

I was getting into more and more powerful and complex programs on the TI, but was getting really tired of having to retype algos whenever I used them in multiple places. So, I decided to implement subroutines in my calculator. The only thing that stopped me from finishing this was graduating high school and getting a laptop, because I suddenly stopped caring about calculators when I could run Lisp. (Which is why I actually replaced the Windows calculator with my Lisp console...)

I found out later that my planned method of accomplishing this was essentially *identical* to the way that actual assemblers implement subroutines - I was implementing stack frames and a call table and all that without any knowledge of what these things actually were.
(defun fibs (n &optional (a 1) (b 1)) (take n (unfold '+ a b)))

User avatar
Berengal
Superabacus Mystic of the First Rank
Posts: 2707
Joined: Thu May 24, 2007 5:51 am UTC
Location: Bergen, Norway
Contact:

Re: Epic coding moments

Postby Berengal » Thu Apr 24, 2008 4:08 am UTC

Heh. I did something similar as well. When I first encountered programming, I had no idea that's what I was doing, and I had no idea what was going on (this was NWScript). I picked up on a few things quickly, such as variables, arrays and loops. My first slightly complex programs followed the following pattern:
"void main" // the magic incantation that has to surround a program, or the compiler will object.
series of flags on the form "int <funcName> = 0x########;"
"int depth = 0;"
"int currentRoutine = 0;"
"int returnedFrom = 0;"
"object returnValue = null;"
"int[] previousRoutines = int[50];"
"object[] previousVariables = object[50];" // NWScript isn't object oriented, but there IS an object type representing an object in-game. These objects can store dynamic variables (persistent through different invocations of scripts, but that's not important here). What I did was something along the lines of "object temp = createObject(TEMP_OBJ, HIDDEN_CHEST); setVariable(temp, "<myVar>", myVar);". Yes, I created actual physical in-game objects to store variables.
"while (true) {"
series of "if (currentRoutine == <funcName>)"
"Functions" in turn had lots of "if (returnedFrom == ..." to keep state between different calls.
Calling functions was a simple matter of going something like *check for array overflow, print "stack trace" if overflowing, create variable object, store variables (including returnedFrom), store object*, "previousRoutines[depth++] = <funcName>;", "returnedFrom = 0; currentRoutine = <otherFunction>; continue;"
Returning from a function was just as simple: After the right "if (returnedFrom ==..." had been found, I proceeded to unwind the "stack", return all my variables from the object I had created etc. etc.

*scratches head*... there probably was an argument variable of type object there as well. What do I know...

This probably belongs more in the "what the hell am I doing?" thread than here. I guess you could say my epic coding moment was when I discovered functions.
Still, it says something about me as a beginner when after all this my programs didn't become noticably more complex. Or perhaps I was just too sure that I was on to something that, with a little twerking and programs of even greater complexity than what I was creating at the time, would come in handy to notice how incredibly bad it was (in my defense, I'll just say "you try to implement functions in a typed environment without casts" (I didn't know about them at the time)).
It is practically impossible to teach good programming to students who are motivated by money: As potential programmers they are mentally mutilated beyond hope of regeneration.

spit_and_prayers
Posts: 3
Joined: Thu Apr 24, 2008 5:34 am UTC

Re: Epic coding moments

Postby spit_and_prayers » Thu Apr 24, 2008 6:07 am UTC

This isn't a specific instance, but I'd have to say my most epic programming moments are when I write a full program in C++ or Java using only notepad, throw it over into the compiler, and find to my utter amazement that it contains no syntax or logic errors. That is the ultimate in coding euphoria for me, kicking it old school with class.

User avatar
'; DROP DATABASE;--
Posts: 3284
Joined: Thu Nov 22, 2007 9:38 am UTC
Location: Midwest Alberta, where it's STILL snowy
Contact:

Re: Epic coding moments

Postby '; DROP DATABASE;-- » Thu Apr 24, 2008 6:30 am UTC

A while back my Internet connection was down for a few days, and for some reason I had OpenGL and a bunch of documentation on the hard drive. So I tinkered with it a bit. I'd looked at DirectX 3D demos before and couldn't make a lick of sense out of them, but I had a simple 3D environment going within hours, having no prior experience with 3D or OpenGL. :D

(Too bad hit detection isn't that easy... >_<)
poxic wrote:You suck. And simultaneously rock. I think you've invented a new state of being.

User avatar
The Hyphenator
Posts: 791
Joined: Mon Nov 19, 2007 2:16 am UTC
Location: The Shades, Ankh-Morpork

Re: Epic coding moments

Postby The Hyphenator » Thu Apr 24, 2008 10:01 pm UTC

Berengal wrote:
The Hyphenator wrote:Now I'm trying to make a program editor emulator with the program editor. It will be truly epic. And then, of course, I'll write a program editor emulator with the program editor emulator, etc.

Couldn't you just run the program emulator in the program emulator?

I could do that too... :oops:

But I just realized today in English class that it would be practically impossible to do this using only TI-BASIC and Xlib (the only two things I have right now). I'll probably just turn this into a hoax OS that I can fool fellow calculator programmers with. A lot of my projects end up like this. :(
The image link changes whenever I find a new cool website.
Spoiler:
Image

User avatar
psykx
Posts: 408
Joined: Sat Feb 23, 2008 11:24 pm UTC
Location: England
Contact:

Re: Epic coding moments

Postby psykx » Fri Apr 25, 2008 1:15 pm UTC

using an eee pc on the train this morning I discovered I could reduce the 20 or so lines of code I had in my prime factorization algorithm to four. Thats the only recent one (I think) although I remember back in the day getting my first program to run was a huge buzz (it was a three line batch file that copied all the *.pwl file to the A:/ :\ )
Berengal wrote:Only if they're killer robots. Legos are happy robots. Besides, even if they were killer robots it wouldn't stop me. You can't stop science and all that.

Zarkonnen
Posts: 9
Joined: Wed Aug 29, 2007 4:22 pm UTC
Contact:

Re: Epic coding moments

Postby Zarkonnen » Fri Apr 25, 2008 2:56 pm UTC

One of my happiest coding experiences was when I was writing a constraint satisfaction algorithm in 2nd year of uni. I was working in a group project that had been told to re-implement Ivan Sutherland's Sketchpad. Since it clearly was the most interesting part, I called dibs on the constraint satisfaction system that allowed Sketchpad to enforce rules like "these two lines are at right angles, and this point is 100 units away from that one".

So I set out on this task, defining a few generic interfaces and constraints, and writing a program that would plot the degree of constraint satisfaction for each position of a point - which made for some great abstract art. I then delved into the algorithm itself. While I was programming it, I kept on coming up with more elegant and general ways of doing things. In the end, I had a complete algorithm that was less than a thousand lines long, and the ability to create new constraints in about ten lines, nine of which were class/function names and brackets.

The algorithm didn't work immediately, and I spent several nights debugging it, making improvements, measuring the results, eventually going to bed far too late to wake up to some inspiration.

Eventually, one evening, the algorithm was working apart from one problem which I just couldn't fix, which only seemed to happen under really complex circumstances. I kept hacking away at it but got nowhere.

It finally turned out that the program was right, and I was wrong - I'd subtly misunderstood the geometry of the question I'd asked.

At that point, I declared the algorithm complete, for it had surpassed my own abilities.
- Zarkonnen

User avatar
Shai
Posts: 86
Joined: Wed Dec 12, 2007 2:59 am UTC
Location: Guelph, Ontario, Canada
Contact:

Re: Epic coding moments

Postby Shai » Fri Apr 25, 2008 5:40 pm UTC

spit_and_prayers wrote:This isn't a specific instance, but I'd have to say my most epic programming moments are when I write a full program in C++ or Java using only notepad, throw it over into the compiler, and find to my utter amazement that it contains no syntax or logic errors. That is the ultimate in coding euphoria for me, kicking it old school with class.


I've recently had that occur while writing a complex, mathematically involved Matlab function that measured the similarity between two images. I think it also happened when changing some Python code remotely using pico. I was especially amazed since I've barely ever touched Python.

I think in general, whenever anything complex works, it's a great and epic feeling.
I blame lag.

Rysto
Posts: 1459
Joined: Wed Mar 21, 2007 4:07 am UTC

Re: Epic coding moments

Postby Rysto » Fri Apr 25, 2008 5:44 pm UTC

spit_and_prayers wrote:throw it over into the compiler, and find to my utter amazement that it contains no syntax or logic errors.

Happens all the time for me.

Ok, I write my Java code using Netbeans. The IDE catches all of my errors before I even compile.

User avatar
Arancaytar
Posts: 1642
Joined: Thu Mar 15, 2007 12:54 am UTC
Location: 52.44°N, 13.55°E
Contact:

Re: Epic coding moments

Postby Arancaytar » Fri Apr 25, 2008 7:29 pm UTC

I once wrote an AJAX application in two hours. :D (It's also the page that got the most visitors in the shortest time, out of all pages I've ever made).
"You cannot dual-wield the sharks. One is enough." -Our DM.
Image

User avatar
TheAmazingRando
Posts: 2308
Joined: Thu Jan 03, 2008 9:58 am UTC
Location: San Diego, CA

Re: Epic coding moments

Postby TheAmazingRando » Fri Apr 25, 2008 8:32 pm UTC

There is nothing more rewarding than writing a long, complicated, optimized procedure in an assembly language and seeing it work perfectly the first time.

Unfortunately, if it doesn't work perfectly the first time, there is nothing more frustrating than debugging it.

User avatar
Berengal
Superabacus Mystic of the First Rank
Posts: 2707
Joined: Thu May 24, 2007 5:51 am UTC
Location: Bergen, Norway
Contact:

Re: Epic coding moments

Postby Berengal » Sat Apr 26, 2008 12:39 am UTC

Seeing as I started using Eclipse immediately (Java is my first language), I never had one of those "no errors" compiles as it builds incrementally as I write. I sort of miss that, as I've had a couple (couple as in two. My two very first programs, which I javac'd) of error'd compiles.

I guess writing a python module and having it run with no "TypoError"s (SyntaxError, NameError, misspellings, whatever) sort of counts. I've done that, and indeed is how most python I write turns out. Python makes it rather easy, actually.

Oh, and there's that one time when I was making Tetris. It feels like I've told the story several times, but I can't see it in this thread so I'll just risk reiterating it:
I was thinking about the best, most elegant way to rotate blocks, but after a couple of hours of working on it I hadn't really found a good way. I went to sleep, and when I woke up the next morning, the phrase "who am I?" was lingering in my head. My thought process went something like this: "Who am I?", tetris and rotate, I? Tetris? Oh shit! Python has built-in complex numbers!

There's also quite many happy moments when I go from "How the hell do I build this?" to "Ah, yes! This is the square peg and this is the square hole. They fit together perfectly!" The best thing about this is that I know exactly what I'm doing when I'm coding, so I can concentrate on writing clever code. There's really no such thing as good as that.
It is practically impossible to teach good programming to students who are motivated by money: As potential programmers they are mentally mutilated beyond hope of regeneration.

User avatar
'; DROP DATABASE;--
Posts: 3284
Joined: Thu Nov 22, 2007 9:38 am UTC
Location: Midwest Alberta, where it's STILL snowy
Contact:

Re: Epic coding moments

Postby '; DROP DATABASE;-- » Sat Apr 26, 2008 6:02 am UTC

After only a couple hours of looking up equivalents of Windows functions and libraries, I compiled one of my programs in Linux and it actually ran. :shock:
poxic wrote:You suck. And simultaneously rock. I think you've invented a new state of being.

User avatar
Cosmologicon
Posts: 1806
Joined: Sat Nov 25, 2006 9:47 am UTC
Location: Cambridge MA USA
Contact:

Re: Epic coding moments

Postby Cosmologicon » Sat Apr 26, 2008 6:21 am UTC

It seems a lot of people have a moment with optimizing their prime number generators. I once had a very similar one with generating primitive Pythagorean triples, of which I wanted a big list. I programmed it the naive way and it generated 10,000 triples in about 30 minutes. I was pretty pleased with that. But while it was running, I did some more research on Pythagorean triples and there's a more efficient way to generate them. I tried that instead, and it generated about 100 times as much output in 1/100 the time.... an efficiency boost of four orders of magnitude. It made me feel sheepish for ever being pleased with my original, while completely obviating the need to precompute these things in the first place.

At the time, I'd never made megabytes of meaningful output (and this was back when megabytes was a lot of memory) in a few seconds before, so that was the epic part for me.

User avatar
Pathway
Leon Sumbitches...?
Posts: 647
Joined: Sun Oct 15, 2006 5:59 pm UTC

Re: Epic coding moments

Postby Pathway » Sat Apr 26, 2008 9:05 am UTC

Cosmo: What was the way you were doing them, and what was the more efficient way?
SargeZT wrote:Oh dear no, I love penguins. They're my favorite animal ever besides cows.

The reason I would kill penguins would be, no one ever, ever fucking kills penguins.

User avatar
Cosmologicon
Posts: 1806
Joined: Sat Nov 25, 2006 9:47 am UTC
Location: Cambridge MA USA
Contact:

Re: Epic coding moments

Postby Cosmologicon » Sat Apr 26, 2008 3:47 pm UTC

Does everyone here know C++? Here it is in C++:

Code: Select all

#include <iostream>
#include <cmath>

inline int gcd(int a, int b) {
  return b ? gcd(b, a % b) : a;
}

void method1() {
  for (int b = 3; ; ++b) {
    for (int a = 1; a < b; ++a) {
      if (gcd(a,b) != 1) continue;
      int c2 = a*a + b*b, c = int(sqrt(c2)+0.5);
      if (c*c == c2)
        std::cout << a << " " << b << " " << c << std::endl;
    }
  }
}

void method2() {
  for (int m = 2; ; ++m) {
    for (int n = 1; n < m; ++n) {
      if ((n+m) % 2 == 0 or gcd(m,n) != 1) continue;
      std::cout << m*m-n*n << " " << 2*m*n << " " << m*m+n*n << std::endl;
    }
  }
}

int main() {
  method1();  // naive way
  //method2();  // fast way
}
Basically you can generate triples with smaller integers m and n. It's pretty easy to find the formula. You can get it from Wikipedia.

User avatar
wing
the /b/slayer
Posts: 1876
Joined: Tue May 29, 2007 5:56 am UTC

Re: Epic coding moments

Postby wing » Mon Apr 28, 2008 5:59 am UTC

Not an epic coding moment, per se, but epic coding-related moments.

Took a distributed object computing class this semester. Around the time that we started doing web apps, I kind of got busy and stopped doing the labs. Today, I sat down to catch up on a half semester of labs. Flipping through the spec sheets, I noticed they simply iterated upon each other... So I wrote the *LAST* lab first (it took about 10 minutes), and then just ripped out features and concepts to move backwards. In under an hour, I'd done what was supposed to take a half semester.

Of course, there was a counterpoint. My dev team had worked on the server half of this other project, and finished it up today. Immediately after we print the documentation, we receive notification that the final spec has changed - the client team is behind and would like to switch to a web services model rather than a sockets model. Some advance notice would have been nice, guys. Now I have to try to work this into my schedule for crunch week and finals week.
I AM A SEXY, SHOELESS GOD OF WAR!
Akula wrote:Our team has turned into this hate-fueled juggernaut of profit. It's goddamn wonderful.

User avatar
ivysbuddy
Posts: 33
Joined: Fri Apr 25, 2008 7:29 pm UTC
Location: Mt. Doom

Re: Epic coding moments

Postby ivysbuddy » Thu May 01, 2008 11:38 am UTC

I spent two weeks figuring out how to run a block delete on a flat text file (sort through lines, find the start word, find the end word, if it contains a filter, delete the block). The thing was, the customer also wanted line deletes and the entire program could not exceed 512K. Oh, and the recipient of the file could not know that anything had been deleted, so no white space.

At the end of the two weeks and 400 LOC just for the block deletes, i went..."huh." I changed my for loop to a "while (!endword)", and i had a complete, working function in 2 hours and 20 LOC tacked onto the original line delete function.

I spent the rest of the work day beating my head against my desk, then took my entire shop out for drinks.
"Someday...we're gonna rise up on the wind, you know...Someday, we gonna dance with those lions..."

qbg
Posts: 586
Joined: Tue Dec 18, 2007 3:37 pm UTC

Re: Epic coding moments

Postby qbg » Thu May 01, 2008 1:18 pm UTC

Rysto wrote:
spit_and_prayers wrote:throw it over into the compiler, and find to my utter amazement that it contains no syntax or logic errors.

Happens all the time for me.

Ok, I write my Java code using Netbeans. The IDE catches all of my errors before I even compile.

Your IDE even catches logic errors?

Rysto
Posts: 1459
Joined: Wed Mar 21, 2007 4:07 am UTC

Re: Epic coding moments

Postby Rysto » Thu May 01, 2008 3:04 pm UTC

:oops:

That'll teach me to skim through the thread.

User avatar
MoD
Posts: 107
Joined: Sun Dec 30, 2007 4:55 pm UTC

Re: Epic coding moments

Postby MoD » Thu May 01, 2008 10:28 pm UTC

Yesterday a friend and I were chatting on IRC and exchanged a few blocks of code. He had written a maze generator, and I had written an implementation of A* independently. I opened up an IDE in the middle of the conversation, and with 7 lines of glue code (drawing the solved path) they worked together flawlessly. I love it when that kind of thing happens.
Last edited by MoD on Wed Jan 21, 2009 11:07 pm UTC, edited 1 time in total.

User avatar
Berengal
Superabacus Mystic of the First Rank
Posts: 2707
Joined: Thu May 24, 2007 5:51 am UTC
Location: Bergen, Norway
Contact:

Re: Epic coding moments

Postby Berengal » Thu May 01, 2008 11:01 pm UTC

MoD wrote:Yesterday a friend and I were chatting on IRC and exchanged a few blocks of code. He had written a maze generator, and I had written an implementation of A* independently. I opened up an IDE in the middle of the conversation, and with 7 lines of glue code (drawing the solved path) they worked together flawlessly. I love it when that kind of thing happens.

Hive-mind.
It is practically impossible to teach good programming to students who are motivated by money: As potential programmers they are mentally mutilated beyond hope of regeneration.

User avatar
Dusty Chalk
Posts: 142
Joined: Thu May 01, 2008 9:00 pm UTC

Re: Epic coding moments

Postby Dusty Chalk » Thu May 01, 2008 11:20 pm UTC

My favourite thing that I ever coded was a generic object printer that used recursion and class functions to determine instance variables and then iterate through them, printing them out if they were primitive.
I remain,
:-Peter, aka :-Dusty :-Chalk

User avatar
Berengal
Superabacus Mystic of the First Rank
Posts: 2707
Joined: Thu May 24, 2007 5:51 am UTC
Location: Bergen, Norway
Contact:

Re: Epic coding moments

Postby Berengal » Sat May 03, 2008 12:46 am UTC

I'm euphoric. I decided to try to add multiplayer to my game, but to do that I needed to learn networking, and threading would probably be nice too.

Anyway, I did some really basic stuff like making a telnet echo server, and then I decided it was time to try a server/client program. On the first run I got this output:
Client thread started. Sleeping 3 seconds...
Server: Port open
Server: Connecting...
Client: Connecting to server...
Client: Connected to server
Server: Connected
Client: Sending request for string
Server: Got request for string. Sending...
Server: String sent
Client: Got string: Hello world!
Client: Disconnecting...
Client: Disconnected. Quitting
Server: Disconnecting from client...
Server: Disconnected
Program finished


Man... I just... wow... and on the first try... I rock!
It is practically impossible to teach good programming to students who are motivated by money: As potential programmers they are mentally mutilated beyond hope of regeneration.

User avatar
Grooving Tony
Posts: 100
Joined: Sun May 04, 2008 9:55 pm UTC

Re: Epic coding moments

Postby Grooving Tony » Sun May 04, 2008 9:58 pm UTC

I'm new to programming but one of my favorite moments so far has been building a fireworks program. Before i managed to get it to work i created a lot of weird/cool bugs that just made it interessting :D.
It's turtles all the way down
Panda
BHCM
protect the flag
snuggles
Jahoclave wrote:Tip: Shotgun, they could be a zombie. Remember, you're the first step in preventing the zombie apocalypse.

User avatar
Xanthir
My HERO!!!
Posts: 5281
Joined: Tue Feb 20, 2007 12:49 am UTC
Location: The Googleplex
Contact:

Re: Epic coding moments

Postby Xanthir » Sun May 04, 2008 10:06 pm UTC

Marketing handed me a pdf showing me how they wanted a new page on our website to look. I *immediately* saw the correct underlying structure, which was far from obvious, threw it together with some styling, and had it turn out *perfectly* when I looked at it for the first time.

Html+css may not be turing-complete, but handling it well is still a skill that does not come trivially. I'm happy!
(defun fibs (n &optional (a 1) (b 1)) (take n (unfold '+ a b)))

qbg
Posts: 586
Joined: Tue Dec 18, 2007 3:37 pm UTC

Re: Epic coding moments

Postby qbg » Mon May 05, 2008 2:08 am UTC

Xanthir wrote:... I *immediately* saw the correct underlying structure, which was far from obvious ...

If you immediately saw it, doesn't that make it obvious? :lol:


Return to “Coding”

Who is online

Users browsing this forum: No registered users and 3 guests