RSS / Atom

Dev Tools & Tricks round-up 2014

2014-12-28 , , , Comment

A quick list of my favorite development tools and tricks, in no particular order:

  • Emacs! Okay, I do use Eclipse sometimes but nearly all my editing is done in Emacs. I’m waiting (maybe alone…) for Guile-Emacs to get to a release sometime before the ubiquity of the flying car and Mr. Fusion so I don’t have to worry about completely buggering up my editor with a poorly thought out background task.
  • The D-Language. I don’t want to write (or read) C++ unless I’m forced but D fits my programming niche.
  • When there isn’t eldoc, there’s Dash. Very convenient pop-up API documentation.
  • Cint, an interpreter for pre-C99 ANSI C and ISO C++ 2003, and its successor Cling, based on LLVM. Invaluable for interactively exploring vendor libraries or testing bits of code.
  • OSX FUSE. The file system in user space (FUSE) driver. I use it with SSHFS to present remote and VM filesystems as local ones for development without the hassle of syncing or using Emac’s Tramp mode.
  • Pry A better Ruby REPL (run, eval, print loop) than the included IRB. I wish I had known about this years ago. Thanks to Shahriar for pointing me to this and Zack for showing me why it’s better.
  • ZMODEM. It’s like a 1987 flashback but ZMODEM is the most convenient way to copy files to and from a host where you have SSH access. I have mine triggered in Iterm2.


Chibios/RT docset for

2014-12-05 , , , Comment

The is a great little offline API/documentation browser (there’s also zeal, which compiles on Unix/Linux and Windows). It’s fairly easy to produce your own docset so I put together one for ChibiOS/RT version 2.2.6, the open source RTOS I’m working with. Download (11MB) org.chibios.tgz from Google Drive.


D Language

2014-04-19 , , , Comment

I recently had to write a moderate amount of C around vendor libraries and get things working in three days. The effort resulted in about 3200 lines of ugly, hastily written code that compiled under gcc and clang with -Wall -Werror -pedantic and looked reasonably leak-free in Valgrind. I whittled it down over the following week as time permitted to a bit over 2000 lines.

Lines of code is a lousy metric, but it’s easy to extract using available tools. Here are the counts from cloc for the original two projects in C:

Language                     files          blank        comment           code
C                                3            298            193           1869
C/C++ Header                     3             32              0            178
SUM:                             6            330            193           2047

Quick passes with grep counts 11, 13, and 16 functions.

A better metric might be complexity. Running it through the cyclomatic complexity checker cyclo results in scores of 79, 99, and 110. These seem completely off the charts (10-15 is the recommended range for a “module”). Quick runs against some code I had lying around shows that these numbers are high (OpenBSD’s strncpy and a naive CRC-16 implementation I had both score a 5, SolarDesigner’s concat function scores a 12) but we can use them for comparison. Let’s torture the numbers by averaging, 13.3 functions and a score of 96, for about 7.2 complexity per function.

I’m always on the look out for an advantage (I need them…) and saw a recent announcement of a release of the D Language compiler. The features piqued my interest: native compilation, garbage collection and dynamic memory, types, classes, interfaces, mixins, exceptions, extensive standard library, and an easy interface to C. Walter Bright, the language designer and writer of the reference compiler, is well known. There’s a decent website, a tutorial, and C++ guru Andrei Alexandrescu wrote the book on the language. Cool, I thought, a better C++. I bought the book, started coding familiar tasks, and dug in during my little free time.

It went easily and I had a satisfactory result in a few days. The equivalent in D:

Language          files     blank   comment      code    scale   3rd gen. equiv
D                     2       109        96       709 x   1.70 =        1205.30
SUM:                  2       109        96       709 x   1.70 =        1205.30

Notice that I’ve reduced the number of files, I’ll get to that. The pass through grep counts 8 and 13 functions, of which 3 of them in each source file are two-line logging routines to replace the classic C preprocessor macros dbgprintf and errprintf. cyclo doesn’t perfectly handle D, but it’s reasonably close in syntax to C/C++, producing scores of 45 and 61. Twisting numbers again gives 10.5 and 53 for a score of about 5 per function. The improvement in complexity is on par with the reduction in lines of code.

The kicker is that not only are the D versions are shorter and easier to comprehend, they do more and have more robust error-checking and exception-handling. Overall I’m more confident they behave correctly. I replaced two independent programs with a single one. I replaced a throttled fork()-ing server with a fixed pool of workers. I leveraged associative arrays, JSON, and Base64 without rolling my own or borrowing from other Open Source libraries. None of this is stuff I couldn’t implement or find somewhere but I didn’t have to. Classic force multiplier of a programming language.


Burst Battery

2013-05-19 , , , Comment

The spare Macbook Pro battery burst overnight. It was sitting on my desk fully charged.

I’m glad it wasn’t in the laptop.


VoIP, SIP registration, and timeouts

2013-05-08 , , , Comment

Quick comment… Everyone in the family has multiple devices— phones, tablets, game consoles, computers— and these tend to make network connections that linger. If you have a firewall like I do, the default TCP and UDP timeouts are probably too high (often 3600 seconds) and when everyone is around on the weekend you get poor performance and strange complaints about how things don’t work. Separately, I have an OBI100 VoIP device providing phone to the house. The OBI100 has a default SIP registration period of 60 seconds and re-registers after half the interval, this is a bit too frequent so I have mine set to 300 seconds. As I’ve found, if the firewall expires the connection quickly you can end up with what looks like a valid registration at the SIP provider and can make outgoing calls but incoming calls fail. I’ve worked around it by expiring connections at 360 seconds for TCP and 180 seconds for UDP.


Ruby debugger in 1.9.3

2013-04-03 , , , Comment

I decided to really dig into Ruby and its ecosystem. It’s quick to get things started using RVM and the language is fun (and for what it’s worth, on my system Ruby 1.9.3 is slightly faster than Perl 5.12 on my favorite trivial string parsing test of extracting fields from 500,000 lines of Apache combined log) but coming from Python and Perl I find frustrating quirks in the tools. Today’s example is that the debugger is broken on 1.9.x and searching turns up hundreds of “fixes” that don’t work or only build for specific releases of ruby and the dependencies. I realize it isn’t “core”— there is a debug module in the 1.9.3 stdlib that is kind of undocumented— but it is the sort of thing you expect to work or get flagged as broken. It seems that the authors/maintainers of the debugger gave up on it, but Gabriel Horner has a fork that works.


« Older Posts