Monday, October 26, 2020

50 Ways to Improve as a Programmer

I have been a professional programmer for over 20 years. I have learned tricks, made mistakes, and gained experience. In no particular order, here are 50 ways to improve as a programmer:

  1. Write lots of programs. Every program you write, no matter how small, adds to your experience. This practice enhances your understanding of programming concepts.
  2. Make programming your hobby. Programming on personal projects builds enthusiasm and passion. If you like what you do, learning is easy.
  3. Search Stack Overflow for answers. If you have a programming question, you will likely find the answer on Stack Overflow. Be critical of answers but use them as learning opportunities. When you are ready, answer questions too.
  4. Get a good book and work through the examples. Good programming books have plenty of content, organized for learning. The Deitel books are very thorough, with lots of examples and explanations. If you are a beginner, take a look at The Super Simple Programming Book.
  5. Learn one way, ignore the rest. Programming languages often provide more than one way to accomplish the same task. For example, there are several ways to increase an integer variable by 1. Pick one way that makes sense and spend time learning different concepts. You can learn the other ways later.
  6. Focus on the basic programming concepts. When you are starting out, the fundamentals are most important. Learn about data types, input/output, selection, repetition, etc. Focus on the basic programming concepts before trying to learn a new language.
  7. Find a mentor. Connect with a colleague, social media contact, or anyone who has technical expertise that you can learn from. You will learn more from a mentor than you will from any book or website.
  8. Participate in coding challenges and events. There are lots of coding challenges and events that are fun ways to practice programming. Twitter has #100DaysOfCode. Code.org has Hour of Code. The Advent of Code is a really fun programming challenge that happens during the first 25 days of December. Coding challenges use fun to motivate you to practice coding.
  9. Take a free programming course. Coursera has excellent computer science courses from top universities. There are similar courses on Udemy. MIT OpenCourseWare publishes course materials for some computer science courses.
  10. Use code linters. Code linters provide immediate feedback for your programs. The online W3C Markup Validation Service checks web documents for validity. PEP8 Online is a linter for Python code. There are many linting tools available.
  11. Take advantage of static code analysis. SonarQube offers static code analysis of programs. It helps you write cleaner and more secure code.
  12. Participate in code reviews. Participate as both an author and a reviewer. Do not fear failure in a code review. We all make mistakes. And mistakes are excellent learning opportunities for everyone.
  13. Watch YouTube videos. There are lots of YouTube tutorials, explanations, and lessons on almost any programming topic. These videos are easy ways to learn programming simply by watching. Here are some YouTube videos on Node.js.
  14. Solve Project Euler problems. Project Euler has lots of mathematical and computer problems to solve. The website lists how many people have solved each problem.
  15. Participate in Google Code Jam. Google Code Jam is an annual, worldwide coding competition. The website lists past and current problems. You can enter the competition or just practice for fun.
  16. Use an IDE. An integrated development environment (IDE) is a programming tool that helps you create, edit, execute, and debug programs. IDEs find and highlight errors while you type your programs. They suggest corrections. An IDE also puts an interactive programming reference at your fingertips.
  17. Go back to school. If you have the means, take a computer science course at your local college or university. Pursue a bachelor's degree or certification to certify your computer science knowledge.
  18. Consider a coding bootcamp. Coding bootcamps offer specialized training on specific programming skills. The skills are often in high demand. Just be careful when selecting one. Not all coding bootcamps are equal, and most are expensive.
  19. Create a programming blog. To learn something, it helps to read it, hear it, and write it. Writing about your programming experiences in a blog will enhance your learning. It will also motivate you to learn more.
  20. Work through online tutorials. There are many excellent online programming tutorials. Some are simply for reading. Others are interactive. The W3Schools online tutorials are simple, straightforward, and interactive. Codecademy has excellent interactive tutorial on different programming languages.
  21. Participate in programming forums. Read and respond to posts in programming forms. The interactions there are excellent learning opportunities. For example, JavaRanch and Java Forums are popular online communities for Java programmers.
  22. Teach programming. Teaching others how to program is a very effective way to enhance your programming knowledge. Tutor university or local students. To teach programming, you must prepare lectures, create examples, and answer questions. This forces you to really understand programming. Even volunteering to teach programming has similar benefits.
  23. Create your own website. If web development is your passion, learn how to develop your own website. Personal projects like this one give plenty of motivation to learn and code.
  24. Participate in coding interviews. Many companies require coding sessions or take-home assignments as part of the interview process. These activities provide excellent learning opportunities and real-world practice. You must also prepare and learn ahead of time. Coding interviews are valuable, even if you do not get the job.
  25. Learn from open source software projects. Open source software projects on sites like GitHub and GitLab offer excellent examples to learn from. Many of these software projects are popular in the industry. Contributing to these open source projects offers more programming practice.
  26. Follow coding standards and style guides. Coding standards are best practices that improve code. They make code more readable, maintainable,  and more. Google publishes coding standards and style guides for a variety of programming languages.
  27. Become a freelance programmer. If you have the time, offer your programming expertise as a service. There are many websites where you can find freelance programming assignments. This is a great way to practice, while earning a little extra money.
  28. Join a programming community. Find programming communities in your area. There are many online programming communities at LinkedIn, Facebook, and other social media sites. These are places where you can interact with people who share the same passion for programming.
  29. Get a job. Get a programming job, any programming job. Nothing beats industry experience and learning.
  30. Volunteer your programming skills. Every industry has a need for programming skills. Many cannot afford to hire programmers. There are plenty of volunteer opportunities for programming. A local school, club, or organization may have programming opportunities that you can assist with.
  31. Write plain vanilla code. Yes, built-in functions, frameworks, and external libraries make coding easier. But there is a lot to learn from coding from scratch. For example, try coding with vanilla JavaScript instead of jQuery. Try using the plain array construct instead of the Java ArrayList class. Coding from scratch will force you to think more and write resourceful solutions. It will also make you appreciate the many useful external libraries out there.
  32. Do not reinvent the wheel. For important programs, do not reinvent the wheel. For specific programming tasks and logic, search for an existing solution. These solutions are often tried and tested. For example, npm is an online repository of Node.js libraries. PyPI hosts external Python libraries. Be critical when selecting external libraries for your programs. Some are better than others.
  33. Attend a programming conference. Programming conferences bring developers of all levels together for presentations, demonstrations, and other learning opportunities. The Grace Hopper Celebration is a popular conference that celebrates women in computing. Google I/O is another popular developer conference. There are many other programming conferences. Some offer virtual attendance now. If not, be sure that they offer proper social distancing if you attend.
  34. Join a professional organization. Professional organizations like the Institute of Electrical and Electronics Engineers (IEEE) and the Association for Computing Machinery (ACM) offer collaboration opportunities, journals, conferences, groups, and other opportunities to learn more about programming. These organizations charge a membership fee, but they offer student discounts.
  35. Write a book. There is an endless number of topics for programming books. No matter what your programming level, there is a book topic for you. Self-publishing sites like Amazon Kindle Direct Publishing make it easy to publish and sell your book. Writing a book will force you to really learn the material, create examples, and test your programs.
  36. Program a robot. What is more fun than seeing your program come to life. Beginners and experts can program robots to complete tasks. The Sphero BOLT is a programmable plastic orb that features sensors, movement, and an LED display. LEGO MINDSTORMS is another programmable robot kit that has advanced capabilities. Programming robots makes programming really fun.
  37. Visit Code.org. Code.org deserves its own spot on this list. The website is dedicated to learning, teaching, and promoting computer science. There are online coding activities for beginners, coding statistics, inspirational videos, and more. 
  38. Try Alice. Alice is a 3D teaching tool for computer science. It makes learning computer science visual and fun. The late Randy Pausch oversaw development of Alice at Carnegie Mellon University.
  39. Learn Git version control. Although this does not specifically relate to programming, you will undoubtedly use Git to maintain versions of your programs. Online Git repositories such as GitHub, Bitbucket, and GitLab are powerful tools for collaborating in software development. However, they are excellent for individual use too. Many developers use GitHub, for example, to host online coding portfolios.
  40. Embrace real-time communication. This is another tip that is not directly related to programming. Real-time communication tools provide immediate feedback and answers when working with others on programming tasks. Slack is a very popular real-time communication tool that offers persistent text, voice, and video chat. The tool allows you to create public and private channels for different topics. It allows threading of conversations for more organization.
  41. Code on the go. Your mobile phone is also a computer. Why not code on the go? QPython is a Python interpreter for Android phones. Python2IDE is on iOS phones. With those apps and many more, you can practice coding right from your mobile phone.
  42. Code without help. Take a programming task and write a program for it without searching online or using assistance from an IDE. See if you can code from memory. This type of coding practice will force you to commit important concepts to memory. It is also good practice for coding interviews.
  43. Refactor your programs. Learn how to refactor your programs. Even if a program produces the correct outputs for all the possible inputs, it may still have room for improvement. For example, make it more maintainable, more readable, and less complicated.
  44. Learn other programming languages. Once you have a good foundation of the basic programming concepts and a strong understanding of a given programming language, it may be time to branch out. Learning another language can increase your understanding of programming languages in general. It is helpful to see how different languages implement the same programming concepts or offer new features. For example, the Java programming language improved on C++ by addressing memory leaks.
  45. Program for art. Programs are not just for business. Programs can create art. With random behavior, graphics, and processing, programs can create beautiful output. This takes the passion for programming to a whole new level. Python turtle graphics and HTML Canvas graphics are two ways to create simple and complex art with programs.
  46. Have the right attitude. Be humble. You cannot know everything about programming. If you think you do, I promise there is someone who knows more. Programming is an endless learning loop. Accept that you do not know, and you will know.
  47. Leverage public APIs. There are many public application programming interfaces (APIs) that you can connect to with programs. Twitter, YouTube, and Google Maps are just some APIs that you can develop against. You can create impressive software applications by leveraging these powerful APIs in your programs.
  48. Assess your programming skills with Soloway's Rainfall problem. Soloway's Rainfall problem is a problem that tests programming skills for introductory computer science students. If you can complete this programming task, you have a good understanding of programming fundamentals.
  49. Learn from console input and output. There are fancy websites and graphical user interfaces. However, do not ignore what simple programs can teach. Programs that accept input from stdin and write output to stdout can be powerful, complicated, and full of functionality. These programs have a lot to teach.
  50. Learn assembly language and computer architecture. When a program executes, it uses computer resources. Understanding how computer memory, the central processing unit (CPU), and other computer components work will help you understand how a program works. Assembly language is a low-level programming language. Its instructions correspond to machine code instructions. An IF-ELSE statement in C may require twice as many statements in assembly language. Understanding low-level assembly language and computer architecture will explain how a program interacts with the computer, teach you to write more efficient code, and make you a better programmer overall.
