Notes on MITx: 6.005.1x Software Construction in Java (Week 1)

Notes on MITx: 6.005.1x Software Construction in Java (Week 1)

MITx has released a course titled “Software Construction in Java”. The course is aimed for more experienced Developers and is going to teach a couple of general principles of Software Development.

The course has the goal that you develop good code, which is defined as:

  • Safe from bugs: Correct behavior of the code, now and in the future
  • Easy to understand: Code should be easily understandable by other developers
  • Ready for change: Architectural patterns that allow you to modify the code without major rewrites.

Over the next couple of weeks I will complete this course and will publish my notes and thoughts on the material.

You can also take the course at https://www.edx.org/course/software-construction-java-mitx-6-005-1x

Why am I taking this course?

I have worked with Java in the past. I do not prefer using the language. However in the Python course from MIT was fantastic and thought very interesting concepts that apply to all languages.

My hope is that this course will teach broader concepts and the language they are using just happens to be Java.

LEcture 1: OVerview + Static Typing

The first lecture i skipped most of the videos, they seemed more like an introduction to Javas static typing, which I was already familiar with.

Lecture 2: Code Review

The second lecture takes a look at good Coding Practices.

Code Review

Lecture notes:

The purpose of a code review has two main goals:

  • Improve the code
  • Improve the programmer

Personal notes:

In reality on many programming projects the “Code Review”- Phase is cut due to budget constraints, lack of time and personal feelings. Remember when you do a code review you may hurt the feeling of another programmer, who thinks he is infallible.

This usually causes that more and more bad code is written. Making the project not maintainable and unreliable.

If it is possible for your project to do Code Reviews, you defiantly should do them, and have a very specific action plan that the other developer can learn from his mistakes.

Style Standards

Lecture notes:

You can find good style guides at https://github.com/google/styleguide

Personal notes:

Every programmer has his personal style how he likes to format and read his code. All university classes (including this one) do not provide a style guide. With the consequence that also no style guide is enforced.

In larger projects this would not be possible. The version control systems suddenly cause problems, create merge conflicts etc.

Styleguides should never be manually enforced. That would be tedious and create a lot of unnecessary work. The guide should be enforced by your build process. This prevents programmers from using their own style guide, avoids merge issues, is easier to manage, and it is psychologically better for the programmer that the machine rejects code rather than another programmer.

The best practice would be that every code commit gets checked prior to be allowed into the repository. This ensures that every developer is playing by the same rules. (To find more information on this subject google for “git hooks” and “java checkstyle”)

Code Smells

  • Don’t Repeat Yourself (DRY)
  • Comments where needed
  • Fail fast
  • Avoid magic numbers
  • One purpose for each variable
  • Use good names
  • No global variables
  • Return results, don’t print them
  • Use whitespace for readability

Personal notes:

While the lecture presents various strategies to prevent the most common beginner mistakes. These are just a select few of all the various types of code smells.

I prefer to use the IDE IntelliJ, it has a feature called “Code Inspector”. It will scan your code and suggest fixes for a lot of types of code smells.

Good code should never have obvious code smells.

Homework

For the “Java Tutor” Homework assignments you must use an Eclipse Plugin.  So sadly you have to use Eclipse with a custom built plugin and as usual I have had a lot of fun with randomly crashing Eclipse, the plugin giving me over and over again the same questions.

The “Java Tutor” is overall quite weak. The questions are more like “fill in the blanks” and only accepts a single correct answer. Usually the titles of the links to the related materials give away the correct answer.

However if you enter the wrong value, you can simply click “Show Answer”, copy the solution and progress without penalty.

Posted by happyneal in Blog, Java, 0 comments
Elementary OS: Loki

Elementary OS: Loki

Elementary OS is a new Operating System that wants to be an alternative to Window or OSX. The team behind the project puts an high emphasis on Usability and Design.

Over the next couple of days I will try to actually switch to the system. Elementary is based on Ubuntu, which in turn is based on Debian, so all *.deb packages and programs can be installed without any problems. As with all Linux Distributions Elementary is free. However the developers require you to think about it if you would like to support their efforts or not. If not you enter a 0 into the download field.

