top | item 18899809

Ask HN: What's the most important piece of code you've written?

105 points| jessehorne | 7 years ago | reply

What's the most important piece of code you've written?

My answer is as follows... The most important piece of code I've written was a rudimentary 2d tile engine in QB64 for an RPG I never finished. It's memorable and important to me because of what writing it did for my confidence as a developer. At the time, writing a tile engine "from scratch", in my mind, would make me a "professional".

I had been following a Game Development YouTube series called "Adventures In Game Development". I wanted to be a game developer! It was my dream! I was a novice developer when I took on that challenge. After a few articles and discussions with some people in various IRC channels, I began.

A few hours later, I saw a map appear that I had hardcoded which contained 0's, 1's. When I saw the square patch of grass with water in the middle (my clever map design), I thought I could accomplish anything. It was one of those moments that changed my life.

I'm not kidding when I say I had wanted to write a tile engine for a year, at least, before I was actually able to do it. I was probably around 14 years old, at the time.

I hope you enjoyed reading my answer to this question and I look forward to reading yours!

EDIT

I found the link to one of the articles I read when writing the tile engine.

http://www.petesqbsite.com/sections/tutorials/tutorials/rpg_tut2.txt

EDIT 2

Another important piece of code I've written was the prototype for this game.

http://hdfgame.com/

I helped with the commercial version a bit but it was awesome to see my prototype turn into the first commercial game that I helped release. The prototype was simple but it had the basic functionality that Hexapod Defense Force has.

108 comments

order
[+] neurocline|7 years ago|reply
This isn’t the most important thing I’ve done, but it’s certainly one of the coolest. And it was important to millions of Starcraft players.

There was a time when we broke patching for Starcraft. I point no fingers because, of the top 4 engineers that worked on Battle.net from the beginning until the point of this incident, 3 of them (myself included) broke patching (Diablo, Warcraft II BNE (my bad), and now Starcraft). This is a tragedy, because we always took the mechanics of it very seriously, and still would get it wrong.

A patch went out that broke the patching mechanism. Starcraft worked fine, but if you had to download another patch, the game would crash. We were looking at a scenario where everyone would have to reinstall the game, and that sucks. Worse, this was back in the early 2000s, so we had no way to message everyone easily.

I spent two days non-stop trying to find a way out. And then I had a crazy brilliant idea, based on the original bug. See, the crash bug was a stack overwrite, causing the version detection code to crash inside the game when returning from the version check. I figured out a way to cause another stack overwrite to fix the first one; use the downloadable version DLL we used at the time to leave a trampoline on the stack that would be right at the stack overflow caused by the bug, and cause the game to jump straight to the download-next-patch section of the code. It took a little while to get everything to work properly, but it was glorious. We made a small patch to fix the bug, and used my stack-overwrite hack to get the game to download it. And then I went and got some sleep.

After this, we (Blizzard) overhauled how we did patch testing, and stopped breaking patching.

[+] Humdeee|7 years ago|reply
Kerrigan would be pleased.
[+] stnmtn|7 years ago|reply
That is so interesting, what a cool fix.
[+] lettergram|7 years ago|reply
It really depends on what you mean by important? Some of my most important code saves a company millions of dollars a year... It's not at all important to me, but it does it's job and it is important to someone.

The most important code to me is a difficult question... I look at code as solutions to problem. What's most important to me, is the code that made me realize none of us are free (weird as that sounds). I can track anyone on the web from their discussions (provided enough comments, i.e. 1000+ words):

https://twitter.com/AustinGWalters/status/104189476543920128...

