Why do I recommend learning C++?

This post is just my ramblings about why I recommend you learn C++ even in 2018:

(1) C++ is a system programming language, and the program implemented in C++ is compiled into machine instructions. IMHO, every genuine software engineer should be acquainted with Operating System, hardware architecture, etc, and learning C++ can give you the opportunity to dive into these stuff. E.g., when you come across the “memory order”, you need to google a lot to really understand it, but it is indeed rewarding.

(2) C++ is actively evolving (C++03, C++11, C++14, C++17 …). Before C++ 11, i.e., modern C++, the main selling point of C++ is object-oriented and powerful template. But after that, C++introduces a lot features, and it becomes more and more complicated. E.g., the code may has different behaviors between C++14 and C++17 (please refer here) . Why do we bother to learn it since it is so intricate? Personally, I think it will give us a huge confidence: if you can harness C++ proficiently, is there any other language you can’t master?

(3) Because C++ is an old but popular language, there are fruitful resource which others can’t compete. From Open Source code to classical books, you can have so many references to help polishing your code skills. BTW, reading some works is a really enjoyment, not only assist you improve programming, but also teach how to write a good essay.

Hope this small article can let you take into learning C++ when you are free!

First taste of newLISP

Occasionally, I bumped into newLISP through the following twitter:

Capture

What attracted me is the newLISP‘s small size and fruitful APIs. Because I am fascinated with functional programming now, I decide to stop to peek at newLISP.

I never get my feet wet on Lisp/Scheme before, so I can’t compare the difference between them and newLISP. As an absolute novice, the key point to master newLISP I think is to be accustomed to parentheses. By default, the first element in parentheses should be a function, like this:

> (println "Hello" " World!")
Hello World!

Or this:

> (+ 4 8)
12

So if you just want a literal, remember to use ':

> '(println "Hello" " World!")
(println "Hello" " World!")

Once you remember this rule, you can understand the newLISP‘s program structure easily. Then the next thing is make your hands dirty, leverage the APIS, lego bricks provided by newLISP to practice writing small programs. For example, it cost me only a quarter to write abase64 encoder/decoder.

Happy hacking newLISP!

Add CC&CXX environment variables in your OpenBSD profile

From OpenBSD 6.2, clang has become the default compiler. So maybe you need to add CC&CXX environment variables in your personal.profile:

export CC=clang
export CXX=clang++

That’s because some software will select gcc as the compiler if you don’t specify these environment variables. The gcc is too old (4.2.1) and not maintained on OpenBSD anymore.

Beware “No such file or directory” error in using ksh

Check following simple script:

#!/usr/bbin/python
print("hello world!")

I misspelled python path intentionally. On Linux Bash, it reported following error:

$ ./hello.py
-bash: ./hello.py: /usr/bbin/python: bad interpreter: No such file or directory

It prompted me that “/usr/bbin/python” couldn’t be found. While on OpenBSD ksh:

$ ./hello.py
ksh: ./hello.py: No such file or directory

It gave an illusion that hello.py didn’t exist. So be careful about this error information if you use ksh.

Symmetric/Asymmetric cryptography in one minute

Modern cryptography is composed of two flavors: symmetric & asymmetric.

In symmetric cryptography, there is only one key that is used in both encryption/decryption. It is also called shared-key cryptography.

While in asymmetric cryptography, there is a key-pair, i.e., a public key and a private key, so it is also named as public-key cryptography. The ciphertext which is encrypted by public key can only be decrypted by private key and vice versa. Generally, as the name indicates, public key is accessed by every one, while private key only you can access . When someone wants to send you confidential message, he/she encrypts the information using public key and only you can use private key to decrypt it. For the same reason, you can use private key to make a digital signature and every one can use public key to make sure it is indeed you publish.

Although asymmetric cryptography is more safer than symmetric, but symmetric is more faster. Nowadays, there is usually a hybrid solution, which is for the content, it is encrypted using symmetric cryptography, while for the key transfer, using asymmetric cryptography. This method can leverage the advantages of both methods.