For my initial setup I will essentially install all the common programs I use on a day to day basis. .

How To install Elementary.io

Step 1 Download the ISO

Go to www.elementary.io and download the current Version. If you have some money to spare you can donate to the project. If not enter a 0 and you can download the iso for free.

Step 2: Prepare a USB Stick

Go to https://rufus.akeo.ie/ and download the Rufus tool, this allows you to easily create a bootable USB stick.

Step 3: Install

Well for the last step you really just have to boot from the stick and follow the instructions.

First Steps

Remove Default Programs

The team focuses a lot on providing a suite of programs that also follow it’s design principles.

I would prefer to use Chrome as my Browser, and VideoLan for videos and I do not need an email client, or a dedicated calendar.  I removed them with these commands:

sudo apt remove pantheon-mail -y
sudo apt remove maya-calendar -y
sudo apt remove epiphany-browser -y
sudo apt remove audience -y

(The program “audience” is the default VideoPlayer)

Install General Programs

Chrome

Since Chrome has some Google stuff in it you first have to add it to apt with this command:

wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add -
sudo sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list'
sudo apt-get update
sudo apt-get install google-chrome-stable

VideoLan

To install VideoLan simply enter following command:

sudo apt-get install vlc -y

Skype

Microsoft has just recently announced that they will create a Skype Client for Linux. For now there is only the official “Skype for Linux Alpha”. Essentially the program is still barebones and is in very early stages of development. – If you install  it do not expect that everything will be working.


wget https://go.skype.com/skypeforlinux-64-alpha.deb
sudo dpkg -i skypeforlinux-64-alpha.deb

Shortcuts

⌘+Space App Launcher
Alt+Tab Window Switcher
⇧+Alt+Tab Switch Windows Backwards
⌘+Left/Right Switch Workspace
⌘+S Workspace Overview
Ctrl+⌘+Left/Right Snap Window to Half of Workspace
Ctrl+⌘+Up/Down Maximize/Unmaximize Window
⌘+T Terminal

Conclusion

The OS looks awesome, it feels like a system you actually could work with for a longer period of time. In the past I have always tried Linux for a couple of days and then said, well interesting, but a lot of my programs simply do not work and I would like to go back to Windows.

Let’s see how long this time the experiment is going to last and if Linux has become more user friendly over time.

Posted by happyneal in Blog, Linux, 0 comments
How to install Windows 10

How to install Windows 10

Preparation

You will need a USB-Drive with a minimum of 3GB free space.

Installation Files

Unlike previous versions of Windows, Microsoft has released a download tool.

  1. Download the tool from https://www.microsoft.com/en-us/software-download/windows10
  2. Attach the USB-Stick to your computer
  3. Start the tool and select your USB-Drive
  4. The tool will download the installation files and make the USB-Stick bootable.

Install Windows 10

Start your computer and boot from the USB-Drive

During Installation you should not use “Express Settings” but instead use “customize settings” and take a close look at the different options.

If you are upgrading a Windows 7 installation or Windows 10 has been previously installed on the computer Windows will not ask you for a Product-Key and does not need to be activated again.

Quick Program Setup

By using chocolatey you can quickly install most of the programs you need.

Install Chocolatey

  1. Open a cmd with Administrator Privilages (Windows Key > type “cmd” > Shift + Ctrl + Enter)
  2. Copy and Paste following script:
@powershell -NoProfile -ExecutionPolicy Bypass -Command "iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))" && SET PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin

Install your programs

  1. Visit the chocolatey site to find packages (http://www.chocolatey.org)
  2. Open a cmd with Administrator Privilages
  3. Create your own script that looks something like this:
  4. choco install -y googlechrome vlc skype 7zip
    

 

Optimizations

Remove Preinstalled Apps

If you are running Windows on a Desktop without any touch capabilities, you will probably have no use for certain features, like Cortana or those Apps in the Start menu. Some of these Apps you can remove using the control panel, however Microsoft apps like “Mail” cannot be removed using the control panel.

To remove them you need to using an evevated Powershell (Windows Key > “Powershell” > Ctrl – Shift -Enter)

To remove a package

Step 1

First List all available Packages


Get-AppxPackage

Step 2

Use the name of the package, only one package should be selected


Get-AppxPackage Microsoft.Windows.Photos

Step 3


Get-AppxPackage Microsoft.Windows.Photos| Remove-AppxPackage

Note: It is not recommended to remove the Windows Store. It is rumored that you then cannot install anymore Windows updates after that.

 

Remove all Packages

As alternative run following command to remove all Apps (excluding the Windows Store).

 

Get-AppxPackage -AllUsers | where-object {$_.name –notlike “*store*”} | Remove-AppxPackage

Note: This command may also remove components you actually would like to keep It is better to create a controlled powershell script to remove only the apps you do not want.

Disable UAC (User Account Control)

Assuming you are a power user and you know what you are doing with Windows. You can disable the User Account Control using the elevated Powershell console.

With this oneliner you can disable UAC on your computer.


Set-ItemProperty -Path HKLM:\Software\Microsoft\Windows\CurrentVersion\policies\system -Name EnableLUA -Value 0

(Restart required)

Posted by happyneal in Windows, 0 comments
Getting Started using AngularJS with Yeoman and Visual Studio Code

Getting Started using AngularJS with Yeoman and Visual Studio Code

Typically to get started with a web-project you would start downloading libraries, configuring grunt etc. Yeoman is a project that takes care of all of this in a simple step and goes one step beyond, it also ensures that you will be using current web-standards. My editor of choice is Visual Studio Code (Other alternatives would be Atom, Sublime, Brackets etc.).

I will be using Windows as my Operating system, all Software is available cross-platform for Mac and Linux. Some commands need to be adjusted for the platform you are using.

Software needed:

Now it may seem odd that python and git is listed here. However while I was trying to get yeoman to work I discovered that bower requires git to be added to the path and since python was missing from my path, some odd errors occurred while creating the initial project.

Getting Started with Yeoman

Working with Yeoman requires you to work with the terminal.

Open Powershell (Powershell is the newer version of the console and emulates more a linuxlike shell) by searching for “Windows Powershell” in the StartMenu

  1. Install a lot of node stuff you need for yeoman
    npm install -g yo bower grunt-cli gulp
  2. Now you need to install the yeoman generator for angularjs
    npm install -g generator-angular

Your first Yeoman project

Simply because you are anyway in the console change the directory to your project directory (something like cd c:/projects)

You can create a new directory using the mkdir-command like:

mkdir angularProject

Finally run

yo angular

to create your project.

You have to answer a couple of questions which (modern) tools&frameworks you would like to use:

Sass (with Compass): Yes

Bootstrap: Yes

Bootstrap Sass Version: Yes

More information about the official yeoman generator-angular can be found here.

If everything goes smoothly the generator-angular created for you an entire modern webapplication project that uses angularjs.

The generated Gruntfile

Grunt is a taskrunner, when properly defined it can automate a lot of tedious work. Yeoman essentially does the work of properly defining the gruntfile.

A lot of tasks are to optimize your various files, like css, js and image files. It also takes care of running the preprocessors like sass or less.

It even runs your javascript tests with karma.js. (and now that grunt takes care of most of your repetitive tasks you maybe even have time to write some tests).

What do you need to know?

There are three commands you can use on the console:

  • “grunt” – simply runs all the tasks and provides a working webapp in the “dist” folder
  • “grunt serve” – starts a webserver and automatically updates your browser while you are working on the source files
  • “grunt test” – runs all of your tests

 Visual Studio Code Setup

Well there is not much to do. You need to open the folder of your project.

And out of the Box you can already run the build and test tasks.

To additionally run the “serve” task in Code

  1. Ctrl-Shift-P > Configure Task Runner
  2. In the tasks.json add a new task
     {"taskName": "serve", "isWatching": true } 

 To use the Visual Studio Code Debugger you need to adjust the Debug Configuration

  1. Ctrl-Shift-P > Debug: Configure
  2. Change the line “program” : “app.js” into “program”: “app/scripts/app.js”.

Conclusion

The power of this setup is mostly that most of the stuff comes out of the box, and provides you with a great foundation to create a high quality code project.

You can and should extend the gruntfile to suit your specific needs like to push your project onto your webserver.

Posted by happyneal in Web Technologies, 3 comments
Maximum Memory by Windows Services Configuration (BlackViper Settings)

Maximum Memory by Windows Services Configuration (BlackViper Settings)

There are a lot of tips and tricks on how to optimize your system memory. One of the main ways to get the most out of your system is to configure the “Windows Services”, essentially tasks and programs that windows starts and stops in the background. These services are needed by other programs, changing this configuration can result in that some programs cannot start or behave in a strange manner. If you mess around with the services, you could disable your access to the internet and its a pain to figure out which service you accidentally stopped that should have been running.

There are only two situations in which you should configure the services

  1. You are desperate and want to optimize a very old pc without having to buy new ram
  2. You are a gamer and want the speediest most lightweight computer

Service Configurations

Fortunately smart people have already played around with various configurations. BlackViper provides on his website a list of “tweaked”, “safe” and “default” settings. However the table on his website is interesting, but not very useful. If you would want to apply these settings you would have to open up “services.msc” and apply each setting manually.

Thankfully I found a way to convert the table into a powershell script.

  1. Head over to his site  http://www.blackviper.com/service-configurations/
  2. Go to your Version of Windows
  3. Use the websites Copy function and save the tap separated table into a textfile
  4. Execute following python code in the same folder

Alternatively you can download the resulting Powershell Scripts for Windows7SP1:  Win7SP1 – BlackViperPowerShell

Note: During the execution of the script errors appear for services that are not installed on your system – just ignore them.

Results

To consistently measure the memory usage I did a clean install of Win 7SP1 on a VirtualBox.

  • Default  39 Processes using  600MB Ram
  • “Safe Configuration”:  29 Processes using 500MB.

While the safe configuration ‘saves’ you 100MB of Memory. The amount of effort of testing if all your programs are still running correctly etc. Does not make a lot of sense – especially when typically you are anyway have 8GB+ RAM in Computers these days.

Image:

Posted by happyneal in Hardware, Python, Windows, 0 comments
EdX: Introduction to Linux

EdX: Introduction to Linux

I recently completed the course “Introduction to Linux” by the Linux Foundation on the edX platform. Instead of paying 2500USD for the course you now can pay 250USD for a verified certificate, or simply get an honor certificate.

https://www.edx.org/course/linuxfoundationx/linuxfoundationx-lfs101x-introduction-1621#.U-YKjfmSyyY

Course Structure

The course is self-paced, you can take the exam anytime and at the end of the month the certificate is going to be issued.

Course Materials

Unlike other edX courses most of the materials are short articles covering the core topics. There are short videos, however they are mostly useless.

Learning Objectives

Sadly the first couple of Lessons are more like Advertisements that Linux is great and that Linux is used everywhere and being able to use Linux is an important skill.

The rest of the course covers the basic operations when interacting with a Linux system.

The course briefly takes a look at the graphical interfaces of three major Linux distributions Ubuntu, CentOS and openSUSE.

As expected most of the course covers how to interact with the Console covers the basic interaction with the console, file operations, security principles, text manipulation and concluding with bash scripting.

Final Exam

The final exam is a 30 question multiple choice test. Sadly some questions are easier to be answered using Google than the actual course material.

People with an basic understanding of Linux could just skip the entire course and just take the exam. It’s rather straightforward.

Conclusion

The course is a great introduction to the Linux System. The course is designed for IT-Specialists (Programmers, Web-Developers, and Administrators etc.) that have not worked with Linux and need a quick introduction how to work with the system.

Sadly with the emphasis on using the console most users interested in using Linux as alternative to Windows/OSX will simply say “Oh god, what a hassle, I’ll stick to my current system.” Once again Linux does not realize that GUIs have been invented to solve an issue where most people find it confusing when they do not see what they are doing.

Most users interacting with a computer are not aware that it is possible to interact with a computer without GUI, telling those users that sometimes you simply do not have a GUI confuses them. Most of the success of Linux as core of Android is the GUI and that users have a simple way installing programs and are not able to access any console / text only mode.

Once again the core of Linux is great, however the presentation and usability is that what sells Linux.

 

 

Posted by happyneal in Blog, 0 comments