Whatever you do, keep practicing programming! Most of all, be safe, practice social distancing, and be well!

Friday, October 23, 2020

You DO Know Hex...


...you just don't know it yet. Allow me to explain.

Back in elementary school, teachers taught us about the ones, tens, hundredths, ... columns. So the number 894 has 8 in the hundredths column, 9 in the tens column, and 4 in the ones column.

More specifically...

894 = (8 * 100) + (9 * 10) + (4 * 1)

Do you see a pattern with the ones, tens, and hundredths columns? They are all powers of ten: 100, 101, and 102. This is the numbering system we learned in school: base 10. The valid numbers in a column are 0 - 9. That makes sense, because we can only have a single digit in a column.

Now in the hexadecimal number system, the base is 16. So the first three columns are the ones, sixteens, and two hundred fifty-sixths columns. In powers of sixteen, they are: 160, 161, and 162. So the number 894 in hexadecimal is:

89416 = (8 * 256) + (9 * 16) + (4 * 1) = 219610

Note that the subscript indicates the base. 894 is the hexadecimal number. 2196 is the base 10 equivalent. You can also represent hexadecimal numbers like this: 0x894. For the 2196 base 10 number, we typically omit the 10 subscript since it is assumed.

The hexadecimal story continues a bit more. If base 10 uses the numbers 0 - 9, then what does base 16 use? Base 16 must have 16 possible digits. Its range of digits start with the same digits 0 - 9. The remaining six digits are: A, B, C, D, E, and F. The letters stand for 10 - 15 respectively. So, counting in hexadecimal is like this:

