Case against single line if statements

… in curly bracket languages. I’ve always said – using single line ifs is dangerous, because a junior (or even a seasoned) developer might make a mistake and add an extra line of code which will not be executed in the if block.

I was watching this presentation of Kevlin Henney about Structured Programming – it talks that it’s good to use if and else if and fast returns and gotos are bad. It has a lot of examples with single line (non-curly bracket wrapped) ifs, and then this Apple’s SSL goto bug came along.

Let’s look at this simple example:

if (someBoolVar)

Pretty simple – doSomething() is executed only if someBoolVar is true. Now say someone want’s to add another method call if someBoolVar is true:

if (someBoolVar)
    doSomethingElse(); // This executes whether someBoolVar is true or not

We have a logical error, that will blow up on run-time. A better solution would be to actually write a single line of if statement:

if (someBoolVar) doSomething();

At least that would prevent adding additional statements without adding scope block. But curly bracket languages have curly brackets that define scope block and my way is to always use them:

if (someBoolVar)

And when other developer adds it’s new method call it will actually work as expected:

if (someBoolVar)
    doSomethingElse(); // Executes only if someBoolVar == true

So my rules of thumb are:

  • Always use curly brackets in if (or any other control structure) to define subsequent statements;
  • If you must use single line if statement – use just single line;
  • Leave wrapped single if statements to Python, because adding another line won’t make things blow up.

Master’s degree in Computer Engineering

So, I finally did it, I’m graduating from university for the second time. The first time was 12 years ago when I got myself a master’s degree in Physical Chemistry, now it’s time to tie up some loose ends and get a degree in what I’ve been doing professionally for the past 14 years – Computer Engineering.

This time I’m so proud of my work in my master’s thesis that I’m willing to share it in public, so here it goes:


In today’s live music performance a computer has become one of the music instruments on stage, but unfortunately it might become a cumbersome factor because of it’s universal nature. As an alternative this thesis researches processor architecture and operating system combinations for running virtual music instrument and virtual sound effects applications on specially developed embedded hardware for live music performances.

The research was done on two different devices with programs running on Linux operating system and directly on processor (bare metal). The main criteria for the research were – the ease of use of development tools, processor performance of floating point calculations and power consumption with an aim to use the device with battery power.

Conclusions were drawn that with today’s relatively cheap embedded hardware devices it’s possible to run virtual music instrument software, these devices boot up fast enough and they can perform long enough on battery power to use them for live performances on stage.


And finally…

So where to next? If that would be possible, I’d look into opportunity to wire a joint doctor’s thesis in chemistry and computer engineering, but we’ll see …

Analog Devices CrossCore Embedded Studio on macOS using Lubuntu

