January 2018

# 6th tip to understand legacy code

Jan 2018

I just watched a video published 2 days ago: 5 Tips to Understand Legacy Code by Jonathan Boccara. I like it a lot, yet I feel that something is missing here. The author gives 5 tips for how can you start figuring out a large codebase that is new to you.

  1. "Find a stronghold" - a small portion of the code (even single line) that you understand perfectly and expand from there, look at the code around it.
  2. "Analyze stacks" - put a breakpoint to capture a representative moment in the execution of the program (with someone's help) and look at call stack to understand layers of the code.
  3. "Start from I/O" - analyze the code that processes data at the very beginning (input data, e.g. source file) or at the end (output data).
  4. "Decoupling" - learn by trying to do some refactoring of the code, especially to decouple some of its parts.
  5. "Padded-room" - find a code that doesn't depend on any other (has limited scope) and go from there.

These are all great advices. I agree with them. But computer programs have two aspects: dynamic (the way the code executes over time - algorithms, functions, control flow) and static (the way data are stored in memory - data structures). I have a feeling that these 5 points focus mostly on dynamic aspect, so as an advocate of "data-oriented design" I would add another point:

6. "Core data structure": Find structures, classes, variables, enums, and other definitions that describe the most important data that the program is operating on. For example, if it's a game engine, see how objects of a 3D scene are defined (some abstract base CGameObject class), how they can relate to each other (forming a tree structure or so-called scene graph), what properties do they have (name, ID, position, size, orientation, color), what kinds of them are available (mesh, camera, light). Or if that's a compiler, look for definition of Abstract Syntax Tree (AST) node and enum with list of all opcodes. Draw UML diagram that will show what data types are defined, what member variables do they contain and how do they relate to each other (inheritance, composition). After visualizing and understanding that, it will be much easier to analyze the dynamic aspect - code of algorithms that operate on this data. Together, they form the essence of the program. All the rest are just helpers.

Comments | #software engineering Share

# How to view CHM files on high DPI monitor?

Jan 2018

Using monitors with high resolution like 4K, where you need to set DPI scaling other than 100%, is pain in the *** in Windows - it causes trouble with many applications. That’s why I want to stick with FullHD monitors as long as possible. One of the apps that doesn’t scale with DPI is Microsoft’s own viewer for CHM files (Microsoft Compiled HTML Help). CHM is a file format commonly used for software help/documentation. It has been introduced with Windows 98 as a replacement for old HLP (WinHelp). Although we read almost everything online these days, some programs and libraries still use it.

A CHM document is completely unreadable on 4K monitor with 200% DPI scaling:

I searched Google for solution. Some sources say there is Font button in the app’s toolbar that lets increase font size, but it doesn’t work in my case. This page says that availability of this button can be configured when creating CHM file.  This page mentions some alternative readers for CHM format (Firefox plugin, as well as standalone app).

I know that apps which misbehave under high DPI can be configured to work in “compatibility mode”, when Windows just rescales their window. I found out that executable for this default CHM reader is c:\Windows\hh.exe, but I couldn’t find this setting in Properties of this file. I thought that maybe it’s because the file is located in system directory and owned by the system with insufficient privileges for administrators and normal users, so I came up with following solution that actually works:

  1. Copy file c:\Windows\hh.exe somewhere else, e.g. to D:\Soft\hh.exe
  2. Right-click file D:\Soft\hh.exe. Choose Properties -> “hh.exe Properties” window appears.
  3. Go to Compatibility tab. Check “Override high DPI scaling behavior. Scaling performed by:”. Set combobox below to “System (Enhanced)”. Click OK -> window closes.
  4. Launch this executable with command-line parameter to browse CHM file of your choice, e.g.: D:\Soft\hh.exe "d:\AGS_SDK-5.1.1\ags_lib\doc\amd_ags.chm" -> document should open in the browser with font size good for reading. Every pixel is just scaled to 2x2 pixels.

Comments | #windows Share

[Stat] [STAT NO AD] [Download] [Dropbox] [pub] [Mirror]
Copyright © 2004-2018