0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F

I guess it would be too confusing in elementary school to combine numbers and letters in math. But it would've been fun trying.

For a final example, here is the conversion of hexadecimal F0A to base 10:

F0A16
= (F * 162) + (0 * 161) + (A * 160)
= (15 * 162) + (0 * 161) + (10 * 160)
= (15 * 256) + (0 * 16) + (10 * 1)
= (3840) + (0) + (10)
= 385010 
So there you have it. Hexadecimal numbers made easy! You already know hexadecimal. Just change the base from 10 to 16. And have a cup of 0xC0FFEE while you're at it!

Monday, October 19, 2020

Five Basic Programming Concepts To Learn First



I often hear new programmers ask, "Should I learn Python?" or "Should I learn Java or JavaScript?" This is the wrong approach. New programmers should focus on fundamental programming concepts. Having a solid foundation of these concepts makes it easy to learn any programming language, because the concepts are common among the different languages.

Here are five basic programming concepts that new programmers should learn first:
  1. Data types - Programming languages represent data in the real world. Data come in different forms such as integers, floating-point numbers, characters, strings, and Boolean. Since programs need data to process, understanding data types is crucial.
  2. Operators - Operators operate on data to create new data. There are mathematical operators for numeric data, logical operators for Boolean data, and more. Programs use operators to process data and create information. For example, in many programming languages the + operator can either add two numeric values or combine two strings.
  3.  Selection structures - Selection structures provide multiple paths of execution in programs. The path depends on a condition or value. For example, the if-then-else statement provides two paths of execution, depending on a true/false condition. Programs would be somewhat useless without selection structures.
  4. Repetition structures - Repetition structures repeat a statement or block of statements. This is useful for implementing repetitive behaviors in programs. Repetition structures, also known as loops, make programs dynamic by executing statements a number of times.
  5. Input/output - Programs accept input and produce output. Input provides data that programs need. Output communicates data and information to the users.
