TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

You Don't Read Code, You Explore It

158 pointsby dotyabout 11 years ago

26 comments

ChuckMcMabout 11 years ago
It is an interesting observation. I expect it is the difference in expertise though. The author compares reading code snippets in Dr. Dobbs (which dates them probably 10 or 15 years ago) to reading stories.<p>Here is the thing, everything you read in a story is supposed to convey imagery of things like what you may have already experienced, they are already internalized, you &quot;see&quot; them when you read as if you were there.<p>Allow me to use another popular space as an example, music. When you are first reading sheet music, you see notes on a stave, key signatures, different shapes representing different durations. At first you mechanically take that understanding and laboriously turn it into actions on your instrument. But after a while, if you do it enough, the shapes become recognizable as rhythms, the tones in the staves become tones not symbols, and then you stop &quot;reading&quot; music, you look at it and you can hear what it will sound like. And by that time you can make your instrument do what ever you hear.<p>Coding is not entirely different, at some point you don&#x27;t see syntax, you see algorithm, you see inter-relationships of data structures, you see flow. After a number of years of coding I got to the point where I could see what code was doing pretty easily (except for obfuscated code which is always jarring on first look). I stop seeing code loops and start seeing iterative processing, if statements are branches on a path.<p>Anything in words or symbols, is code for something else. Whether its a murder mystery, a symphony, or a sorting algorithm the words and symbols are there to express the idea inside your head you can understand it, I think it is all reading though :-)
评论 #7613007 未加载
评论 #7611993 未加载
评论 #7611740 未加载
评论 #7613054 未加载
评论 #7614400 未加载
curtisabout 11 years ago
I&#x27;ve pretty much come to the conclusion that you don&#x27;t understand code by reading it. Understanding someone else&#x27;s code is almost always a reverse engineering exercise. It&#x27;s often necessary to actually run the code repeatedly to understand it. This should really come as no surprise. It&#x27;s likely that the guy that wrote the code didn&#x27;t write it all at once, but rather wrote it in increments testing along the way. If he couldn&#x27;t write it without testing every little bit, it&#x27;s unlikely that you can read it without doing the same.
评论 #7612429 未加载
评论 #7613106 未加载
评论 #7611908 未加载
评论 #7612652 未加载
spankaleeabout 11 years ago
And this is one of the main reasons I massively prefer type annotations, statically analyzable languages and IDEs over dynamically typed languages, very loose languages and plain text editors.<p>Not being able to see what types code deals in, jump to definition, and find usages makes me feel crippled when exploring a new codebase.<p>One of my wished for programmers everywhere is that tools like Github and BitBucket start analyzing projects and letting you navigate better. I think that could save thousands of engineer hours.<p>This topic alone is a huge reason I started using Dart and eventually joined the team. Trying to figure out how a very large JavaScript codebase works is so incredibly painful, doing so in Dart is incredibly easy. This is also where very reflective libraries like Guice go wrong, and why, in my opinion, meta-programming should be used very carefully and sparingly.
评论 #7614610 未加载
coolsunglassesabout 11 years ago
One of my ideas I&#x27;ve been kicking around for the last year or two has been to write a book on learning to read code properly. I would submit that one of the greatest weaknesses of your typical programmer is that they don&#x27;t know how to read other peoples&#x27; code.<p>On another note, being able to read other peoples&#x27; code is one of the strengths of Haskell. The Functor&#x2F;Monad&#x2F;Monoid&#x2F;etc stuff becomes a way to know, based on a common vernacular, exactly what kind of interface is being exposed and what sort of data structures you&#x27;re working with.
评论 #7619226 未加载
userbinatorabout 11 years ago
I&#x27;ve read a lot of code (both source and otherwise) and found that in many cases one of the biggest barriers to understanding the system as a whole is actually abstraction&#x2F;indirection -- or more precisely, the often-excessive use of such. Following execution across multi-level-deep call chains that span many different files in different subdirectories feels almost like obfuscation, and all the pieces that are required to understand what happens in a particular case (important when e.g. looking for a bug) are scattered thinly over the whole system such that it takes significant effort to collect them all together.<p>In my experience, the majority of existing codebases I&#x27;ve worked with tends to be this way, although there are exceptions where everything is so simple and straightforwardly written that reading them is almost an enlightening experience.
Chris_Newtonabout 11 years ago
Program comprehension seems like a fascinating research field if you enjoy figuring out why we do the things we do as software developers. It seems that we do indeed explore code, but we do so in somewhat systematic and predictable ways, which in turn might give us ideas about how to <i>write</i> our code to be more readable.<p>If anyone is interested, I suggest the publications of Anneliese von Mayrhauser and A. Marie Vans from the mid-90s as a possible starting point. They did a lot of work to reconcile earlier theories and paint a more unified big picture. Václav Rajlich is another name to search for, with several interesting publications in the early 2000s.
kaelukaabout 11 years ago
This is related to something that I pondered about yesterday. In main stream languages, imperative programs require you to read the whole thing, while functional programs allow you to look at a function and derive its meaning only from its implementation: there can&#x27;t be another influence on the outcome, as there are no side effects and types are -- in ML&#x2F;Haskell family members -- precise. So referential transparency, in a sense helps you to read code depth-first, only looking at the relevant bits now.<p>As soon as you branch off from basic type systems and add in, for instance, subtyping or type classes or existential quantification, this ability is getting weakened. Now, in order to understand what a piece of code does, you need to understand some context: &#x27;which implementation is it?&#x27;, &#x27;what do the possible implementations have in common?&#x27;. The effects of this small complexities add up until there&#x27;s too much information to be kept in biological memory at the same time, the oldest thunk of information gets purged.<p>I do think that typed and pure languages have big advantages here: the information that I need is available immediately from looking at the type of the reference to it. If the types aren&#x27;t funky, I can assume that it will terminate, throw no exception, not suffer from data races -- I can exclusively think about <i>what</i> it does, not how (btw, I&#x27;m not having one specific reference language in mind right now, I&#x27;m just thinking about what would be possible).
necubiabout 11 years ago
Here&#x27;s a challenge for somebody: create a code review&#x2F;pull request tool that helps you really <i>understand</i> the code changes. Some IDEs do an ok job of this for static code (IntelliJ for Java, Emacs haskell-mode), but I&#x27;ve never seen a good tool for giving insight into how a diff is changing a program at the structural level.
评论 #7612056 未加载
评论 #7611767 未加载
thomabout 11 years ago
Part of my difficulty reading large code bases is there&#x27;s often no particularly good entry point to start from. Towards the end of my time in OO languages I was struck by Reenskaug and Coplien&#x27;s DCI [1] - many people just don&#x27;t model a system&#x27;s use cases as first class concepts. The most important part of a system - what it actually does! - doesn&#x27;t get explicitly mentioned in a lot of people&#x27;s code.<p>[1] <a href="http://en.wikipedia.org/wiki/Data,_context_and_interaction" rel="nofollow">http:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Data,_context_and_interaction</a>
softbuilderabout 11 years ago
I rewrite code to explore and understand it. This actually started as a bad habit - &quot;Oh, I can&#x27;t believe this person did X, I&#x27;m going to change that to Y&quot;. Do that enough and you quickly figure out exactly <i>why</i> they did X, and they were either smarter than you or much more familiar with the problem domain. But now you know a little more, you have a little more respect for the code, a little more humility, etc..<p>Nowadays I take it as a given that I&#x27;m probably wrong, but I start rewriting anyway. Worst case (and most common case) I have to toss the code. But I learn. Plus there&#x27;s a different place your brain goes when you feel like you control the code vs. looking at it behind glass.
评论 #7612053 未加载
评论 #7612089 未加载
anigbrowlabout 11 years ago
I&#x27;m baffled by the absence of tools for diagram generation from code and things like contextual highlighting in, well, every code editor. Even code folding seems pretty primitive. Bret victor &amp; the LightTable team are proposing some significant innovations, but most IDEs make me feel like I&#x27;m trying to explore a room through a keyhole.
beliuabout 11 years ago
I find it surprising that in 2014, most of the tools we use to read code treat it mostly like any other text. With the exception of some IDEs for some languages (e.g., Eclipse and Java), very few apps for browsing code actually understand its structure, i.e., the hierarchy of symbols and namespaces and the implicit graph defined by module imports, function calls, type references, etc. We&#x27;re relying more and more on external, often open-source libraries, and are therefore spending more and more of our time reading through other people&#x27;s code. Yet the tools don&#x27;t seem to have caught up.
collintabout 11 years ago
Code is easy to read if you understand the domain.<p>Code is nearly impossible to read if you don&#x27;t understand the domain.
评论 #7611900 未加载
评论 #7611916 未加载
javertabout 11 years ago
My technique for reading code is to find out where execution starts and go from there, following what the code does at runtime.<p>If you do it any other way, it won&#x27;t necessarily make sense. This is really the only way to do it. (Though I&#x27;d be interested in hearing other perspectives.)<p>This was a hard-won lesson for me because we programmers tend to make the control flow of our programs start at the <i>bottom</i> of source files.
rmthompsonabout 11 years ago
There are many things that you read that are neither enjoyable, nor easy to understand. Especially at a cursory read. That doesn&#x27;t make the word less appropriate, nor does it make the word explore any more appropriate. I don&#x27;t explore a quantum physics textbook, nor do I explore a journal article on tubulins. I read, I jot down notes, and I read some more.
georgeoliverabout 11 years ago
Don&#x27;t professional readers (i.e. writers, lit critics, or just close readers) also read literature differently than casual readers?
评论 #7612016 未加载
sparkieabout 11 years ago
I like Tim Daly&#x27;s viewpoint that we shouldn&#x27;t just be writing <i>code</i>, but we should write <i>manuals</i> - giving high level overviews of our problems and specifying their implementation details inside the manuals. His talk &quot;Literate Programming in the Large&quot;[1] covers why.<p>The example he gives in his talk is the Axiom algebra system[2], which was revised to use literate programming style - the source code, with usage examples, is contained entirely within the books.<p>[1]:<a href="https://www.youtube.com/watch?v=Av0PQDVTP4A" rel="nofollow">https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=Av0PQDVTP4A</a>, [sldes]: <a href="http://daly.axiom-developer.org/TimothyDaly_files/publications/DocConf/LiterateSoftwareTalk.pdf" rel="nofollow">http:&#x2F;&#x2F;daly.axiom-developer.org&#x2F;TimothyDaly_files&#x2F;publicatio...</a><p>[2]:<a href="https://en.wikipedia.org/wiki/Axiom_%28computer_algebra_system%29" rel="nofollow">https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Axiom_%28computer_algebra_syst...</a>
dugmartinabout 11 years ago
I wrote this a couple of years ago to help read and explore code:<p><a href="http://sherlockcode.com/demos/jquery/" rel="nofollow">http:&#x2F;&#x2F;sherlockcode.com&#x2F;demos&#x2F;jquery&#x2F;</a><p>It&#x27;s recently seen a spike of interest and I&#x27;ve started working on it again. The beta sign up link is still active if you are interested in getting updates.
girvoabout 11 years ago
Yes, yes, yes! I agree wholeheartedly. Exploratory programming is my new favourite weapon for learning about new codebases, new languages, new everything.<p>I just started a new job at a really interesting agency. I got put on to a 12 month old project, a huge web application, that started life overseas, moved back here to Australia, and according to git-blame has then moved through the hands of nearly 15 developers, a solid 70% don&#x27;t work here anymore (most were contractors).<p>So, the codebase is a mess. But, with Xdebug and a neat client for it that gives an interactive console when you hit a breakpoint, two weeks later I&#x27;m already understanding the twists and turns far better than I ever hoped for!
shurcooLabout 11 years ago
I agree, I think we need better tools for exploring code. [1]<p>I&#x27;m currently envisioning (and trying to build) something where the types&#x2F;func definitions are hyperlinks, and they jump to definition in an overlaying window similar to when you navigate in Spotify (the web based player). So you can quickly explore something without losing context.<p>[1] <a href="https://twitter.com/shurcooL/status/156526541214457856" rel="nofollow">https:&#x2F;&#x2F;twitter.com&#x2F;shurcooL&#x2F;status&#x2F;156526541214457856</a>
评论 #7614677 未加载
nalandabout 11 years ago
For him has been in the field more than thirty years, this author speaks too easy about some important figures. I stop &#x27;reading&#x27; or &#x27;exploring&#x27; and start writing —all the CSworld is a scene and MS and Int, merely players. However, I downgrade the article.
halayliabout 11 years ago
I think there should be a university course that teaches how to read code; the good, the bad and the ugly.
knownabout 11 years ago
You Don&#x27;t Read Code, You Debug It.
ttfleeabout 11 years ago
The way to explore a bunch of codes is really dependent to how much time and effort one can pour into:<p>- To grep it<p>- To debug it<p>- To read over it<p>- To rewrite it
psychometryabout 11 years ago
We know. It&#x27;s just an expression.
DonHopkinsabout 11 years ago
The road to fail is paved in goto intentions.