News for hackers. Stuff that matters.
Re:Ask HN: How do you familiarize yourself with a new codebase? by tessierashpool on Friday June 26, 2015 @10:06AM (#9784408)
I wrote some simple bash scripts around git which allow me to very quickly identify the most frequently-edited files, the most recently-edited files, the largest files, etc.

https://github.com/gilesbowkett/rewind

it's for assessing a project on day one, when you join, especially for "rescue mission" consulting. it's most useful for large projects.

the idea is, you need to know as much as possible right away. so you run these scripts and you get a map which immediately identifies which files are most significant. if it's edited frequently, it was edited yesterday, it was edited on the day the project began, and it's a much bigger file than any other, that's obviously the file to look at first.

we tend to view files in a list, but in reality, some files are very central, some files are out on the periphery and only interact with a few other files. you could actually draw that map, by analyzing "require" and "import" statements, but I didn't go that far with this. those vary tremendously on a language-by-language basis and would require much cleverer code. this is just a good way to hit the ground running with a basic understanding which you will very probably revise, re-evaluate, or throw away completely once you have more context.

but to answer your actual question, you do some analysis like this every time you go into an unfamiliar code base. you also need to get an idea of the basic paradigms involved, the coding style, etc. -- stuff which would be much harder to capture in a format as simple as bash scripts.

one of the best places to start is of course writing tests. Michael Feather wrote a great book about this called "Working Effectively with Legacy Code." brudgers's comment on this is good too but I have some small disagreements with it.

Re:Ask HN: How do you familiarize yourself with a new codebase? by fokz on Friday June 26, 2015 @11:11AM (#9785001)
Thanks for sharing. I often get lost in large projects. Blindly jumping around is quite inefficient and frustrating.

How hard do you think it is to write a tool to draw dependencies map for a specific language?

May be there're built-in code analyzing tools in compilers for popular languages that I'm not aware of?

Re:Ask HN: How do you familiarize yourself with a new codebase? by h8liu on Friday June 26, 2015 @01:36PM (#9786394)
For golang std lib, since packages have no circular deps, it can be automatically drawn out like this:

http://lonnie.io/gostd/dagvis/

If you write your project that even has no circular deps among files and all files are small (like me in https://github.com/h8liu/e8vm), you can draw the similar graph but at a much finer granularity, like this:

http://8k.lonnie.io/

Re:Ask HN: How do you familiarize yourself with a new codebase? by baby on Friday June 26, 2015 @10:14PM (#9788822)
wow! What did you use to make these? It looks awesome!
Re:Ask HN: How do you familiarize yourself with a new codebase? by h8liu on Friday June 26, 2015 @11:59PM (#9789045)
Thanks.

Here are my hand-made tools to generate those stuff: https://github.com/h8liu/e8tools

Javascript version (I actually wrote this first for go std lib): https://github.com/h8liu/dagvis

Re:Ask HN: How do you familiarize yourself with a new codebase? by tessierashpool on Friday June 26, 2015 @01:14PM (#9786201)
dependency graphs and code analysis are huge topics. this is probably the hard part with libraries like npm or Bundler.

the graphs can have cycles, multiple references to the same dependency, multiple distinct versions of the same dependency, et cetera. it's also all very, very language-specific. in many languages, the order of the require or import statements matter; in others, they don't. you can also have something like Clojure, with several different ways of bringing in a dependency, which makes the whole issue much more fine-grained.

prior to writing these scripts, I tried to do something more ambitious with auto-refactoring tools. these exist in Eclipse and can even be graceful in Smalltalk but my own results were not so amazing. I got somewhere with regular expressions, code generation, and shell scripting. but I also built a thing in Ruby which could auto-refactor a tiny, TINY subset of the most obvious refactorings in JavaScript. it took me months, maybe harmed my sanity, and was definitely not the best code I ever wrote.

TLDR: compilers, zomg.

edit: forgot to say you're welcome. :-)

Re:Ask HN: How do you familiarize yourself with a new codebase? by roflc0ptic on Friday June 26, 2015 @11:24AM (#9785119)
Re:Ask HN: How do you familiarize yourself with a new codebase? by rch on Friday June 26, 2015 @10:18AM (#9784496)
Great answer. I can't begin to estimate how many times I've considered writing something along these lines.

It might be nice to surface files that are frequently edited together as well.

Re:Ask HN: How do you familiarize yourself with a new codebase? by azeirah on Friday June 26, 2015 @10:21PM (#9788836)
I made a crappy visualization of the commits of our University project, http://codepen.io/Azeirah/pen/bdawBm

It was a 3D pong game, along with the game engine. Pretty neat to see this visualized.

Re:Ask HN: How do you familiarize yourself with a new codebase? by thameera on Saturday June 27, 2015 @11:08AM (#9790383)
Anybody knows a similar analysis tool for an SVN project? One option would be to convert the SVN to git for analysis purposes, but I'd be interested in a better solution.
Re:Ask HN: How do you familiarize yourself with a new codebase? by r41nbowcrash on Monday June 29, 2015 @04:59AM (#9797041)
never tried it myself, but you can take a look at the accompanying code "Your Code as a Crime Scene"

https://github.com/adamtornhill/code-maat

Re:Ask HN: How do you familiarize yourself with a new codebase? by thameera on Monday June 29, 2015 @12:55PM (#9799277)
Thanks! Gonna give this a try.
Re:Ask HN: How do you familiarize yourself with a new codebase? by baby on Friday June 26, 2015 @02:15PM (#9786649)
Is it normal that it takes a while > 2minutes to run your program on some big java repo?

edit: took like 4 minutes, worked well!

Re:Ask HN: How do you familiarize yourself with a new codebase? by tessierashpool on Friday June 26, 2015 @02:33PM (#9786770)
quoting from the readme:

Caveat: Running this code against extremely large projects with very long histories (e.g. Rails) might be very slow.

Re:Ask HN: How do you familiarize yourself with a new codebase? by davelnewton on Friday June 26, 2015 @02:21PM (#9786693)
That doesn't seem very long at all.
Re:Ask HN: How do you familiarize yourself with a new codebase? by davelnewton on Sunday June 28, 2015 @10:20AM (#9793540)
Well, it doesn't; wth.
Re:Ask HN: How do you familiarize yourself with a new codebase? by rajathagasthya on Friday June 26, 2015 @12:41PM (#9785899)
Thanks for sharing. For someone in their early career like me, this is very useful.
Re:Ask HN: How do you familiarize yourself with a new codebase? by lsiebert on Friday June 26, 2015 @08:19PM (#9788497)
Hmm... this is an interesting project. No License info though.
Re:Ask HN: How do you familiarize yourself with a new codebase? by lsiebert on Friday June 26, 2015 @09:06PM (#9788642)
Added a pull request to use git ls-tree for filenames so you only check stuff in the repo, instead of find. Hopefully it will end up on an open source license of some sort.
Re:Ask HN: How do you familiarize yourself with a new codebase? by zodvik on Saturday June 27, 2015 @01:49AM (#9789256)
Very simple & quite effective. Thanks for sharing.
Re:Ask HN: How do you familiarize yourself with a new codebase? by rpcope1 on Friday June 26, 2015 @10:50AM (#9784777)
Very cool! Thanks for sharing your scripts.
Re:Ask HN: How do you familiarize yourself with a new codebase? by nmb on Friday June 26, 2015 @11:59AM (#9785495)
thanks for making this and sharing!