Showing posts with label swift. Show all posts
Showing posts with label swift. Show all posts

This Week I Learned - 2016 Week 01

In case you miss out, last week post.

#1 Flowgorithm: Flowchart Programming IDE. Creating application using simple flowcharts, yet another level of abstraction for coding. Screenshots, step-by-step tutorial, and file format. Similar flowchart-based programming environment tools are RAPTOR, Visual Logic, and LARP. Unfortunately Windows only (should try with Wine). Flowgorithm is written in C# and most probably can run in GNU/Linux since .NET Compiler Platform ("Roslyn"), the compiler for C# and Visual Basic has been open-sourced. If there any tools to do the reverse or something like Visualize Python which let us visualize the flow from the source code instead? Well all the mentioned tools catered for educational purpose, is there anything similar for the industry like those for Model-driven engineering?

#2 How to think visually or rather, which visualization diagram should I use? Which reminds me of another visual decision tool, the chart chooser and slide chooser by Andrew Abela and Paul Radich. I always interested with visualization tools as it's a form of storytelling with data. I've been exploring different chart tools these days to plot my daily walking steps.

#3 Dummy output sound adapter in Ubuntu? Nothing but a force restart (pulseaudio -k) of PulseAudio sound server can't solve. It has been so long since I last encountered any sound card issue in GNU/Linux. I still remember many years back I tried, for weeks, to get my sound card to workonly to realize that I picked the wrong driver for the Linux kernel. Although the is a Yamaha sound card, the driver only works with the chipset, if I remember correctly, Cirrus Logic.

#4 DNS Conformance Suite and Test Harness. Conformance or to be exact, conformance testing, "is testing to determine whether a product or system or just a medium complies with the requirements of a specification, contract or regulation". Enormous list of Request for Comments (RFC) just to make sure that the DNS implementation conformance to the standards. Standardization is always tricky where so many parties involved and each with their own agenda which sometimes, slow down the the adoption of the certain standards. Case in point, Hyper Text Markup Language (HTML).

#5 Software Testing Techniques. Class Report for 17-939A (PDF) by Annie Lu Luo. Comprehensive literature review of software testing techniques. So far, the best paper I read in 2016. How I wish all the software engineering papers were written in such way. Again, this remind me of Ke-Sen Huang's resource for computer graphic page. Unfortunately my lack of mathematics knowledge and patience prevent me from fully understand most of these papers. Nevertheless, you can appreciate the beautifully generated images of these computer graphic research papers. And off course, there is this Papers We Love, where a group of people who love to read academic computer science papers. Unfortunately, as usual, there is still MY chapter and judging by all the past meetups, its existence will not sustain for long.

#6 Books Scientists Should Read Before The Age of 20. Some books are questionable but nevertheless, a good starting list. Personally, I will like to start with George PĆ³lya's How to Solve It: A New Aspect of Mathematical Method. If you're short of time, here is the summary of his method.

#7 100 Days of Swift. Progression notes on learning Swift programming language. Compare to other self-learner, he managed to create interesting UI related small projects just by applying a few concepts. Something that anyone should try out when picking up new programming language.

#8 Write code every day? Not necessary, as fellow redditor, EarLil advised that just "follow your rhythm and stay healthy" (make sense but which rhythm?) or you can just switch between coding and writing, "code doesn't have to be code". Github commit heatmap is a good motivator to encourage you to make an effort to write or code something, even one-liner. The question remains? How long should you allocate time in a day so that it will get you started and won't burn you out? For me, one line of record or code, or a sentence. Something so easy that you don't have any mental excuses not to do it. Getting started is always the hardest. But once you've started, everything else will fall into places. Just start!

#9 Valuing time over money is associated with greater happiness. First empirical evidence that people who value time over money are more happier. This reminds me of the personal finance book, Your Money or Your Life, where the authors asked "how much that we have trade our hourly life energy for money?". Once you realize that the actual amount of cost, time, and effort spent just to earn an hourly wage, you will have a change of opinion regarding your career and the money you earned..

Swift in Fedora 24 (Rawhide)

Swift, the language developed by Apple, which is set to replace Objective-C, was recently open sourced. However, the existing binary only available for Ubuntu and Mac OS. Hence, for Fedora user like myself, the only option is to install it through source code compilation.

First, install all the necessary packages.
$ sudo dnf install git cmake ninja-build clang uuid-devel libuuid-devel libicu-devel libbsd-devel libbsd-devel libedit-devel libxml2-devel libsqlite3-devel swig python-devel ncurses-devel pkgconfig

Next, create our working folder.
$ mkdir swift-lang

Clone the minimum repositories to build Swift.
$ git clone https://github.com/apple/swift.git swift
$ git clone https://github.com/apple/swift-clang.git clang
$ git clone https://github.com/apple/swift-cmark.git cmark
$ git clone https://github.com/apple/swift-llvm.git llvm

