Thursday, March 25, 2021

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 are documentation for your repo. They describe topics such as installation, configuration, and deployment. They document development and contribution procedures. The topics are up to you.

Markdown files render like HTML in web-based Git repos. They are popular in repos and expected by developers.

A Markdown file is nothing more than a text document with the file extension .md. The file contains Markdown syntax. Here is an example of a Level 1 header:

# My Repo

The single # indicates a Level 1 header. Two ## indicate a Level 2 header:

## Installation

Here is a sample list:

* lions
* tigers
* bears
...and a sample numbered list:
1. Wash
1. Rinse
1. Repeat
Note that the numbers are all 1s, but they will appear as 1, 2, and 3 when they render in the browser.

There are many other ways to format text in a Markdown file. Some organizations extend Markdown syntax for their platforms. But the core Markdown syntax is complete enough to get started.

Learn Markdown syntax and start creating Markdown files. At the very least, create a README.md file at the top level of your repos. Then see how the browser automatically renders that file as HTML in your web- based repo. All serious repos have a README.md file.

Wednesday, March 24, 2021

How to use JavaScript template strings

JavaScript Template Strings are another way to create and combine strings. The technique is simple once you know the syntax.

Here is a code snippet with three string variables:

const str1 = 'Coffee ';
const str2 = 'and ';
const str3 = 'code';

One way to combine the strings is the concat() function:

const combinedStr = str1.concat(str2, str3);
console.log(combinedStr); // outputs: Coffee and code

Another way to combine them is the + operator:

const combinedStr = str1 + str2 + str3;
console.log(combinedStr); // outputs: Coffee and code

And here is how to combine the strings with a JavaScript Template String:

const combinedStr = `${str1}${str2}${str3}`;
console.log(combinedStr); // outputs: Coffee and code

To create a Template String:

  1. Start and end the Template String with a backtick (`).
  2. Put your variable, expression, or data between ${ and }. JavaScript evaluates this value.
  3. Other characters in the Template String are just literal characters.
Here is another Template String example that combines literal characters with a random number:

const num = Math.random();
const combinedStr = `Here is a random number: ${num}.`;
console.log(combinedStr); // sample output: Here is a random number: 0.07571510037185902.

JavaScript Template Strings are another way to combine and create strings. The technique is convenient and simple. Some JavaScript lint tools prefer Template Strings over string concatenation. So that is another reason to learn them.









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. 





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...