Hacker News new | ask | show | jobs
My Co-Founder threw away 90% of the code I wrote
21 points by imaginaryspaces 492 days ago
TL;DR: This is an appreciation post for all those co-founders who take our messy, hacky code, and somehow transform it into maintainable, production-ready software.

Back in October, my co-founder and I started working on an ambitious project to automate the entire machine learning lifecycle. We split our PoC into two parts: ML model generation (my part) and data generation (his part), tackling them independently. Within weeks, we had cobbled together a solution that could generate datasets from problem descriptions and then train ML models with them. Rather than getting caught up in perfection, we deployed it to AWS, exposed it as an API, and started getting user feedback.

The response was encouraging, but users consistently asked to see under the hood. Given we were working with data, open-sourcing seemed like the natural next step. While part of me wanted to immediately throw our code onto Github, my co-founder wisely suggested we take a step back, review, and refactor the critical pieces first.

Here's where it gets interesting: We decided to swap our codebases. I would review his data generation code, and he would tackle my ML model generation code. What followed was both humbling and enlightening.

His data generation code was a thing of beauty - meticulously documented, well-structured, and so clean that it took me just a couple of days to make minor tweaks for release. My code? Well... my co-founder spent over a week essentially rebuilding it from scratch while preserving the core functionality. In his typical gracious manner, he maintained the essence of what I'd built while making it actually maintainable.

Looking back, I basically threw spaghetti at the wall while my co-founder actually wrote real software. My code worked (somehow). Meanwhile, his codebase was like a well-organised library - everything in its place, properly documented, actually maintainable. Sure, we got our prototype out fast, but I'm pretty sure I owe him a few years of his life for having to deal with my "creative" approach to software engineering.

So here's to all the co-founders out there who clean up after us "move fast and break things" developers. Your dedication to code quality might not always be visible to users, but it's what transforms promising prototypes into lasting products.

3 comments

Can you share snippets of both so we can compare? Would be interesting to see
Unfortunately the old version is long gone now but I can show you the current version :)
No version control ?
You caught me trying to escape some embarrassment. Here's an example:

To set some context: The code handles isolated execution of machine learning code.

Original version:

    def run_code(code, timeout=3600):
        try:
            p = Process(target=exec, args=(code,))
            p.start()
            p.join(timeout)
            if p.is_alive():
                p.terminate()
                return "Timeout"
            return "Success"
        except Exception as e:
            return f"Failed: {str(e)}"
New version:

    class ProcessExecutor(Executor):
        def __init__(self, execution_id: str, code: str, 
                     working_dir: Path, dataset: pd.DataFrame, 
                     timeout: int = 3600):
            super().__init__(code, timeout)
            self.working_dir = Path(working_dir).resolve() / execution_id
            self.working_dir.mkdir(parents=True, exist_ok=True)
            self.dataset = dataset

        def run(self) -> ExecutionResult:
            start_time = time.time()
            code_file: Path = self.working_dir / self.code_file_name
            with open(code_file, "w") as f:
                f.write(self.code)
                
            try:
                process = subprocess.Popen(
                    [sys.executable, str(code_file)],
                    stdout=subprocess.PIPE,
                    stderr=subprocess.PIPE,
                    cwd=str(self.working_dir),
                    text=True,
                )
                stdout, stderr = process.communicate(timeout=self.timeout)
                return ExecutionResult(
                    term_out=[stdout],
                    exec_time=time.time() - start_time,
                    model_artifacts=self._collect_artifacts(),
                    performance=extract_performance(stdout),
                )
            except subprocess.TimeoutExpired:
                process.kill()
                return ExecutionResult(
                    term_out=[],
                    exec_time=self.timeout,
                    exception=TimeoutError(
                        f"Execution exceeded {self.timeout}s timeout"
                    ),
                )
It may be that his does something important yours doesn’t, but yours is much easier to understand! Short and clear is good.
100%. I code like OP and find it much easy to understand. The latter could be well structured but a novice coder like me needs comments to understand it.
Fair enough! Thats a good point :)
without further context, i think the original version is the better code.
Thanks!
The second snippet of code seems to come from a template. Perhaps your colleague had already worked on on a similar problem before (e.g., python code to runs processes)?
Perhaps, shall check with him! But this is only one example, there’s a lot of other places as well. In case you’re interested to see more the project we’re working on is https://github.com/plexe-ai/smolmodels
Does your co-founder come from 90s/early 2000s Java background?
No, he’s from a Python background :)
Well done! I thought this was going to be a whining rant where you lacked enough self reflection to maybe see there was a reason that your cofounder did it. But you did just the opposite.
Thank you! There’s absolutely no reason for me to rant since we have a solid foundation to build on now :)
BTW, in this age of AI... Writing beautiful, well-documented, well-tested code is a lot less painful.

You should use it since you are in AI space :p

Good point! The initial 60% of the code was thought out but with time passing, the urge to launch quicker became more important leading:)