Learn these five basic programming concepts well. Practice them in your programming language of choice. When it is time to learn a new programming language, you will already know the concepts. You will just need to learn how to use them in the new language.

Friday, October 16, 2020

The Programming of Art


I have spent most of my career writing programs for business reasons. Writing them has given me a sense of fulfillment. But this was not the reason why I chose this career. Every now and then, I am reminded why I love this field so much.

Recently, I wrote a program that revived the enthusiast in me. While preparing examples for students in my full stack web development course, I accidentally created art. I named the program The Walk. It is currently executing above. Refresh the page to restart it.

The surprising thing about the program is that it is fairly simple. After all, it is a teaching example. The program has only a few basic elements:
  • an HTML document that uses built-in canvas graphics
  • random numbers
  • rotating colors
  • repetition
The algorithm is simple. Start in the middle of the two-dimensional canvas. Pick a random color. Pick a random direction. Draw a line with the color and direction for 10 pixels. Repeat the process, while changing the color every 1,000 steps.

The result reminds me of complex systems where agents and simple interactions lead to emergent behaviors. In this program, one emergent behavior is the output art at the end of the program. Another emergent behavior is the creation of additional colors by retracing steps.

There is nothing novel or proprietary about the program itself. It uses basic HTML, JavaScript, and CSS statements that you can learn from online tutorials (see W3Schools).

The full source code for The Walk is below. Save it to a file named walk.html. Double-click the file to execute the program in a browser. Programming isn't just for business applications. Programming is an outlet for creativity. And creativity leads to art.