Continuing from my previous how-to post, today I’d like to show you how to develop on Analog Devices hardware using CrossCore Embeded Studio on macOS. As it is with most of these types of sofware – they run on Windows and sometimes (if you’re lucky) they’ll have a Linux version. In my case I wasn’t 100% lucky, as the Linux version does not run quite perfectly on virtual machine.


  1. VirtualBox
  2. Lubuntu LiveCD
  3. Analog Devices CrossCore Embedded Studio (this one you can download inside the virtual machine)
  4. Windows virtual machine (I used one downloaded from

Prepare virtual machine

After installing the VirtualBox and downloading Lubuntu LiveCD, go and create a new virtual machine with at least 40GB of disk space (you’ll actually need less than that, but it’s always safe to have some legroom).

Mount the LiveCD and install the bare minimum Lubuntu with GUI. After installing the Lubuntu, open the web browser inside it and download CrossCore Embedded Studio.

Installing CCES

Installing CCES is pretty straight forward, just install the deb package using:

cd ~/Downloads/
sudo dpkg -i adi-CrossCoreEmbeddedStudio-linux-x86-2.8.3.deb

It will be installed under /opt/analog/cces/2.8.3/.

Unfortunatelly CCES is based on Eclipse (requires Java) and is 32-bit only, so you’ll have to install a few more dependencies by hand to make it work:

sudo apt install lib32z1 lib32stdc++6 lib32ncurses5 openjdk-8-jre:i386 libswt-gtk-3-java:i386

Now you can run the CCES by running:


Installing license

This is the tricky part – unfortunatelly CCES can’t install license on Lubuntu – it fails with error “validation code has expired” even after entering a valid serial and all the registration data. It also can’t do the e-mail validation and effectivelly won’t add your serial number to license manager. Don’t worry – I found a workaround – use Windows. Bare with me…

You’ll need to do following:

  1. Download Windows on a VirtualBox disk image (I used for that purpose with Windows 10 disk image)
  2. Before launching the image change it’s network adapter’s MAC address to match the one used in Lubuntu (Go to Settings -> Network -> Advanced) as CCES uses MAC address to tie the activation to your computer.
  3. Launch Windows, install CCES, activate CCES using your serial number.
  4. Now you’ll have to copy the license.dat file from C:\ProgramData\Analog Devices\CrossCore Embedded Studio\license.dat to your Lubuntu ~/.analog/cces/license.dat – easiest way is to copy it through shared clip-board, because license.dat is just a text file. Just mind that on Windows it has CRLF line endings whereas on Linux it’s LF only.
  5. Get rid of Windows.

Use CrossCore Embedded Studio

When all that is done, you’re ready to write your DSP stuff on a macOS in a virtual Linux, just pass throuh [the device] to the guest machine (Go to Devices -> USB -> [device]) and you’re good to go.

Xilinx ISE WebPACK 14.7 on macOS using Lubuntu

Xilinx does not provide official installation of their FPGA IDEs for macOS, but there’s a nice way around – by using a Linux running on virtual machine. There’s an older how-to for Ubuntu, but I prefer to keep it light weight and went for Lubuntu instead.


  1. VirtualBox
  2. Lubuntu LiveCD
  3. Xilinx ISE WebPACK 14.7 (this one you can download inside the virtual machine)

Prepare virtual machine

After installing the VirtualBox and downloading Lubuntu LiveCD, go and create a new virtual machine with at least 40GB of disk space (you’ll actually need less than that, but ISE download is huge and the same is the installed version – you’ll need some legroom).

Mount the LiveCD and install the bare minimum Lubuntu with GUI. After installing the Lubuntu, open the web browser inside it and download ISE WebPACK installer.

Installing ISE is pretty straight forward, just extract the archive and run these commands in terminal:

cd ~/Downloads/Xilinx_ISE_DS_Lin_14.7_1015_1/

When installing choose WebPACK version and uncheck “Install cable drivers” as that will fail (we’ll build the driver in the next step). After the installation is finished I’d suggest you add Xilinx bin path to PATH in your ~/.bashrc file:

export PATH=$PATH:/path/to/Xilinx/14.7/ISE_DS/ISE/bin/lin64

You’ll also need to get a license file from Xilinx support site and add it’s path to environment (in the same ~/.bashrc file) as this:

export XILINXD_LICENSE_FILE=/path/to/Xilinx.lic

Build the driver

You’ll need to install a few packages using APT:

sudo apt install git libusb-dev build-essential libc6-dev fxload

Now clone the usb driver from a GIT repo:

cd /path/to/Xilinx
sudo git clone git://

Build the driver:

cd usb-driver/
sudo make

Set up the driver and restart the udev:

./setup_pcusb /path/to/Xilinx/14.7/ISE_DS/ISE/
/etc/init.d/udev restart

And add the dirver path as a pre-load variable in ~/.bashrc:

export LD_PRELOAD=/path/to/Xilinx/usb-driver/

And you’re set, now if you’ve set up everything as I’ve said, type ise in the terminal and it should open up ISE WebPACK.


Don’t forget to pass the Xilinx device to Lubuntu from macOS in VirtualBox Devices -> USB menu.

Here are some screenshots of macOS High Sierra running Lubuntu running ISE WebPACK 14.7:

Latvian locale for Mac OS X

This is going to be a tiny post. So I came across the problem that OS X does not have any lv_LV locales, it has Lithuanian (lt_LT), but no Latvian. So I did what any developer would do – I created my own and also released it on GitHub.

OS X: an unfinished bussines

It’s been a while since I’ve posted something larger than a tweet. A lot has changed since…

So I’ve got a Mac – after 18 years of PC I’ve finally returned to the wonderful world of Apple – It has changed a lot since the last time I was there (it was Mac OS 7 & 8 back then). It’s changed to something really good – and I can agree with everyone who has switched to OS X, that it just works. All the preinstalled apps, like iMovie, Pages, Mail and Maps – they are a great set of products made to be useful from the very first boot.

Continue reading “OS X: an unfinished bussines”

Restart/Reiterate Everything. Voila the Long Mode!

It’s been a month – pretty long vacation away from my most beloved hobby, but I’m just a human, I have my needs. I like snowboarding, so I went to Austria and did a proper powder riding. I’m still playing in the band, and I did a few gigs here in Riga. And last but not least – I have a job – and deadlines are killing me. But enough of appologies, here it is…

Continue reading “Restart/Reiterate Everything. Voila the Long Mode!”