DEV281x: Introduction to ReactJS

I took a quick look at Microsoft Introduction to ReactJS, not to actually learn React, but to evaluate how good the materials are for a beginner to learn React.

tl;dr
Avoid the assessment. Maybe use create-react-app instead of codepen.
Covers the basics quite well.

Lesson 01 | JSX and React Components

Instead of using “create-react-app” as a starting point, the course tells you to go to codepen to check out react.

I guess that makes it a little more focused on the React concepts and less focused on all the surrounding technologies that are needed in an production environment.

After that it covers the basics of ReactJS, and JSX.

If you are a beginner you probably want to check out create-react-app.

Lesson 02 | State, Life Cycle and Event Handlers

I think the chapter covers the basics quite well. Nothing really to add here.

Lesson 03 | Lists and Forms

Here i think it is very nice that they cover the basics of handling multiple Form Elements with a generic handler.

Assessment

The Assessment is quite theoretical and asks rather complicated questions. These questions are especially hard if you have already worked with React as you would never even try to build something in that way.

As a beginner I would completely skip the Assesment. It does not help you to further your understanding of React. It actually also confronts you with bad practices, while inferring that this would be the way how you would actually do things

Conclusion

If you use create-react-app with vscode I think you would have a much better starting experience.
The course is great to get started with ReactJS, if you avoid the assesments and rather just experiment with your own code base.

edX – Microsoft: DEV275x Writing Professional Code

The course DEV275x Writing Professional Code, is a very short introduction to best practices when it comes to writing code.
As usual this is only my notes I took during the course, you defiantly should check out the course for yourself at
https://courses.edx.org/courses/course-v1:Microsoft+DEV275x+2T2017/course/

Module 1: Elements of Professional Code

Source Control with Git

Source Control is one of the most important aspects of programming.

  • Backup of your Source Code
  • Ability to compare with changes done in the past
  • Restore previous versions if something goes wrong with the new version
  • Easy collaboration with other people

There are many different Software packages that enable Source Control.
Currently the two most popular systems are Git (70% of Programmers) followed by SVN (10% of Programmers) (Survey of 30k Developers)

The core difference between the two is, that for SVN you need to set up a dedicated Source Control Server, and all changes are tracked there.
With Git it is distributed, so you can use it locally and if you choose in combination with a server.

Especially Code Editors like Visual Studio Code have Git directly integrated making it really easy to set up and use Git.

Programs:
* Git

Cloud Providers
* Gitlab For Private Repos
* Github For Public Repos

Workflows
* Comparing Workflows
* GitLab Flow

Markdown

Markdown is really great because you can learn it really fast, and even if you do not convert Markdown into a HTML site or PDF the text is still formatted quite neatly and readable.

Like Git you find support for Markdown files in common editors like Visual Studio Code / Atom.
And of course in blogging software like WordPress have plugins that enable Markdown for the Posts.

Module 2: Communicate with Code

Now this chapter was rather interesting, it focused on how those smaller things like code conventions actually help to improve the codebase.
While the presenter did not use automated tools to improve the code readability it was nice to see that it is a very important aspect of coding to get the really basic elements correct.

Consistency and Naming

Code should be formatted always in the same matter. It improves the readablity and removes all personal style from the code enabling all developers to immediatly take ownership of the code instead of saying well that is the style of developer A, he should fix it.

Naming is important and greatly improves the readability of the code it does not help to say var c = 0, it is much better to say var beanCounter= 0.
You do not write code for the computer but actually for other human beings. The compiler will then convert it into machine code, but you will probably not have to debug that.

Refactor Duplicate Code

A great problem is when the code base has a lot of duplicate code. As soon as that happens and some minor change changes the way how you do things, then you would have to go back and change all the different places where that piece of code is used.

Refactoring early reduces the risk that the next developer says, well, I will just do that with copy and paste.

Simplfy

This one is rather difficult, but by keeping the code and the structures simple and readable has an much higher benefit in the maintainability of the code than some complex structure that executes a micron second faster. Of course that depends on the program you are writing.

As a rule of thumb functions should be rather short, not hundreds of lines long. (Too short is also bad.)
If you needed to add complexity then you also should document why you are adding it and what is the best approach to understand that complex structure.

Module 3: Code Confidently With Unit Tests

