Friday, April 14, 2017

Hack C

Work has been busy and eating up most of my "Copious Free Time", so most of my projects have been placed on hold.

However, one thing I am getting from the past 6 months "deep dive" back into C programming (I've been programming C on and off since 1985 -- yes over 30 years *gasp*), is that a lot of my code in LuaJIT, Perl, C++11, Clojure and Haskell (and others) could be rewritten pretty concisely in C (C99 or C11 in particular).

Now, hold on, you say -- that is crazy talk.

A lot of the types of applications/tools I write are "system level".  When not coding Cortex M4 ARMs (my day job) I do a fair bit of networking (ethernet/IP packet level) hacking.  Or, I use libraries such as OpenCV to do simple vision stuff. So, I am not really using the advantages of higher level programming languages.

What I am really benefiting from is those language's  REPL -- the interactivity.  

I recently rewrote an OpenCV based image detection application, I originally explored and coded in LuaJIT, in C99. It was almost a line by line translation (I even found a couple of bugs!).

Okay, so honestly, I wonder if I had some sort of C REPL (gdb on steroids?), all I am missing is a nice convenient hash table (i.e. associative array, dictionary, etc).  I don't like the baggage of bringing in whole toolkits/frameworks for that (I like to keep my C lightweight and avoid things like pseudo-OO), so I just need a nice fast, generic hashtable implementation.

I need to get back into hacking C (for a while at least) and avoid the drama associated with picking a programming language "tribe".

Wednesday, February 01, 2017

Perl 6 - Diving in...

So, I've been a long time Perl user since the 1990s.  I rarely used it on job, but my only (widely?) used open source contribution is an application written in Perl 5: AFT (It is on github and is also available to any Ubuntu based distro by typing "sudo apt install aft".

Apparently, Perl 6 is now usable.

It looks very interesting. In particular, I am excited about its concurrency/parallel support (why is it that so few languages come with this baked in?).  The FFI looks usable (I've managed to get Perl 6 working with libusb pretty quickly).

But why bother?

I've always liked the language design approach of Perl.  The maximal syntax approach is dense but can have some appeal. In particular, it seems to avoid the (overbearing) library approach that other languages take.  This is a strength shared by Haskell and (yes) C++1x (C++11, C++14, etc).

For me, a couple of lines of well written code always wins over the "I must dive into a hierarchy of libraries and calls".  You just need to avoid making the couple of lines too dense.

This is the thing... in C++ and Perl I tend to avoid libraries if I can.  Externally dependencies are more subject to code rot. AFT still runs (on almost any Perl distro)  in part due to lack of dependencies on libraries that may be "abandoned" or improperly upgraded (to kill backward compatibility with older Perl distros).

But, I digress....

This entry is just my way of committing myself to a Perl 6 learning effort:

I have written 2 Mumble compatible chat/VoIP servers: One in Erlang and one in Lua(JIT). (I attempted one in Clojure but Java based networking made it nearly impossible to do sanely.)

I am now trying to see if Perl 6 is up to the task.

Stay tuned...

Wednesday, January 18, 2017

Crazy Complexity:The STM32L476

The STM32L476 very low power Cortex M4  costs $9 at Digikey.
This tiny MCU has, among other features, 128KB RAM, 1Mbyte Flash and
  • USB OTG 2.0 full-speed, LPM and BCD
  • 2x SAIs (serial audio interface)
  • 3x I2C FM+(1 Mbit/s), SMBus/PMBus
  • 6x USARTs (ISO 7816, LIN, IrDA, modem)
  • 3x SPIs (4x SPIs with the Quad SPI)
  • CAN (2.0B Active) and SDMMC interface


The reference manual is 1704 pages long.  
The reference manual is 1704 pages long.  
The reference manual is 1704 pages long.  

I work on this beast at my day job.