Expanding on this system I built an investment framework part of which is incorporated in (https://projectpiglet.com). It has helped me make 100% yoy returns since 2013 (including >200% last year, even with the downturn):

https://twitter.com/AustinGWalters/status/107014266501716787...

It's the basis for my startup, but perhaps more importantly, made me realize we have no freedom. I can do this with no funds, in my house, with a computer. I track a couple million people in real-time (public data only)... I wrote a blog post about my introspection:

https://austingwalters.com/the-last-free-generation/

In a sense, it's open my eyes to the dystopia we are building and it's changed my outlook dramatically.

[+] nixpulvis|7 years ago|reply
You might want to redefine "freedom" for yourself. I personally struggle with this too, but I find it useful to remember; I can still go down the street, buy something to eat, then go to town and see all that's around.
[+] wodenokoto|7 years ago|reply
Why is selling investment advise better then gearing your own investments?
[+] natalyarostova|7 years ago|reply
It's hard to understand why if you're able to consistently do 100% yoy you'd even bother or waste any time selling investments products.
[+] cek|7 years ago|reply
In 1987 I wrote about 150 lines of 68000 assembler that applied a low-pass filter to every sound heard by the towed-array sonar system on the Los Angeles class fast-attack submarines. I was an intern (co-op) and nobody even looked at my code. But it fixed the problem that had been plaguing the ANN-BQQ-5D system, preventing it from going into trials and 'management' just shipped it once the tests started passing.

Compared to other things (including some of the ID3 tag processing code that's still in Windows today, and OLEView) this seems pretty important.

[+] ndespres|7 years ago|reply
For what it's worth to you, I still remember the first time I watched Windows detect that a folder was full of MP3s and enumerate artist/album data alongside the other typical file attributes, and feeling that it showed a big step in its development. It felt like something close to magic for Explorer to be able to do that.
[+] compsciphd|7 years ago|reply
The most important code I ever wrote was as a phd student. No one uses that code, but they use the concepts behind it every single day.

The Q was how does one manage large numbers of heterogeneous containers (VM sprawl was already considered a problem, but we said if containers took over the sprawl would be worse). At the time the primary container mechanism was Solaris Zones and people uses ZFS clone functionality to create per zone container file systems. However, this only really helps if your containers are homogeneous. I built a system that created container file systems out of composable layers. One would define template file systems as a collection of layers that are stored in local and remote layer repositories and these layers would be instantly unioned together on demand when one provisioned new containers. We also demonstrated that since heterogeneous containers are now easy to manage, we can not just use containers as lower overhead but similarly long lived VM replacements, but also enable them to be used ephemerally, opening up many new use cases.

You probably know of this by a different name today.

[+] aerovistae|7 years ago|reply
> The Q was how does one manage large numbers of heterogeneous containers

my god this man invented UPS

> At the time the primary container mechanism was Solaris Zones and people uses ZFS clone functionality to create per zone container file systems.

oh wait nevermind he invented docker

[+] yeukhon|7 years ago|reply
AUFS or something?
[+] zodvik|7 years ago|reply
I wrote a lot of code for payments processing at an Indian e-commerce shop & see/make it scale from 100s of QPS to ~200k QPS. Just having the code paths exercised by so many people over a day gives me joy.

One change that I will not forget that made the highest "perceived" impact with a one line change. The payments flow was at a different domain the rest of the site. This meant the users incurred a fresh set of DNS lookup, TCP connection establishment & a SSL handshake cost. The change was to load a "pixel" image from the payments domain a page before. It dropped the first call latency from 550ms to 100ms :-)

[+] cknight|7 years ago|reply
I'm an IT/SysAdmin type guy so I don't really code beyond web stuff at a hobbyist level, though I did do CompSci at uni way back when. However when I followed my partner overseas for a few years, the only job I had while away was working in a computational research group at a university.

I was brought on to provide a nice looking web UI for an online system that scientists could use to submit jobs to a server running molecular dynamics simulations. After finishing the job queue and interfaces though, I had plenty of time to spare. So the boss asked me to try and run some necessary manipulations on the uploaded PDB (protein data bank) files, before they would be sent to run in the simulation.

It's still the only time I have ever actually used direct material from my undergrad degree at work - using Dijkstra's algorithm and standard deviation to discover protein structural features, then manipulating them. It was also the only time I ever used the Python I spent just one semester learning a decade before. With all those libraries, I can understand why it was the language of choice my boss' field.

I made a log of the jobs as well, and in the 5 year since then, over 10,000 jobs have been submitted, helping scientists from dozens of countries all over the world. It's also the only code I've written since my uni days which isn't just typical web app type stuff. It's just this pokey little online service but I'm really proud of it, and I hope I've contributed to humanity's progress in some tiny way.

[+] mikek|7 years ago|reply
I added support for the middle finger emoji to the WhatsApp iPhone app.

Unlike other messaging platforms, WhatsApp provides their own emoji graphics to ensure backwards compatibility even on old versions of the OS that don’t support that emoji natively.

[+] sterlind|7 years ago|reply
I designed and implemented the core algorithm that currently allocates Azure VMs to physical nodes (though the policies aren't mine, and I owe much credit to my coworkers for actually shipping it.) It removed a fundamental scale bottleneck.

Later, I designed an efficient solver for a category of NP-hard graph problems that currently powers Azure's WAN, 98% faster than the module it replaced.

Hopefully with time I'll be able to publish both. I had mental and physical breakdowns on the way, but those experiences make me proud to be alive.

[+] suff|7 years ago|reply
I see. You must have been a Microsoft blue badge...
[+] AnonymousRider|7 years ago|reply
The most important code I “wrote” was merged with code from my wife and produced a tiny human executable.
[+] IMTDb|7 years ago|reply
I was at university working on a side project: I wanted to have my own movie torrent website. The idea was to list movies and under each movie list the best available torrents.

This is now a pretty common feature, but at the time trackers only had a list of file going like Titanic.1998.DVDRiP.Proper.MyGroup.

I was able to fetch the torrent, but the hard part was linking each torrent the correct movie (by IMDb ID). I tried for ages to get it right with reg exp to extract the movie title from the torrent name, use the IMDb API, and so on until I found the solution.

The solution, was to just simply take the torrent name, extract the year as the last 4 digit sequence, remove all regular tokens like dvdrip, TS, xvid and so on and perform an automated google search on the string: IMDb "Everything else" (Year). and extract the ID from the first result. It took me less than an hour to implement, and gave absolutely glorious results, matching movies with typos, rejecting non movie torrent and generally getting a fantastic accuracy.

I went on to release the website, which went on to become semi famous in the field and the consequences for me were :

- Sometimes complex problems actually have simple solution, think outside the box, you don't have to do everything yourself.

- I actually earned money from some ads I put there, which made uni life a lot funnier. I also experienced what it's like to put a ton of efforts in a product only to get a very slow growth. And then see "something" happen, and you get rewarded for all of that. In a way I felt like a founder.

- I maintained the website for years. I was able to apply most of what I learned in my lessons on an actual product, learn new stuff on my own, and faced challenges like scaling that my peers simply could not grasp. I finished uni with top grades and a significant reason for that was my illegal torrent website.

- I got a ton of recognition for my work from friends and family. Even met someone at a bar that wanted to show me the cool website he found when we started discussing movies. One of my bets memories. I started working at BigCo and did not get that kick anymore, which prompted me to change path and work in startups. Really happy with that choice.

The code itself was simple, not really beautiful or efficient, non scalable, completely against any TOS you can dream of, and the goal was to aid movie piracy. It dod not generate million of USD. It probably did not change the life of many, but it changed mine

[+] candlelightX|7 years ago|reply
Wrote whole ad tech platform and roped in the advertisers/publishers with my sales skill then received 5M payout got kicked off the company.

After that they hired sales guys from big companies because they had enough cashflow going.

I don't really regret it but he could have given me atleast 10% equity.

I didn't know that the project will ever end up doing multi million dollar business. I couldn't see it coming.

But I did whatever tasks of sales/coding/customer service were demanded from me.

And the worst part? My girlfriend left me for him because she met him at a party and got impressed by his Noveu rich lifestyle and a new supercar.

[+] iamtoorobbed|7 years ago|reply
Same thing happened to me. The founder was a business major, knew nothing about tech but was Street smart and contacts with lawyers.

I developed an advertising tracking platform, similar to Voluum.com

But founder kicked me out and now they do roughly 10M sales from ad agencies.

He was even blogging about it how he did corporate Takeover and considered himself supersmart about this move.

He told me see pal, you are not my enemy but in life you only get on shot, either you can be loser or a winner, and you know what I'll choose.

[+] jessehorne|7 years ago|reply
The ending was incredibly sad. You don't need someone like that in your life, anyway...
[+] busterarm|7 years ago|reply
I wrote some code related to a class action case supporting child victims of molestation by Catholic priests.

That said, the details of that ugly situation, extremely narrow scope of litigation and details of any possible settlements led me to stop working in the legal industry entirely. When we were working on that project I was simultaneously furious and in tears pretty much every day for weeks.

[+] philpem|7 years ago|reply
Important to the company? A system which could automatically perform partial-stroke testing on pneumatic emergency-shutoff valve/actuator blocks. The end goal was to allow big chemical plants to run for longer between maintenance cycles. The idea is you part-close the shutdown valve enough to prove it can move but not enough to interrupt process.

We were one of the first to prototype, and the only one to do it without needing a bulky valve positioner. The prototype worked on nearly every setup we could build in the lab. Then we added an automatic setup mode which nobody else had.

Alas, marketing got involved. "We want the manual setup removing, permanently. Not just disabled."

And of course the first sale, the customer was doing something which screwed up automatic setup and couldn't be worked around. Manual setup would have worked, but both marketing and management fought engineering tooth and claw to prevent us re-adding it.

The customer sent every single unit back. The stress burned me out (and more besides)... Not long after that, I was "managed out" of the business (read into that what you will).

On a happier note, most important to me? I help out a small-medium size volunteer-run fandom convention (think Comic Con on a smaller scale). I rebuilt their radio communications infrastructure, added call recording (for training/liability reasons) and staff-call pagers. At the staff debrief, the chairman called it "a game changer" and asked if I'd come back as their Head of Operations.

I said yes.

[+] tootie|7 years ago|reply
My first professional job was doing a little bit of work for the Human Genome Project. I've never done anything else nearly as worthwhile.
[+] jtwaleson|7 years ago|reply
At my previous company I created a buildpack that allowed our proprietary runtime to run on Cloud Foundry (an open source Enterprise PaaS like Heroku). I built the first version in my spare time in a couple of evenings. It made our software and company compatible with the platforms of major players in this space, including SAP, IBM, GE and Siemens. The compatibility made our tech and our company much more interesting to these companies. In fact, the company was acquired by Siemens last year for $730M.

If I would not have built it, another engineer in the company would have done it a couple of months later while explicitly being assigned the task. I proved that it worked within a couple of days. The code powers tens of thousands of deployments today and is also the basis for running on Docker & Kubernetes.

[+] jchendy|7 years ago|reply
Probably this UI: https://www.facebook.com/live/create

I didn't do it alone of course (probably a dozen people have worked on the UI, and hundreds on the backend), but it was my main project for around 9 months. Lots of videos that people care a lot about go through there.

[+] azhenley|7 years ago|reply
That seems like a very impactful project. Hundreds of thousands of people (millions?) have used Live videos on FB. Not many engineers can say they've made an impact like that. Congrats!
[+] azhenley|7 years ago|reply
The first Flash game that I released [1].

I had been programming for about 6 years but had never finished anything of substance. The game took about 6 weeks of working on it between classes (and with the help of a friend with the polish and graphics). It went on to be played millions of times and made several thousand of dollars in ad revenue. Even 10 years and a PhD later, this is one of my biggest accomplishments.

It was one of those moments that makes me feel like now I can actually do this (this feeling seems to repeat every few years...).

[1] http://www.mindjolt.com/stay-up.html

[+] jopx|7 years ago|reply
Actually nothing, which makes me really frustrated.

I'm just building boring CRUD systems for boring companies. I can use a lot of concepts/buzzwords, like microservices, serverless... But at the end, just CRUD apps.

How can I improve? After 5 years just doing this, I don't feel capable of doing something cool like some of the posts in this thread.

[+] chrismeller|7 years ago|reply
Ehh, if you’ve only been developing for 5 years I’d say that’s fairly standard. Think about other fields: after 5 years practicing medicine you’re barely out of residency and still working 24 hour shifts doing the dirty work no one else wants to do. After 5 years as a lawyer you’re likely still an associate working 90 hours a week doing the same.

Just focus on learning new things as much as you can. Whether that’s from more senior guys at work or in your own time with side projects, all that matters is you learn. Then start applying for new jobs. You’ll probably be disappointed at first with rejections and/or the pay they’re willing to offer, but that’s fine - their feedback will show you where you need to focus your efforts to improve.

[+] kahlonel|7 years ago|reply
I wrote a data collection and messaging framework for devices with a few MBs of memory, that had to stay powered-on and connected to a TCP socket server for about a year before they were going to be accessible again for maintenance etc. A bug in the code that could require a reset of the device could cost the company a big client. I couldn't find any ready-made solution that would satisfy all of the requirements. So I wrote, tested, documented and deployed it in a month almost single handedly. Two and a half years later, that code is still serving them.
[+] jason_slack|7 years ago|reply
I guess when I was 12 and had a Commodore 64 in my bedroom. I stayed up late and got up early to learn basic, put sprites on the screen, debug and otherwise get caught up in whatever I wanted to create that day.

I’d like to say thank you to my father for buying it and keeping the chocolate milk and powdered doughnuts flowing.

[+] sawmurai|7 years ago|reply
Oh man, this brings up so many good memories :)