@@ -432,17 +432,20 @@ considered as "one set goal", but apparently it will not be useful for reading t
432432actually. It will not be a trigger of any concrete action. Therefore, your first job will be to
433433drag down the vague goal to the level of a concrete thing.
434434
435- Then, what will the method be? Firstly, it's good if you pretend that you are the composer of
435+ Then how can we do it? The first way is thinking as if you are the person who wrote
436436the program. You can utilize your knowledge in writing a program, in this case. For example,
437437when you are reading a traditional "structured" programming by somebody, you will analyze it
438438hiring the strategies of structured programming too. That is, you will divide the target into
439- pieces, little by little. For another example, suppose you are reading a GUI program that walks
440- around in an event loop, you can just start looking at the event loop before studying the roles
441- of the event handlers. In another case, you will look up what "M" is for in MVC (Model View Controller).
439+ pieces, little by little.
440+ If it is something circulating in a event loop such as a GUI program,
441+ first roughly browse the event loop then try to find out the role of each event
442+ handler. Or, try to investigate the "M" of MVC (Model View Controller) first.
442443
443- Secondly, keep in mind the methods of analysis. Everybody might have certain analysis methods,
444- but they are often done based on experience and relying inspiration. It's crucially important
445- to give it to the notion how to read source code well.
444+ Second, it's good to be aware of the method to analyze.
445+ Everybody might have certain analysis methods,
446+ but they are often done relying on experience or intuition.
447+ In what way can we read source codes well?
448+ Thinking about the way itself and being aware of it are crucially important.
446449
447450Well, what are such methods like? I will explain it in the next section.
448451
@@ -464,20 +467,22 @@ should at least be closer to the fact than dynamic analysis.
464467
465468h3. Dynamic analysis
466469
467- h4. Use the target program
470+ h4. Using the target program
468471
469472You can't start without the target program. First of all, you need to know in advance what
470473the program is like, and what are expected behaviors.
471474
472- h4. Follow the behavior using the debugger
475+ h4. Following the behavior using the debugger
473476
474477If you want to see the paths of code execution and the data structure produced as a result,
475478it's quicker to look at the result by running the program actually than to emulate the behavior
476479in your brain. In order to do so easily, use the debugger.
477480
478- However, there is not adequate tools unfortunately, especially in free software,
479- that can generate the picture of the data structure at execution. A snapshot of the comparatively
480- simpler structure may be obtained by converting text data obtained instantly into a picture using
481+ I would be more happy if the data structure at runtime can be seen as a picture,
482+ but unfortunately we can nearly scarcely find a tool for that purpose
483+ (especially few tools are available for free).
484+ If it is about a snapshot of the comparatively simpler structure,
485+ we might be able to write it out as a text and convert it to a picture by using a tool like
481486graphviz\footnote{graphviz……See doc/graphviz.html in the attached CD-ROM}.
482487But it's very difficult to find a way for general purpose and real time analysis.
483488
@@ -492,85 +497,96 @@ If you are watching the history of one variable, for example, it may be easier t
492497to look at the dump of the result of the print statements embed, than to track the variable
493498with a debugger.
494499
495- h4. Understanding code by modifying it
500+ h4. Modifying the code and running it
496501
497- Say for example, you do not understand some part of the code or a particular parameter,
498- just make a small change and then re-run the program.
499- By trying out small changes and seeing how they affect the code you will understand how it works.
502+ Say for example, in the place where it's not easy to understand its behavior,
503+ just make a small change in some part of the code or a particular parameter
504+ and then re-run the program.
505+ Naturally it would change the behavior, thus you would be able to infer the
506+ meaning of the code from it.
500507
501- It goes without saying, you should have an original binary to compare your changes to.
508+ It goes without saying, you should also have an original binary
509+ and do the same thing on both of them.
502510
503511h3. Static analysis
504512
505513h4. The importance of names
506514
507- Static analysis is simply source code analysis. Therefore, source code analysis is
515+ Static analysis is simply source code analysis. And source code analysis is
508516really an analysis of names. File names, function names, variable names, type names,
509- member names -- A program is just a bunch of names.
517+ member names -- A program is a bunch of names.
510518
511- One of the most powerful tools for creating abstractions in programming is naming.
512- This may seem obvious but keeping this in mind will make reading much more efficient.
519+ This may seem obvious because
520+ one of the most powerful tools for creating abstractions in programming is naming,
521+ but keeping this in mind will make reading much more efficient.
513522
514- Also, I 'd like to mention something about coding rules.
523+ Also, we 'd like to know about coding rules beforehand to some extent .
515524For example, in C language, @extern@ function often uses prefix to distinguish the type of functions.
516- And in object-oriented programs, the name of member fields in a function often includes prefix,
517- which is really important information (e.g. @rb_str_length@).
525+ And in object-oriented programs, function names sometimes contain the
526+ information about where they belong to in prefixes,
527+ and it becomes valuable information (e.g. @rb_str_length@).
518528
519- h4. Read documents
529+ h4. Reading documents
520530
521531Sometimes a document describes the internal structure is included.
522532Especially be careful of a file named @HACKING@ etc.
523533
524- h4. Read the directory structure
534+ h4. Reading the directory structure
525535
526- You should read in what policy the directories are devided .
527- You can grasp the overview about how the program is structured, and what the parts are.
536+ Looking at in what policy the directories are divided .
537+ Grasping the overview such as how the program is structured, and what the parts are.
528538
529- h4. Read the configuration of the files
539+ h4. Reading the file structure
530540
531- While browsing the name of the functions, see how the file files are divided.
541+ While browsing (the names of) the functions,
542+ also looking at the policy of how the files are divided.
532543You should pay attention to the file names because they are like comments
533544whose lifetime is very long.
534545
535- Another important viewpoint is to locate a module in the file.
536- Functions for the module are thought to be located in a series.
537- So, you can understand the module's structure from the order of functions.
546+ Additionally, if a file contains some modules in it,
547+ for each module the functions to compose it should be grouped together,
548+ so you can find out the module structure from the order of the functions.
538549
539- h4. Investigate abbreviations
550+
551+ h4. Investigating abbreviations
540552
541553As you encounter ambiguous abbreviations, make a list of them and investigate
542- each of them as early as possible. For example, suppose @GC@ is short for Garbage Collection.
543- But the context will be very different if it's actually short for Graphic Context.
554+ each of them as early as possible. For example, when it is written "GC",
555+ things will be very different depending on whether it means "Garbage Collection"
556+ or "Graphic Context".
544557
545558Abbreviations for a program are generally made by the methods like taking
546- the initial letters or dropping the vowels. Note especially the fact that
547- popular abbreviations in the fields of the program's target are used without notice.
548- You should be familiar with them at an early stage.
559+ the initial letters or dropping the vowels. Especially,
560+ popular abbreviations in the fields of the target program are used
561+ unconditionally, thus you should be familiar with them at an early stage.
562+
549563
550- h4. Understand data structure
564+ h4. Understanding data structure
551565
552566If you find both data and code, you should first investigate the data structure.
553- In other words, when exploring code in C, it's better to start with the header file .
554- When reading filenames, you should use your imagination as much as possible .
567+ In other words, when exploring code in C, it's better to start with header files .
568+ And in this case, let's make the most of our imagination from their filenames .
555569For example, if you find @frame.h@, it would probably be the stack frame definition.
556570
557- Also, you can understand many things from the type and member name in a structure .
571+ Also, you can understand many things from the member names of a struct and their types .
558572For example, if you find the member @next@, which points to its own type, then it
559573will be a linked list. Similarly, when you find members such as @parent@, @children@,
560574and @sibling@, then it must be a tree structure. When @prev@, it will be a stack.
561575
562- h4. Understanding the relationship between functions
576+ h4. Understanding the calling relationship between functions
563577
564578After names, the next most important thing to understand is the relationships between
565- functions. It's very useful to visualize the relationship between functions and
566- their callers with a tool called a "call graph". I highly recommend you use one .
579+ functions. A tool to visualize the calling relationships is especially called a
580+ "call graph", and this is very useful. For this, we'd like to utilize tools .
567581
568- A text-based tool is sufficient, but call graph tool that generates an actual graph is even better.
569- There are not so many tools that generate these graphs, though and most are shareware, not OSS or freeware.
570- I often use graphviz to generate these graphs.
571- I also implemented a small Ruby parser to generate output for graphviz, then graphviz generates the graph.
582+ A text-based tool is sufficient,
583+ but it's even better if a tool can generate diagrams.
584+ However such tool is seldom available (especially few tools are for free).
585+ When I analyzed @ruby@ to write this book,
586+ I wrote a small command language and a parser in Ruby and
587+ generated diagrams half-automatically by passing the results to the tool named @graphviz@.
572588
573- h4. Read functions
589+ h4. Reading functions
574590
575591動作を読んで、関数のやることを一言で説明できるようにする。関数関連図を
576592見ながらパートごとに読んでいくのがいい。
0 commit comments