Golang: Polymorphism

Polymorphism is a bit different in Go. A function’s parameters must accept an interface. If it accepts a concrete type, then you will not be able to pass anything other than what you are asking for. To help you understand better, here is an example:

However, Polymorphism doesn’t work when driveACar(lammborgini) would not work if Car was a struct and not an interface. Here is an example:

Don’t waste time

A friend of mine sent me an interesting quote by Imam Ghazali which puts things in perspective.

Your time should not be without any structure, such that you occupy yourself arbitrarily with whatever comes along.
Rather, you must take account of yourself and order your worship during the day and the night, assigning to each period of time an activity that must not be neglected nor replaced by another activity.
By this ordering of time, the blessing in time will show itself. A person who leaves himself without a plan as animals do, not knowing what he is to do at any given moment, will spend most of his time fruitlessly.
Your time is your life, and your life is your capital: by it you make your trade, and by it you will reach the eternal bounties in the proximity of Allah.
Every single breath of yours is a priceless jewel, because it is irreplaceable; once it is gone, there is no return for it.
So do not be like fools who rejoice each day as their wealth increases while their lives decrease. What good is there in wealth that increases while one’s lifespan decreases?
Do not rejoice except in an increase of knowledge or an increase of good works.
Truly they are your two friends who will accompany you in your grave, when your spouse, your wealth, your children, and your friends will remain behind.
— Imam al-Ghazali

Go: Declaring and using objects

Go (or Golang) doesn’t have the concept of classes. The class equivalent in Go loos like this:

The above declaration can now be used as an object like so:

First impressions of Go

I have been in search for a language I can use for web programming, writing computationally intensive and general scripting among other things. The language that came close to fitting all of these things was Racket, a dialect of Chicken Lisp. It can even do geometry drawings. However, there were issues with it so I ended up concluding it wasn’t that language in was in search of.

I started learning Go some time ago and, at first, found its syntax backwards. Declaring types after variable names was hard to get used to. And, the syntax for writing “classes” is even more weird. However, when I found out that Go supported concurrency (and parallelism) natively, I was intrigued. On a side note: default Python and Ruby interpreters do not support parallelism. PHP has some support through pthreads but using it could mean you not being able to use other extensions.

If you want to have a true parallel app in Ruby or Python you have to get the interpreter that runs on JVM. So, you Ruby code is run by the Ruby interpreter which is running on JVM. Ruby and Python support concurrency but their threads run one at a time. So, no parallelism.

Once you get past the syntax weirdness, Go is actually a pretty cool language. It makes it easy to write concurrent apps. They call them “go routines”. From what I have learned, go routines are cheaper to create and maintain than normal threads and the way Go is designed, it is very easy to communicate between threads (using channels). And, all of this makes sense since one of the goals of Go was to make multi-threaded network applications.

