2016-06-19

Flowchart to choose your programming language

Just now, I found a cool site to generate flowchart from source code (just like dot program):

(click for larger picture)

Anyway this just a joke, just like before (if programming language were religion/woman), may odds be in your favor..

Btw here's the code if you want to modify.. please use http://pastie.org if you want to do a long comment containing source code..

Choosing Programming language flowchart;
if(I really really care 
about runtime performance) {
  if(I am masochist..) {
    if(I like Mozilla..) {
      Use Rust;rust-lang.org
    } else {
      Use C++;cplusplus.com
    }
  } else if(I don't want 
  to learn something new..) {
    Use C;cprogramming.com
  } else if(I like long lines..) {
    Use Java;java.com
  } else if(I like FP?) {
    if(But I'm not masochist..) {
      Use Scala;scala-lang.org;
    } else if(I like parentheses..) {
      Use Clojure;clojure.org
    } else if(I like Microsoft) {
      Use FSharp;fsharp.org;
    } else {
      Use Haskell;haskell.org;
    }
  } else { 
    if(I like Microsoft..) {
      if(I hate C++) {
        if(My computer is ancient..) {
          Use VB6;
        } else {
          Use VB.NET;
        } 
        vbforums.com;
      } else {
        Use CSharp;csharp-station.com;
      }
    } else if(I like Facebook..) {
      Use Hack;hacklang.org;
    } else if(I like Apple..) {
      if(I'm a bit masochist..) {
        Use Objective-C;developer.apple.com;
      } else {
        Use Swift;swift-lang.org;
      }
    } else if(I like Google..) {
      if(But I also like java 
      and javascript..) {
        Use Dart;dartlang.org;
      } else { 
        Use Go;golang.org;
      }
    } else {
      // you can also use Lazarus
      // lazarus.freepascal.org
      Use Delphi;embarcadero.com;
    }
  } 
} else {
  if(I don't want to install a thing..) {
    if(I use linux, mac, or win 10) {
      Use Bash;bash-hackers.org;
    } else {
      Use Javascript;javascript.com;
    }
  } else if(I love spaghetti..) {
    if(I don't care about my future..) {
      // Most likely you will be killed by maintainer that reads your code..
      Use Perl;perl.org;
    } else {
      Use PHP;php.net;
    }
  } else if(I want to make game mods..) {
    Use Lua;lua.org;
  } else if(I like indentations..) {
    Use Python;python.org;
  } else {
    Use Ruby;ruby-lang.org;
  }
}

Aww snaps, I forgot to add Elixir, Julia, and Crystal  -_- oh well.. maybe sometime in the future.

2016-06-11

EasyEngine: WordPress made easy

So, newbies out there, for those that have a root server access or VPS, and you want to create a blog. There is a tool called EasyEngine that could help you (automate) setup Nginx (not Apache), PHP (or PHP7/HHVM), MariaDB/MySQL database, Postfix mail transfer agent, WordPress, WP Super Cache (or W3 Total Cache, Nginx Cache, WP Redis) on Ubuntu or Debian operating system.

There's a lot more it can offer:

How to install EasyEngine?

wget -qO ee rt.cx/ee && sudo bash ee

What's we must use this? it saves time (automated install, automatic update), best practice (Nginx instead of Apache, HHVM/PHP7 instead of PHP5, caching), configuration backup (using Git)


For more information you can visit their website https://easyengine.io/

But wait kiz, you hate PHP right? why you endorse this?
at least this IS far better than poor performance/neglected/insecure/lousy crap configuration/choice that I always see in the past.

2016-06-05

Go is Programming Language for The Future

Well, I like Go so much, Here's some reason why Go is the language for the future:

1. low learning curve. syntax similar to C, but it's simplified, high readability, standardized code-formatting, almost no syntax changes from older version to newer version, has compact language specification for whole language (only 79 A4 pages) compared to:
2. it performs near equal to Java
3. fast compile, especially for big project

4. concurrency at language level, it's no doubt that concurrency is the trend (processor manufacturer now tend to adding more cores)

5. garbage collected, safe-pointer, contrast to manual memory management that can lead to buggy code (eg. memory leaks, buffer overflow attacks)

6. built-in utf8 string and maps (associative array), as other newer programming language also done (the Go programming language creator also the one that wrote utf8)

7. big company support (Google), other companies that have been using Go: Dropbox, Twitter, SoundCloud, etc, this leads to future job vacancy.


8. small memory footprint (unlike Java, that everything has 8-12 bytes overhead)

9. built-in package management, it's easy to distribute libraries, leads to many contribution.

10. simple cross compilation

11. autocomplete daemon, this leads to many editor/IDE support

12. built-in testing support (for TDD/BDD)

