Is there any guiding principle which is beneficial while working with existing code base?
Ask HN: How to be productive with big existing code base
1–10 of 187 posts
Re: Ask HN: How to be productive with big existing code base
#2Re: Ask HN: How to be productive with big existing code base
#3Re: Ask HN: How to be productive with big existing code base
#4I recommend the book Working Effectively with Legacy Code by Michael Feathers. I've been reading it recently, and I've enjoyed the lessons and advice so far.
Re: Ask HN: How to be productive with big existing code base
#5Tools: emacs, org mode, org babel.
Create a parallel directory structure, hypothetical project:
./src
./project/src/main.js
./project/src/some-file.js
Create a new directory structure with one org file per source file and one index org file: ./project-org/src/main.org
./project-org/src/some-file.org
./project-org/index.org
(You can organize it differently, this has worked for me.)index.org will be a simple tree view of the folder hierarchy:
* Project Name
Description
** Source Files
*** src
**** [file:src/main.org]
**** [file:src/some-file.org]
You may add in some notes about the general purpose of each of those files.main.org copy the entire code into the main.org file like:
* main.js
#+BEGIN_SRC js
// all the code from main.js
#+END_SRC
* [[file:../index.org][Project Root]]
Start splitting the contents of main.js into separate snippets, I don't know Javascript very well so let me make some quick C example: * main.c
#+BEGIN_SRC c :noweb yes :tangle yes
>
>
>
#+END_SRC
** includes
#+NAME: includes
#+BEGIN_SRC c
,#include // [0]
#+END_SRC
** structs
#+NAME: structs
#+BEGIN_SRC c
// structs
#+END_SRC
** functions
#+NAME: functions
#+BEGIN_SRC c :noweb yes
>
>
#+END_SRC
*** main
#+NAME: functions
#+BEGIN_SRC c
int main (...) {...}
#+END_SRC
*** some_func
This function will initialize a block of memory
to be used as a shared buffer between two processes.
#+NAME: some_func
#+BEGIN_SRC c
void some_func (...) {...}
#+END_SRC
As you go through this you can make cross-references to other files and functions/structures. Eventually you'll find a smallest reasonable unit. A long, but clear, function doesn't need to be dissected. But a short, complex one, may end up with each line broken out and analyzed.I don't just import a massive code base and do this in one go. Instead I import parts of it and break down all the related files to a particular topic ("How does X happen?"). I trace it from start to end, and then repeat with the next question. Good, modular code makes this much, much easier. The more tightly coupled, the harder it is to understand no matter the method.
[0] The comma is inserted by org babel to distinguish from it's on #-prefixed content.
Re: Ask HN: How to be productive with big existing code base
#6I think it's developer nature to look at a huge pile of code that someone else wrote and immediately think: "This is a pile of crap. I can do better, so the first thing to do is rewrite all of this, my way (which just so happens to be _The Right Way_)."
Figure out what you're trying to do, and what is keeping you from doing it. Take an iterative approach to get things done. Realize that after 3 years, they have hopefully fixed a lot of bugs and got to a solution that is somewhat mature and better than you can do in a week.
Re: Ask HN: How to be productive with big existing code base
#7My #1 rule for existing codebases: Just because you wouldn't have done it the way they did doesn't mean they did it wrong. I think it's developer nature to look at a huge pile of code that someone else wrote and immediately think: "This is a pile of crap. I can do better, so the first thing to do is rewrite all of this, my way (which just so happens to be _The Right Way_)." Figure out what you're trying to do, and wh…
I see myself in your words.
Re: Ask HN: How to be productive with big existing code base
#8My #1 rule for existing codebases: Just because you wouldn't have done it the way they did doesn't mean they did it wrong. I think it's developer nature to look at a huge pile of code that someone else wrote and immediately think: "This is a pile of crap. I can do better, so the first thing to do is rewrite all of this, my way (which just so happens to be _The Right Way_)." Figure out what you're trying to do, and wh…
I'll take this one step further and say: if you think this, you're unqualified for the position. You are an amateur.
Re: Ask HN: How to be productive with big existing code base
#9My #1 rule for existing codebases: Just because you wouldn't have done it the way they did doesn't mean they did it wrong. I think it's developer nature to look at a huge pile of code that someone else wrote and immediately think: "This is a pile of crap. I can do better, so the first thing to do is rewrite all of this, my way (which just so happens to be _The Right Way_)." Figure out what you're trying to do, and wh…
"This is a pile of crap. I can do better," I'll take this one step further and say: if you think this, you're unqualified for the position. You are an amateur.