<!-- walk.html -->
<!DOCTYPE html>
<html lang="en">
<head>
  <title>The Walk</title>
</head>
<body>
  <canvas id="myCanvas" width="600" height="600" style="border:2px solid black;"></canvas>  

  <script>
  var canvas = document.getElementById("myCanvas");
  var ctx = canvas.getContext("2d");
  var iterations = 0;
  var color_iterations = 0;
  var idx = 0;
  var MAX_ITERATIONS = 14000;
  var colors = ['red','orange','yellow','green','blue','indigo','violet'];
  var x,y;

  //color canvas white
  ctx.fillStyle = "white";
  ctx.fillRect(0, 0, canvas.width, canvas.height);
  
  //do the random walk
  ctx.fillStyle = colors[idx];
  x = canvas.width / 2;  //start in the middle
  y = canvas.height / 2;

  function walk() {
    ctx.beginPath();
    ctx.moveTo(x,y);
    m = Math.floor(Math.random() * 4);
    newx = x;
    newy = y;
    switch(m) {
      case 0:
        newy = newy - 10;  //up
        break;
      case 1:
        newy = newy + 10;  //down
        break;
      case 2:
        newx = newx - 10;  //left
        break;
      case 3:
        newx = newx + 10;  //right
        break;
    }
    
    //if new coordinate are off the grid, skip it
    if (newx < 0 || newy < 0 || newx > canvas.width || newy > canvas.height)
      return;

    //step is good
    ctx.lineTo(newx,newy);
    ctx.stroke();
    x = newx;
    y = newy;
    ctx.closePath();
    color_iterations++;

    //change colors after 1,000 steps
    if (color_iterations >= 1000) {
      color_iterations = 0;
      idx++;
      if (idx > 7)
        idx = 0;
    }
    ctx.strokeStyle = colors[idx];
    
    iterations++;
    if (iterations > MAX_ITERATIONS) {
      clearInterval(id);
      console.log('done.');
      return;
    }
    
  }

  var id = setInterval( function() {walk(); } , 0);
  </script>
  
</body>
</html>

Monday, October 12, 2020

What programming language is this?

What programming language is this?

    a) Java
    b) C
    c) JavaScript
    d) C++
    e) All of the above

If you answered e), you are correct! Learning that first programming language makes the next language easier to learn. That's why it's so important to focus on the fundamentals. Learn the basic programming concepts (e.g., for loops). Your next language has the same concepts, just written in a different way. 





Saturday, October 10, 2020

The Philosophy of Recursion

It was CS111, my first computer science course at Rutgers University. The lecture topics were fairly straightforward so far. Input/output, selection, and repetition statements made sense to me. I started to think that a programming career was possible. Then my professor announced the topic for the day: recursion.

I wasn't intimidated until my professor started describing recursion. He said that recursion was a different way of thinking. It was both powerful and abstract. It was elegant and mysterious. It would twist your mind into thinking differently. But what really caught my attention about recursion was that fully understanding it was a moment of enlightenment. You may not understand it right now, in a few days, or even months later. One day, when you are ready, recursion will come to you and say, "I see you."

For me, that moment came years later at my first full-time job after college. I was having a difficult time with a program. I understood the problem, but I couldn't develop the solution algorithm. Then I remembered recursion. The problem reminded me of recursion. After some reflection, I was able to wrap my head around recursion and develop the algorithm. It was a moment of enlightenment for me, like in The Karate Kid when Daniel realizes that Karate was in him all along.

It was then that I realized that recursion was always around me, in many forms. On television, I saw a newscaster. Behind him was a television monitor of that same broadcast. In that monitor was the same broadcaster sitting in front of a television monitor of the same broadcast. And so on.

At a child's birthday party, I picked up two mylar balloons. They both had silvery, mirror-like surfaces. I put them next to each other and saw myself in a reflection of myself in a reflection, seemingly into infinity.

Even artwork from as far back as 1320 illustrate recursion. Medieval paintings used the Droste effect to show a picture, within a picture, within a picture, etc. The main photo at the top of this article is an example of the Droste effect. Take a minute to contemplate that drawing. Let it draw you in.