There's many other things that I personally like from Go:
  • variable initial value always zeroed
  • limited set of operator (no frustration when other people use too many operator with confusing precedence)
  • no generics XD yes, I found C++'s template error message really painful, but templates are quite useful when writing generic data structures
  • letter case visibility
  • no function overloading
  • statically linked
  • no circular dependency
  • no warnings, just errors
I bet Go will become really popular in 2020 (at least until full-featured Swift comes to Linux and Windows). Hopefully there would be Go that compiles to WebAssembly :3



Real Reason to use newer Go 1.5+: Cross Compile

As you already know, that compiling in Golang becomes slower since 1.5+, then why we must use the newer? there's no incompatible syntax changes right? See the graph below for the compile duration ratio:


There's some you must consider when using older Go version (<1.4.3):
  1. Broken libraries, some libraries (such as fasthttp) doesn't support older version of Go (<1.5), because there are changes on standard libraries, for example there's no bytes.LastIndexByte, bufio.Reader.Discard,  time.Time.AppendFormat, etc on older version of go standard library)
  2. Slower GC (see Go 1.6 latest low latency garbage collector, it's even less than 21ms)
  3. Bigger binary produced (but see goupx)
  4. Slower runtime performance (but it's already fast compared to another language)
  5. No Vendoring (see no more dependency hell)
  6. And lastly, no Cross Compiling!
Did you know that since Go 1.5 you can build other platform's binary?

$ go build
-rwxr-xr-x   1 asd  staff  11261296 Jun  5 19:41 PUPS
PUPS: Mach-O 64-bit executable x86_64

$ env GOOS=linux GOARCH=amd64 go build
-rwxr-xr-x   1 asd  staff  9232191 Jun  5 19:42 PUPS
PUPS: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, not stripped

$ env GOOS=windows GOARCH=386 go build
-rwxr-xr-x   1 asd  staff  8048640 Jun  5 19:42 PUPS.exe
PUPS.exe: PE32 executable for MS Windows (console) Intel 80386 32-bit

This feature is really useful especially when your server is Linux, but you develop in Mac :3
Or when you want to create a cross-platform games/apps.

Solution for golang Slow Compile

I think this need more exposure, http://dev.pawelsz.eu/2015/09/slow-go-compilation.html show that slow compilation source, by using -x flag. This also related to my previous answer on stackoverflow http://stackoverflow.com/a/26752149/1620210 a real slowdown that happened after upgrading or downgrading to newer version of golang. Fortunately, there's a quickfix for that:

First of all if you are using go 1.7, you'll need to change the ownership of your GOROOT's pkg directory:

[ `ls -ld $GOROOT/pkg | awk '{print $3}'` != `whoami` ] && sudo chown -Rv `whoami` $GOROOT/pkg

Then if you are upgrading or downgrading, you'll need to remove the GOPATH's pkg directory, there's the bash snippet to check if gitlab.com/kokizzu/gokil library was precompiled with different golang version than installed:

PKG_OS_ARCH=`go version | cut -d ' ' -f 4 | tr '/' '_'`
[ `strings $GOPATH/pkg/$PKG_OS_ARCH/gitlab.com/kokizzu/gokil/A.a | grep 'go object' | head -n 1 | cut -f 5 -d ' '` != `go version | cut -f 3 -d ' '` ] && rm -rf $GOPATH/pkg

This last part stolen from the blog above, the real script that makes the next compile runs faster:

go list -f '{{.Deps}}' ./... | tr "[" " " | tr "]" " " | \
  xargs go list -f '{{if not .Standard}}{{.ImportPath}}{{end}}' | \
  xargs go install -a

Alternatively, you can use

go build -i

The last 2 commands above looks for all dependencies and recompile/preinstall them, it's better than I expected, normally it took about 15 seconds to recompile on go1.6.2.

# go 1.4.3
[gin] Build Successful in 1802.47 ms
[gin] Build Successful in 2854.65 ms
[gin] Build Successful in 2325.35 ms

# go 1.6.2
[gin] Build Successful in 5673.43 ms
[gin] Build Successful in 8081.75 ms
[gin] Build Successful in 6867.12 ms

# go 1.7b1
[gin] Build Successful in 2579.98 ms
[gin] Build Successful in 3649.08 ms
[gin] Build Successful in 4182.04 ms
[gin] Build Successful in 3881.66 ms
[gin] Build Successful in 3722.20 ms
[gin] Build Successful in 2785.84 ms
[gin] Build Successful in 2981.62 ms
[gin] Build Successful in 3793.66 ms
[gin] Build Successful in 4458.86 ms
[gin] Build Successful in 4376.60 ms

Anyway I still stick with go1.4.3 since it has the fastest compile, it makes our edit-compile-test cycle faster.