Those used to dynamic languages might find it a bit difficult to work with Go in the beginning as it is strongly typed. I was, however, able to adjust pretty easily (then again I have done C++, Java and C# in the past). Your mileage may vary but I highly recommend trying it out. You might like it.

Programming Macros for Ergodox

The default configuration tool on Input Club or Massdrop don’t allow for macro programming. So you will have to get your hands dirty and mess with the firmware code a little. It’s not hard.

  1. Run the following commands on your terminal to clone Ben Blazak’s firmware code from github and create a custom layout for yourself

  2. Open keyboard/ergodox/options.mk and add qwerty–custom to the KEYBOARD_LAYOUTS and change the KEYBOARD_LAYOUT to qwerty–custom. The keyboard layout will look something like this :

  3. Edit keyboard/ergodox/layout/fragments/macros.part.h and create a function for your macro. As an example, we will do a macro that prints b4.

  4. Now that the macro is ready, it can be placed in the layout. Put m_b4 for whichever key you want the macro to trigger. Edit firmware/keyboard/ergodox/layouts/qwerty–custom.c and put your macro in it.

  5. In the terminal, run make It will create firmware.hex
    Upload the file to Ergodox and your macro will be ready for use.

You can look up the hex codes for keys here: http://www.usb.org/developers/hidpage/Hut1_12v2.pdf

What should I learn?

This is a question I get asked a lot. Mostly by those who are just starting off their career as programmers/developers, but often times also by veterans of IT field.

Recently, I found myself asking that question when I came to the realization that PHP, as a language was not as much in demand as it once was. Not that I didn’t know this before but it became more apparent when I moved away from New York. With hundreds of companies and their office, it was never hard for me to find a job with great pay. Now, not so much.

With new technologies emerging faster than a New York minute how do you keep yourself relevant and keep moving up that corporate/salary ladder? A big part of that is knowing which technologies are in demand and being able to predict if they will stay in demand long enough for you to never run out of work.

After some experimentation (and a lot of help from God), these are the things that helped me realize where the market is going and what I need to learn next.

  1. Search the job sites
    Check out various job listing sites (monster.com, dice.com, etc) and search for jobs of all the technologies you are interested in and take a note of how many jobs are available and what their salaries are.

    If you are planning to move soon, then perform this search for the city you are going to move to (or thinking of moving to).

  2. Talk to recruiters
    The first time I heard big data was increasing in demand is when a recruiter mentioned it to me. She also told me PHP was becoming more of a niche skill than a mainstream skill. So, I decided to learn Ruby. I have always been fascinated by the meta-programming capabilities of Ruby.

    However, I came across an article published by Stack Overflow which showed Ruby was even less (much less) popular than PHP. I haven’t stopped learning it though. It’s a fun language and I want to explore it more.

  3. Go to startup meetups and see which technology stack is being used

    A few years ago, Python was the popular kid on the block. All the cool kids (new startups) were using it. If you told someone, your new project was not in Python or Node, you were looked down upon (I wish I was exaggerating).

    The only reason I found this out was because I noticed that at networking events, most new companies were using Python and Mongo.

  4. Other Thoughts

    These three things help you get a general idea of what you should learn next. However, there other things you should take into consideration. What is the most important thing you want your employer or your job to have? If you like working 9-5 then find out what big companies are asking for. If you like the startup culture, then find out what they want.

    Sometimes, you don’t know what you want until you have gone through a few jobs. When I started by career as a developer, my first few jobs were great. I was part of planning process for projects and it opened my mind to all the possibilities. I enjoyed that a lot. I felt intellectually challenged and learned a great deal.

    Later on, one of the jobs I got was at a firm where my manager expected his team to be robots. On top of that he micro-managed everything. I hated it. I didn’t like being micro-managed. Some people prefer it. Some developers are okay with vague requirements, some get paralyzed by them. In an ideal world we would have clear cut business requirements, but depending on where you work, that is often not the case. You need to figure out what you want and then narrow down your search based on that criteria.

    Currently the popular technologies seem to be: NodeJS, AngularJS, React, Big Data (data analysis, machine learning, etc). I think the reason for this is that quite a few new companies are being founded and investors (as well as business owners) need to know if the business plan will work and how to make it work. Javascript is is supported outside the browser, (applications like Mirth let you write code in JS for custom rules) which has added to its popularity.

    Java will always be in demand in the financial sector. You can never go wrong with learning C/C++. As long as computers are in use, C/C++ will be in demand.

    I hope this helps others are out who confused about their next step. Please feel free to contact me, if you have anything else that might be helpful. Below are some useful links:

    http://stackoverflow.com/research/developer-survey-2016 (a great resource)
    http://monster.com
    http://dice.com
    http://glassdoor.com
    http://indeed.com
    http://careers.stackoverflow.com

Clean your oil painting brushes the non-toxic way

Oxyclean stain remover is your friend. Wipe your brushes with a paper tower, then spray some Oxyclean into the bristles, leave it for a few seconds and wash them. You may need to use more than once on a brush but it will clean the brush and leave no color stains ( at least not as much as Gamsol + soap and water ).

I have heard some artists like to use baby oil to clean their brushes and they say you need a lot of it. I haven’t tried this method

Another cleaner that works great is Fast Orange hand cleaner. It is a bit thick and has pumice in it so I don’t use it for brushes as much. You have to make sure you get all the pumice out after you are done cleaning. Also I have had to use quite a bit of it on brushes.

Fast Orange cleaner is amazing for your hands. It will clean them better than regular soap and water. Also, you can use it as a facial or body scrub.

Notice how new brushes need to be broken in before painting. The bristles are stuck together and you need to brush them lightly on you hand to get them to part. You can get that with milk. After cleaning the brushes, take a few drops of milk and shape the brush. Next time you reach for it to paint, it will feel like you are painting with a new brush.

Is Zephir worth learning?

Not so short answer: If you want to learn something that makes you more marketable, then no. It is better to learn C++ instead. If you just want to play with it, maybe write an extension or two for your project, then Zephir is fun language to learn.

I checked for jobs dice.com and other popular job sites and I found 10 jobs on all of them combined. This is 10 jobs for both Zephir and Phalcon combined (searched separately). There are no popular websites I know of, that use Phalcon. There are some Russian and Polish websites that use it and I don’t know how popular they are but none that I have seen in the US.

Phalcon is the fastest framework but it hasn’t been widely adopted. In fact, I don’t know of any site, or web app that uses it. For those that don’t know: Phalcon (a PHP framework installed as any other PHP extension) is written in Zephir.

At first, I thought the lack of adoption of Phalcon (or Zephir) was because it lacks a wide variety of features (data mapper pattern being one of them). While that is true, that is not the only reason for it. Most websites (or web applications) run on shared hosting. They don’t have the ability to install custom extensions. So, unless the web hosting provider already has Phalcon installed, you are out of luck. This reduces Phalcon’s demographic by a significant percentage.

I think Zephir’s usage is directly proportional to Phalcon’s usage. As far as I can tell, it doesn’t seem very promising. One day when PHP let’s you install extensions like we install libraries through composer, it will have a better chance. For the near future, however, there are few to no job prospects for it.

Zephir (like its makers point out) is not a general purpose programming language. It was made for a very specific purpose of developing Phalcon and overcoming the adoption barrier. It is a bit limiting and expressing complex problems in it can be difficult. However, if you can get the hang of it, I think it is worth checking out.

On a side note: there is an app that converts your code to C++, making it compilable. It is called Swig and can be found here: http://www.swig.org”

A second look at Zephir

Ever since I found out about Zephir, I have been very curious about it. I mean compiled PHP code. How awesome is that? Also, Zephir code doesn’t have to be compiled into a PHP extension. You can just convert it to binary and run it normally like any other PHP code.

Why spend a lot on Zend Guard or any other encoding software when you can do it for free with Zephir? There is a caveat though: Zephir is not PHP. It has similarities but it is not completely PHP code. So, you would have to learn whqt works and what doesn’t.

One thing to note is that it is still in beta. Phalcon has been out for a while so I figured it would at least be 1.0.0 stable. However, that is not the case. At the time of writing this article, the latest version is 0.9.8b. I have always wanted to write code as PHP extension so it would run much faster than regular PHP code.

I read (haven’t benchmarked yet) that not all compiled Zephir code runs faster than regular PHP code. This is probably because of some I/O bottlenecks. If you are planning on using Zephir, make sure you benchmark the performance for your use case. If compiling doesn’t make things any faster then its not worth the extra pain to compile and install a PHP extension.

Macports Ruby: Symbol not found: _SSLv2_client_method error

This error usually shows up when you try to run the following command:

For those that don’t know what I am talking about, this is the error message:

The only way to get this to go away is to re-compile ruby so it will use the new openSSL library. Macports, however, installs packages from binaries. So, after hours of trial and error, I found a way to get around this. You can re-install ruby with the following command and the error message will go away:

You will have to replace ruby23 with whatever version you want to install.