The 2010 sci-fi film Inception is perhaps the clearest example of recursion in a movie. In the film, the characters must access deep layers of subconsciousness to extract information and alter the future. To do this, they sleep and enter a shared dream world. Once in the dream, they assemble and once again sleep and dream. And so on. The deeper they go, the closer they get to the subconscious state of the target's mind. To leave a dream state, the characters use a kick to return to the previous dream state and so on. More on kicks later.

One final example of recursion is one that you can do yourself. Take two phones and start a video call between them. Then face one camera to the other. With both cameras in view, quickly rotate one phone a quarter turn clockwise. Watch the effect on the other phone. This effect is also seen at the end of the Arkangel episode of the Black Mirror television series.

Now back to programming. The Hello World program for recursion is the factorial concept from mathematics. Here is the calculation of five factorial (5!):

5! = 5 x 4 x 3 x 2 x 1 = 120

A simple Java program to calculate the factorial is:

int n = 5;

for (int i=4; i >= 1; i--)
  n = n * i;

System.out.println(n);  //120

The for loop simply performs the calculation above in a straightforward manner.

A recursive program requires a different way of thinking. The factorial equation above offers clues on how to think recursively. 5! is the same as 5 times 4!. 4! is the same as 4 times 3!. And so on. Eventually, we reach 1! which by definition is simply 1.

So, a function call to calculate 5! would  return the expression:

5 times a function call for 4!

But the function call for 4! is a function call to the same function. In other words, let the function call itself.

Ponder that for a moment 🤔.

When the first function call for 5! makes a second function call for 4!, it waits for the second function call to return. The second function call returns the expression:

4 times a function call for 3!

It too waits for the function call for 3! to return. Function calls repeat in this manner until the function call for 1!. At that point, there is no need for an additional function call, because the function can simply return 1. This simple case is the kick needed to stop making recursive calls and return to the previous level. Inception.

The previous function call receives 1 and returns 2 * 1 to its caller, which returns 3 * 2 to its caller, which returns 4 * 6 to its caller, which returns 5 * 24 to the first function call, which is the final answer of 120.

Here is the complete Java program for this example:

public class FactorialExample {

  public static int factorial(int n) {
    if (n == 1)
      return 1;
    return n * factorial(n-1);
  }
  
  public static void main(String[] args) {

    System.out.println( factorial(5) );  //120

  }

}

Recursion will make you think on a different level or levels. It will twist your mind like a Droste painting. But recursion will one day come to you, and you will recognize it like an old friend. And together you will navigate the world of programming in ways you never thought of.

Thursday, October 8, 2020

My Cold Brew Recipe

I became a huge cold brew coffee fan when I came across this New York Times recipe. I adapted the recipe, and I have been a huge fan ever since 😀. So easy, so cheap, and better than anything you can buy IMHO!

Ingredients & Items
Brewing
  • Add ground coffee to the 40 oz glass food storage jar
  • Fill glass jar to the top with filtered water
  • Close/seal the jar so it is airtight
  • Wait for 24-48 hours
Filtering
  • Double-filtering is key...
  • Place the plastic brewing cone on an open mason jar
  • Place the paper cone filter in the brewing cone
  • Place the reusable cone filter in the paper cone filter
  • Open the glass food storage jar and pour the cold brew mix into the reusable cone filter
  • Continue the process to double-filter all the cold brew mix
  • Cover the mason jars with lids to make them airtight
  • Remember that the output is cold brew concentrate!
  • Cold brew concentrate lasts up to 2 weeks in an airtight container
Drinking
  • Pour 1 part cold brew concentrate and 3 parts filtered water and ice in a glass (you can vary the ratio to make it stronger or weaker)
  • Add cream and sugar to taste, or drink it black (my favorite!)
Enjoy! 😋

What is Git Markdown?

Git Markdown is a markup language that creates HTML-like documents for web-based Git repos like GitHub, GitLab, and Bitbucket. The documents...