Ranking Programming Languages

A recent article on InfoWorld titled Breakthrough: Python reaches Tiobe index Top 3 – Yey Python – But wait, what is being ranked?

The TIOBE Index uses search engine data to extract which languages are popular.

That is a questionable way of figuring out if a language is popular. It only means people are searching for a language. Does the search data separate between Java and JavaScript (two very different languages)? Are the searches for things that are difficult in the language and unclear. Basically if a language is badly documented = more searches => higher on the index. The more issues and frustrations you have with the language will rank you higher.

If we take a look at the 2017 results unsurprisingly Java takes the Number 1 spot. As many companies use Java and many universities teach Java. Thus a lot of people are searching for Java. – However programmers are actually starting to dislike Java, as there is currently so much poorly crafted Java-code in the world that desperately needs to be rewritten. In addition the Java community is facing a lot of problems with rapid unwanted changes from Oracle. (*Note: Java is a great language that strongly promoted object oriented programming and is a great tool – it is just in a wierd phase right now.)

Interestingly on position 11 we have Delphi / Pascal. A programming language I have used the last time over 17 years ago. I doubt any company is still using Pascal applications. However as a part of programming language history it is quite interesting. And there was of course a spike last year as a new version of the compiler was released. (https://www.freepascal.org/) Also schools with outdated curriculums still teach Pascal…

I am not sure what information I can gain from this type of ranking. It could mean that Java is a mess because so many people are googling their problems with the language and an old language Pascal is now suddenly on the rise and will become the next big thing?

How would I rank programming languages?

First we need to figure out who needs rankings of programming languages. My guess is people that want to start learning a programming language, people who want to see trends in the industry and managers who need to make project decisions.

Before we can even begin with ranking the languages the first stumbling block. Depending on your project you may be already locked in with a specific language. In many cases you want to start building on things somebody else is providing you, a Web Browser (JavaScript), a mobile device (iOS: Swift/Objective-C, Android: Kotlin/Java) a game engine (Unity – C#, Unreal – C++), etc.

Simply put if you have a defined project, just start working on the project. The language might be already defined and you do not need a ranking.

A person who wants to learn programming

This list should take multiple things into consideration. The person learning has practically no knowledge. The person has to learn everything from scratch. The important thing is to start learning programming concepts. It should be easy to learn, ideally avoiding advanced stuff like compilers and static typing (and preferably a language also used by the industry and not university only).

This leaves a rather short list:

  • Python
  • JavaScript

These two languages are dynamically typed and at the beginning still very forgiving for mistakes. Both have tons of documentation.

Starting with JavaScript is really easy, just press F12 in your browser and you can get going, no installation needed. It also simultaneously teaches you concepts about HTML and Networking. Concepts of Object Oriented Programing as well as functional programming can be learned. And variants of the language like TypeScript can explain the value of static typing and what a compiler does.

Starting with Python is a little more difficult. As you first have to install python etc. The other thing is of course the meaningful whitespace, which is wierd for a beginner but at the same time the best way to get a beginner used to the idea that code should be beautiful and readable.

There is no real ranking – just choose one of the two. Both are equally well suited as a starting language.

I would take a look at how many new projects are being created in which language. Statistics from Github from their Octoverse Survey

  1. JavaScript (2.8Mio)
  2. Python (1 Mio)
  3. Java (0.9 Mio)

Of course this is only from one source and you would have to add multiple sources to get a better picture. (In this case we only see values from OpenSource projects). If you want to see trends you can observe these values over the last couple of years.

For business people

Here we need to take the money aspect into account. Just because “Java” appears at every top list of backend enterprise web development – that does not mean it is currently the best business choice.

One of the key indicators could be how verbose a language is. As research has shown that a Java Developer and a Python developer take the same amount of time to write the same lines of code. – However a Python program can need in some case 30% less lines of code to do the same function.

From the http://helloworldcollection.de/

Python Hello World:

print("Hello, World")

Java Hello World:

public class HelloWorld {

    public static void main(String[] args) {
        System.out.println("Hello, World");
    }

}

You would have to take a look at long term maintainability of the language. Basically: who is maintaining the language – will it still exist in 10 years?

  • Java is supported by Oracle, that is messing around with the business model surrounding Java, so maybe not.
  • TypeScript supported by Microsoft, and Open Source (worst case you are going to need to maintain it yourself)

Another important factor is tooling and ecosystem. If the ecosystem is dying then it may be a good time to switch languages.

And of course the last factor would be how many programmers are currently listing the language as one of their skills. (there are programmers on the market that you potentially could hire to work on your system)

Depending on your project you may need to take hardware costs into account.

Unfortunately there is no universal approach to this multifaceted problem. Depending on which factors are important for your project you will get a different ranking of possible languages for your project.

Conclusion

There is no singular good way to rank programming languages. However whenever you encounter a list or ranking of programming languages just be aware of what techniques they used to create the list.

Credits: Image: Evaluation System Designed by Makyzz / Freepik

Gayle McDowell – Cracking the Coding Interview

The book “Cracking the Coding Interview” helps you to survive the famous ‘technical interview’. Major tech companies like Google, Amazon etc. use these types of interviews to figure out if you can program.

Overall even with the book your chances are slim of passing the interview. – In any case most of the questions are the usual university preparation questions for the most broadest subjects in the field of computer science. So a lot of theoretical stuff and low-level programming skills. – The questions are in a way stupid – but what do you expect? they are questions that an HR person can ask you that have no merit or value in your day to day work.

Basically prepare yourself for this:

You probably should use additional resources if you really want to pass this type of interview. Mostly things like hackerrank or codewars.

The book however is a really good starting point And it is nice that for every topic there is a short introduction about what is important and how to approch questions from that topic.

Interview Process

The HR person will look for four things:

  • Analytical Skills
  • Coding Skills
  • Technical Knowledge
  • Culture Fit / Communication

“Prior experience” – is not needed, you put that already on your CV.

Of course the entire process is riddled with tons of mistakes and false negatives – simply because the process does not figure out if you can actually do the job. However the few people that survive the process – are probably candidates you can position anywhere in your large corporation.

Whiteboards are used to focus on ‘what is really important’ – translation: it is easier and quicker to set up an whiteboard than an actual IDE. Get ready to get maybe judged for making minor typos even though ‘the interviewer does not care’ – subconsciously he is judging you.

Before the Interview

Get the right experience

  • Try to take classes with big programming projects
  • Internships: Try to get some work experience
  • Build something in your spare time (=> Github)

Write a great resume

Keep your resume to 1-2 pages, HR People spend very little time reading it. But it needs to be perfect so they dont throw it out due to small things.

Write strong bullet points

Use the formula: “Accomplished X by implementing Y which led to Z”

Leave out stuff

You are applying for a programming job, you probably know how to use Office etc. be conservative which programs you list Same is true for all the programming languages, list those that are relevant and are widely used.

Be aware of the stigmas that are associated with languages. Some languages like Visual Basic while they are used and even if you know the language on an expert level it is mostly seen as that you have less experience than a language like Java/Python etc.

Certifications – Usually a waste of paper and most people do not see it as relevant. (in the field of computer science)

Behavioral Questions

Prepare your past projects ask yourself for each project

  • What where the Challenges?
  • What went wrong?
  • What did you enjoy?
  • Who lead the project? Did you lead the project?
  • How did you resolve conflicts?
  • What would you do differently?

During this phase of the interview try to create a dialog about how your new employer deals with certain issues. You need to interview the company if the company would fit to you or not.

Focus on you not your project, however you still need to show that you can work well with others.

When you are talking about your past projects you should use the SAR principle

  • Situation
  • Action
  • Result

Ensure that during your stories you can show

  • Initiative
  • Empathy
  • Compassion
  • Humility
  • Teamwork

And of course sprinkle in shows how you succeeded.

Technical Questions

Well you need to get the book for all the questions, but about 90% of the book are questions on various topics with well written answers.

Conclusion

The book is really useful when you are applying for big US-Tech companies. However for German-Tech companies the advice in the book is rather limited as they do not use the ‘technical-interview’ in the hiring process. (It produces too many false negatives and developers are rare)

It only helps you if you are attempting to pass the “technical-interview” and you basically need about 1 year of training prior to your actual interview to pass the interview. Basically the ‘technical-interview’ is a skill only needed to get into a couple of companies.

If that is not your goal your time is much better spent contributing to open source and creating your own projects as you will learn more ‘day-to-day’-skills.

Despite all of that it is a very interesting overview of questions you may encounter in an interview. Get the book at Amazon

Image: Gayle McDowell – Cracking the Coding Book Cover

CodeWars: Weekly Newsletter

8kyu – positiveSum

The first question is to sum up all the positive integers in an array. Basically two things need to be done:

  • Filter out Values that should not be added to the sum
  • Sum up every item in the array

Basically you can write the solution like this:

export function positiveSum(arr: number[]): number {
  return arr
          .filter(val => val > 0)
          .reduce((total, current) => total + current, 0)
}

It is important to note that the initial value of 0 must be set, as if you pass in an empty array it would return NaN

7kyu – next Prime

Basically you need to check every number if it isPrime. Then you need to select an algorithm that can check if it is a prime number.

In this case I just took the code from the npm package is-number-prime. Which is a brute force way of figuring out if the number is prime or not. (There is probably something more mathematically elegant out there)

function isNumberPrime(n) {
  if (n === 2 || n === 3){
    return true;
  }
  
  if (n < 2 || n % 1 || n % 2 === 0 || n % 3 === 0) {
    return false;
  }
  let foo = Math.floor(Math.sqrt(n));
  for (let i = 5; i <= foo; i += 6) {
    if (n % i === 0 || n % (i + 2) == 0) {
      return false;
    }
  }
  return true;
}

function nextPrime(n){
  while (true){
    n++;
    if (isNumberPrime(n)){
      return n;
    }
  }
}

CodeWars: Weekly Newsletter 02

8kyu – Logic Drills: Traffic light

You need a function to handle each change from green, to yellow, to red, and then to green again.

Based on how the question is formulated it is suggested that you should always return the next item in an array. If it is the last item it should return the first item.

/**
 * 
 * @param {'green'| 'yellow'| 'red'} current 
 * @returns {string}
 */
function updateLight(current) {
  let lights = ['green', 'yellow', 'red'];
  let nextIndex = (lights.indexOf(current) + 1) % lights.length;
  return lights[nextIndex];
}

However as alternative you also could say: We always already know the next state, we do not need to calculate the next state. For traffic lights this system also probably will never change. Thus you can use an object to save the next states.

/**
 * 
 * @param {'green'| 'yellow'| 'red'} current 
 * @returns {string}
 */
function updateLight2(current) {
    return {
    'green': 'red',
    'yellow': 'green',
    'red': 'yellow'
  }[current];
}

7kyu – Sum of numerous arguments

The idea of this problem is mostly to make aware of that you can pass in an arbitrary amount of arguments into a js function.

In ES5 you would be using the arguments object and iterate over the array. in ES6 however we can use the cleaner spread-syntax:

/**
 * 
 * @param {number[]} args 
 * @returns {number}
 */
function findSum(...args){
  if (args.find(val => val < 0)){
    return -1;
  } else {
    return [...arguments].reduce((total, current) => total + current);
  }
}

Dealing with the new Java Release Schedule

Oracle has just announced that the End of Support for Java 8 is going to be January 2019. This, in turn, means that every business using Java will need to upgrade for security reasons to the latest version of Java. The new release strategy says that newer versions have a 6-month support and then a new major version of Java is going to be released. In Addition, they are changing the Version naming scheme from SemVer to <year>.<month>Basically allowing Oracle to introduce breaking changes to Java every 6 months. As a business you basically are given the choice:

1. Upgrade Java every 6 Months

If we would go with the first option it already gets strange. At the moment assuming you are currently on Java 8 you would need to directly update to Java 10, as Java 9 Support already has ended. However, you still would first need to update to Java 9 just to see what all does not work anymore due to Java 9 major changes and then move to Java 10. But that is assuming that your 3rd Party libraries also already did the update to the new version. Then in September, you would upgrade to Java 11. A lot of people are going to say, well good then we just do not upgrade now and wait for September to do the upgrade. Yes, you can do that, but that does not really matter as in the following March you anyway would have to upgrade again. Your business needs a new strategy how to deal with the rapid version changes. That is now only supported for 6 months instead of the ~3+ years. Personally, I really like this, as most businesses have the strategy: “Version upgrade? only when hell freezes over” – that only costs money and has no immediate benefits.  Focusing on the short-term impact, neglecting the fact that continuous upgrades are cheaper in the long-term and contain less risk compared to the big bang upgrades. Source: Java Release Roadmap

2. Get Java Advanced licenses (Extended Support)

The alternative is to just get the Java Advanced license. I could not find any information on the Oracle site. Basically, you are paying around 500usd/core (Source), so depending on how many servers you are using you will have to pay a small fortune. At the same time, you are only sidestepping the upgrade issue as you anyway have to upgrade your system every 3 years at least once.

3. Use another Language

Depending on your codebase you may want to look into moving away from Java. If you are starting a project you may want to look into C#, Python or JavaScript (or any other language) Many Java projects are anyway already running for 15+ years and may need a technological overhaul. You could think about switching to micro-services and start replacing a service one by one with another technology. While there are many costs and risks involved switching technologies, *developer training, system stability, continuous support etc. etc.

Conclusion

It really depends on your project and how your business deals with change how you ultimately deal with Release Schedule.  You definitely need a strategy how to approach this problem. The future of Java is unclear. Oracle is promising more rapid improvements of the language.  But there is the possibility that the changes are too drastic so that businesses will stop using the language. Either Java will continue to be one of the most used programming languages or fade into obscurity. The only thing that is certain is that the world of Java is going to be changing significantly in the next couple of years.

HTML: How to control the Form ‘autofill’-autocompetion

Image Designed by Freepik

The ‘autofill’ feature of browsers is a blessing and a curse. The feature enables the browser to reuse the data the user has previously entered in forms. The trouble starts when a form does not fulfill the standard. Then the feature sometimes fills in the wrong information into the fields.

Why does autofill fail?

The standard implemented a feature to group fields. This was created by adding optional ‘8characters at the start of the name’. A field like “first-name” could be interpreted as the group: “first” and autofill-field: ‘name’(=> last name). To correct this you would need to rename the field to ‘given-name‘ as this is defined in the standard. However, if you would test ‘first-name’ in the browser you will discover that autocomplete works without problems. That is because even though it is not in the standard certain aliases are detected correctly. Depending on how the browser interprets the form. If you are not using the standard you basically are telling the browser to guess what the field is and let the browser decide what to autofill.

The Standard Keywords

If you want a pleasant user experience for the visitors of your site then you should take the time to make sure that your form confirms to the standard keywords:

  • “name”
  • “honorific-prefix”
  • “given-name”
  • “additional-name”
  • “family-name”
  • “honorific-suffix”
  • “nickname”
  • “username”
  • “new-password”
  • “current-password”
  • “organization-title”
  • “organization”
  • “street-address”
  • “address-line1”
  • “address-line2”
  • “address-line3”
  • “address-level4”
  • “address-level3”
  • “address-level2”
  • “address-level1”
  • “country”
  • “country-name”
  • “postal-code”
  • “transaction-currency”
  • “transaction-amount”
  • “language”
  • “bday”
  • “bday-day”
  • “bday-month”
  • “bday-year”
  • “sex”
  • “url”
  • “photo”

For Credit Card Information:

  • “cc-name”
  • “cc-given-name”
  • “cc-additional-name”
  • “cc-family-name”
  • “cc-number”
  • “cc-exp”
  • “cc-exp-month”
  • “cc-exp-year”
  • “cc-csc”
  • “cc-type”

To use these keywords with attribute autocomplete. However if the field autocomplete is not set browsers will automatically check the attribute-name. In this example both fields would be detected by autofill as ‘name’:

    <form>
    <input name="field1" autocomplete="name" />
    <input name="name" />
    </form>

As a personal preference, I would not set the autocomplete-attribute and simply use the keywords in the field name. This immediately eliminates the need to think of a more suitable name. If you are dealing with a backend you cannot modify I would use the field autocomplete.

Groups

Sometimes you need some of these fields multiple times. Let’s say you need a shipping and a billing address.  Then you simply add a prefix to the attribute.

    <form>
      <input name="billing-street-address" />
      <input name="billing-country" />
      <input name="shipping-street-address" />
      <input name="shipping-country" />
    </form>

How to disable autofill?

In the rare case that you do not need this feature at all you probably would want to disable it. To do this you have again two options:

Disable globally

Simply add the attribute autocomplete="off to the form-element. You then can re-enable the autofill on an individual component by using autocomplete=on.

    <form autocomplete="off">
      <input 
        placeholder="disabled Autocomplete" 
      />
      <input 
        placeholder="enabled for only this input" 
        autocomplete="on" 
      />
    </form>

Disable Individual Input

You can disable the autofill feature for an individual component by adding autocomplete="new-password" (This is because Chrome ignores the ‘off’ value)

    <form>
      <input 
        placeholder="disabled only for this component"
        autocomplete="new-password" 
      />
    </form>

Sources:

ReactJS: Tech Demo – Learn Typing

In order to learn ReactJS, I decided to create a small useful tool to learn to type. I just recently had found the typing exercises I did when I was 10, so using that data as a basis I created a small react site. Demo: http://typing.nealbuerger.comSourceCode: https://github.com/borgfriend/Learn-Typing

Core Prototype

The prototype only took a look at how to create a single lesson. The lesson was hardcoded and simply took a look at how the lifecycle methods of ReactJs work.

Issue Keyevent Binding I discovered pretty soon that my typing lesson was a quite unusual case for the key event binding for React. I was creating a new type of input field that displayed the old text and change the display depending on the input of new text.

Solution: For my unique case, I added an additional event listener to the document using and passed the information into the react app.

Issue Design Since the goal was to look at various technologies I analyzed ant.designsemantic-ui, and material-ui.

Solution Each of the GUI-Frameworks has their pros and cons. It was a difficult choice, in the end, I created the app using material-ui simply because I liked how it looked. Diving deeper into it how it deals with styles (while incredibly flexible) I would need to get a little more familiar with it. For the next project, I will probably try out something else.

Functional Prototype

To make the app a little more useful, I converted all lessons into a single JSON file. I considered to create a server with a database, but as I only had around 20 lessons and the resulting JSON file was 67kb I decided to simply include the entire JSON file. With more lessons, I needed a lesson overview page and routing. I added react-router and used it with the tools it initially provided. Using react-router can be a little awkward at first. But as soon as you get the hang of it it is a powerful tool.

Improved Functional Prototype

Problem Slow Display of Characters For short lessons react worked great. However, if the lesson had more than ~500 characters the react became extremely sluggish, with even longer texts it took ages only to type a single character. React was re-rendering all components on every keypress.

Solution Basically, the problem was caused by inefficient state management and updating techniques. I added in mobx to deal with all the states and rewrote the core prototype to take advantage of the mobx observers. An additional benefit was to use mobx-react-router which can create a routingStore and lets you avoid the withRouter()stuff.

Current Version

For the last iteration of the project, I refactored the entire code to be more readable and maintainable in the future. For now, I stopped working on this project. It should be only a quick tech demo to show how React code should look like.

Image: Green Typewriter Designed by Freepik

How to publish on Github Pages with create-react-app and react-router

Now I will be assuming a couple of things:

  • You have a GitHub account and you created a repository for your app.
  • You created a react app either with npx create-react-app <appName> or npx create-react-app <appName> --scripts-version=react-scripts-ts
  • Then let’s get started.

Add gh-pages

Run npm i -D gh-pages\

Configure your package.json

First, you need to tell the react app where it will be hosted. You need to add to your package.json the attribute ‘homepage’:

    { ...
    "homepage": "https://<UserName>.github.io/<RepositoryName>/"
    }

Additionally, you need to adjust the scripts attribute.

    "scripts": {
    ...
    "predeploy": "npm run build",
    "deploy": "gh-pages -d build"
    },

Now you can run npm deploy and it will automatically create a branch, build the app and deploy it into your repository. It will even configure your github repository that the branch gh-pages will be now hosted.  So you can simply navigate to  https://<UserName>.github.io/<RepositoryName>/ and see the result. # Configure React-Router Before we can publish we probably have to change a couple of things in the configuration of the react-router.

  1. We need to set the basename. The basename ensures that all links of the Router are relative to this basename. To configure the basename you can use the variable process.env.PUBLIC_URL this ensures that you only need to configure the url via the package.json.
  2. We need to ensure that we are using aHashRouter instead of the typical BrowserRouter . The difference is that the hashRouter adds a ‘#’ into the url and upon a refresh of the page you will not see a 404 Github Error

Your index.js should look something like this:

    import * as React from 'react';
    import * as ReactDOM from 'react-dom';
    import { Router } from 'react-router';
    import createHashHistory from 'history/createHashHistory';
    
    const hashHistory = createHashHistory({ basename: process.env.PUBLIC_URL });
    
    ReactDOM.render(
        <Router history={hashHistory}>
          <App />
        </Router>,
      document.getElementById('root') as HTMLElement
    );

Deploy

Now can simply run `npm deploy` and your site should be published on https://<UserName>.github.io/<RepositoryName>/

Note: Since the build is published on a separate branch, your main repository may contain different src than what is published. So you still need to ensure that you commit your changes to your repository.

CodeWars: 7kyu – The Highest Profit wins

I am exercising to get back into Python. Even though the solution to this exercise is quite straightforward, you could tweak the code a little bit so that it runs a little faster.

Basically, with min() and max(), the list would need to be iterated over 2 times. You could rewrite the code so that you only iterate once over the array. Overall I choose to stick with my initial solution as it is better readable, thus making it easier to maintain in the long run.

def min_max(lst):
    '''
    Exercise: https://www.codewars.com/kata/the-highest-profit-wins/train/python
    Example:
        min_max([1, 2, 3, 4, 5]) => [1, 5]
    Args:
        lst: A list of numbers
    
    Returns:
        A list with two entries of the min and the max value of the list
    '''
    return [min(lst), max(lst)]

CodeWars: 6kyu – Counting Bits

You got numbers, you want to know how many bits are flipped to a 1

Sourcehttps://www.codewars.com/kata/bit-counting/train/python

Approach:

Well, first we need to convert our number from an integer to a binary number.

There are two ways to do this:

Variant 1: String Formatting

"{:b}.format(number)"

Variant 2: Build In a binary converter “bin(number)”

Then well now we just have to count the occurrences of ones.

def count_bits:
   return bin(number).count(str(1))

Note: It is important to count the instances of ones as strings of “1” instead of integers of 1. This is the case because we converted the int to a string and are now looking for strings instead of numbers.