Well writing Unit Tests and overall having Tests for your code, allows you to a) know the use cases of your code and b) allows you to see when you change something what else may have been broken while you were developing a new feature.

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

This week the course is covering another two very important topics: Testing and Specifications.

LECTURE 3: Testing

Testing is a very important part of creating functionally correct programs.

Testing will be always incomplete

You will try to test your program using three methods:

  1. Formal Reasoning, essentially you manually verify that your program works correctly
  2. Code Review: Another Programmer takes a look and says everything is ok.
  3. Test Suites: Essentially you write another program (which can have its own bugs) to test your program. You define the inputs and the expected output and compare them.

The course mentions again the residual defect rates of 1-10 defects/kloc(1000 lines of code). Again this does not cite where this number actually comes from. Especially when using Industry Standards and Test Suites this high number would drastically drop to an much lower number. However in the end it only would remain to be an assumption since the actual number cannot be determined.

You testing your program for every possible input (Exhaustive testing) is not feasible. The strategy to simply take a look and see if it works (Haphazard testing) will also not reveal all bugs. The same is true for “Random” testing. All of these test methods cannot be used to test software.

Write Tests

When you are writing tests you should think about how you can make your program fail. Test drive development takes the following approach.

  1. Specify what you want to program
  2. Write tests that would test the specification
  3. Write code so that your code passes the tests

The specification is key to define what inputs are possible and which outputs will be produced. (This also includes throwing errors)

Blackbox testing only focuses on the input and output of the function. These tests do not take into account how the algorithm actually works.

The alternative is Whitebox testing takes into account how the program is implemented.

Test Coverage

Now that you have written tests for all of your code, did you also test all of your code? Coverage takes a look at if all Statements and all possible paths through your code are covered.

There are various Code coverage tools available that you can run and then visually see which part of the code is covered by your tests.

In reality you should try to achieve a coverage of 70-90% of your code achieving 100% is usually not possible due to time constraints. Of course this is not the case if you are using Test Driven Development.

Running Tests

Usually you would create a Testsuite of Unit Tests. You should integrate these tests into your build process to ensure that the tests run automatically. Especially when you modify existing code this will ensure that your modifications will not accidentally break something unintentionally.

When working with multiple people you should add hooks to your git repository that it rejects code that does not pass your test suite.

 

LECTURE 4: Specifications

This lecture is going to cover preconditions and post-conditions in method specifications, and how to write correct specifications.

What is a specification?

The lecture defines a specification primarily only concerning how the interfaces are defined and how the specification document essentially is used as communication device to talk to the client.

Now this actually assumes that the client is another programmer that wants the module/system to do a specific functionality. In my work experience usually the client has no technical background and expects the programmer to know what he wants.  Yes the specification is the key document on how to negotiate which features etc. the client requires, it is however not exactly defined which functions or how interfaces should be created, this is usually the task of the programmer.

The course actually is more talking about a documentation document how and which interfaces exist in the code you are programming for the client. The documentation is key whenever other programmers need to use the code you have programmed.

In either case, the specification document is a key document. It defines the work that needs to be done. The document shields the programmer from the client, if the client forgot to specify something, thus the programmer did not implement it he can prove it was the clients fault. At the same time the programmer is bound to the document that he actually implements all features. (or negotiates, talks with the client that the functionality is unfeasible, or not possible to be implemented)

Pre and Post Conditions

For each function you require the preconditions (what inputs) and postconditions (what outputs).

The inputs may have to have a specific structure, cannot be a certain value etc. These need to be checked.

The function also will have various outputs. This is of course the result, and how the result should be structured, the method also can throw errors.

Write test cases

Essentially if the specification of the function is well defined it is very easy to write the test cases. You simply follow the specification write tests to get the expected correct results and willfully pass wrong arguments into the function.

The rest of the lecture covers how to throw Exceptions. Which to use when.

HOMEWORK

Again another batch of “Java Tutor” exercises. They were as exciting as the last batch…

However this time they also provided a “warm up” problem set. The warm up is just to implement the mathematical “quadratic roots formula”.

The straightforward implementation of the formula will not pass all the Unit Tests. You need to take a deeper look at Java to actually figure out why the last Unit Test fails, and how you can change your code to make your code pass the test.

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.

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.