If you have slow internet connection and experiencing disconnection during clone, is best to clone partially. Otherwise, you've to restart from the beginning again.
$ git clone --depth 1 https://github.com/apple/swift-llvm.git llvm
$ cd llvm
$ git fetch --unshallow

If you have the great Internet connection, you can proceed with the remaining repositories.
$ git clone https://github.com/apple/swift-lldb.git lldb
$ git clone https://github.com/apple/swift-llbuild.git llbuild
$ git clone https://github.com/apple/swift-package-manager.git swiftpm
$ git clone https://github.com/apple/swift-corelibs-xctest.git
$ git clone https://github.com/apple/swift-corelibs-foundation.git

As Swift was configured to work in Ubuntu or Debian, you may encounter error several issues during compilation. These are my workaround.

/usr/bin/which: no ninja in ...
In Fedora, Ninja Built binary name is 'ninja-build' but Swift builder script expect it to be 'ninja'. We create an alias to bypass that.
$ sudo ln -s /usr/bin/ninja-build /usr/bin/ninja

Missing ioctl.h
During compilation, the ioctl.h header file was not found as the build script assumed it's located in '/usr/include/x86_64-linux-gnu' as shown below.
header "/usr/include/x86_64-linux-gnu/sys/ioctl.h"

Temporary workaround is to symlink the folder that contains these files.
$ sudo mkdir -p /usr/include/x86_64-linux-gnu/
$ sudo ln -s /usr/include/sys/ /usr/include/x86_64-linux-gnu/sys

pod2man conversion failure
The 'pod2man' doesn't seems to convert the POD file to MAN page as illustrated in error message below.
FAILED: cd /home/hojimi/Projects/swift-lang/build/Ninja-ReleaseAssert/swift-linux-x86_64/docs/tools && /usr/bin/pod2man --section 1 --center Swift\ Documentation --release --name swift --stderr /home/hojimi/Projects/swift-lang/swift/docs/tools/swift.pod > /home/hojimi/Projects/swift-lang/build/Ninja-ReleaseAssert/swift-linux-x86_64/docs/tools/swift.1
Can't open swift: No such file or directory at /usr/bin/pod2man line 68.

Upon this error message, the 'swift.pod' file has been corrupted and emptied. You'll need to restore it back from the repository.
$ git checkout -- docs/tools/swift.pod

We need to disable the '--name swift' parameter. This is done by commenting out the 'MAN_FILE' variable.
$ sed -i 's/MAN_FILE/#MAN_FILE/g' swift/docs/tools/CMakeLists.txt

Once all the workarounds have been applied, we'll proceed with our compilation. You do not really need to set the '-j 4' parameter for parallel compilation which can really reduce compilation time. By default, Ninja Build will compile code using the available CPU cores. Also, we just want the release (-R) build without any debugging information attached.
$ ./swift/utils/build-script -R -j 4

Add our compiled binary path to the system path.
$ cd /build/Ninja-ReleaseAssert/swift-linux-x86_64/bin/
export PATH=$PATH:`pwd`

Lastly, check our compiled binary.
$ swift --version
Swift version 2.2-dev (LLVM 7bae82deaa, Clang 587b76f2f6, Swift 1171ed7081)
Target: x86_64-unknown-linux-gnu

Be warned, compilation took quite a while, maybe for several hours. This depends on your machine specification and the type of build. I've noticed my lappy was burning hot as four CPU cores were running at 100% most of the time. It's recommended during compilation, place your lappy near a fan or any place with good ventilation. See that the temperature exceed high threshold of 86.0°C.
$ sensors
acpitz-virtual-0
Adapter: Virtual device
temp1:        +95.0°C  (crit = +98.0°C)

thinkpad-isa-0000
Adapter: ISA adapter
fan1:        4510 RPM

coretemp-isa-0000
Adapter: ISA adapter
Physical id 0:  +97.0°C  (high = +86.0°C, crit = +100.0°C)
Core 0:         +94.0°C  (high = +86.0°C, crit = +100.0°C)
Core 1:         +97.0°C  (high = +86.0°C, crit = +100.0°C)

Under normal usage, the average temperature is roughly 50°C.
$ sensors
acpitz-virtual-0
Adapter: Virtual device
temp1:        +46.0°C  (crit = +98.0°C)

thinkpad-isa-0000
Adapter: ISA adapter
fan1:        3525 RPM

coretemp-isa-0000
Adapter: ISA adapter
Physical id 0:  +49.0°C  (high = +86.0°C, crit = +100.0°C)
Core 0:         +49.0°C  (high = +86.0°C, crit = +100.0°C)
Core 1:         +45.0°C  (high = +86.0°C, crit = +100.0°C)