Say Something

There is a fine line between funny and hurtful. It seems the two are getting so intertwined it is often hard to distinguish between them. When people say something hurtful to or about me I am often…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Why Thinking Matters More Than Coding

What I thought programming is going to be like

Before my journey as a novice programmer, I used to think that programming will be filled with long hours of writing code. The archetype display of a Silicon Valley programmer in black hoodies bashing down on their Cherry MX Blue keyboard with dual monitors stuck with me whenever I thought of computer programmers.

Unsurprisingly, this facade of a computer programmer isn’t far too different from how Hollywood and movies only portray the “cool side” of an occupation. In fact, it might come to a surprise for a lot of beginners to know that a huge part of computer programming/software development is actually the thinking process; the brainstorms and constant back-and-forths to the drawing board.

There are a lot of reasons why a good programmer should think before writing code. Devoting time to meditate on the problem gives assurance that the computer programmer can truly understand the problem and consider all possible problem cases. Doing so will result in a program that is mostly full-proof and capable of running smoothly.

Another reason to do is to create an efficient program with cleaner source code and zero redundancy. As computer programming has as much art as science, there are over a million possibilities in how one could solve a certain problem. There is the brute-force way of writing code, or the logically-sound and algorithmically beautiful code. There is also the clean and readable code following the proper style, while there is also code with more redundancy than appropriate documentation.

During this time of solitary and quarantine, I decided to jumpstart my way to the University of Texas at Austin’s CS 312, Introduction to Computer Science, syllabus. I figure it wouldn’t hurt gain prior understanding so that I wouldn’t have any difficulty later on. Surprisingly, while typical coding courses such as Codecademy starts off with writing syntax (if statements, for loops, functions, etc), the syllabus for CS 312 starts with Java’s static methods and redundancy. I believe this is one reason why formal education still runs triumph in comparison to online courses.

Write a program in a class named Shining that prints the following line of output 1000 times:

You should not write a program whose source code is 1000 lines long; use methods to shorten the program. What is the shortest program you can write that will produce the 1000 lines of output, using only println and methods?

Note that loops are not allowed.

As I have said at the beginning of this article, thinking of the problem is, in a huge way, more important than writing the actual code. If I were to immediately code without thinking of the problem, I could have created a simple code with 1000 println statements. Nevertheless, this approach to the problem is both inefficient and a major time waster. To tackle this problem, I placed my thought on the question.

One fundamental principle of problem-solving is breaking down the problem into smaller pieces. With this in mind, I thought of ways in which I could break down the enormous figure of 1000. From a mathematical standpoint, 1000 is equal to 10*10*10. This is also true for 10*100. After breaking down the problem to smaller pieces, I can finally come up with a suitable solution.

The first step in any Java program is to create the class and the main method.

Afterward, I created the following method which prints out the “All work…” statement.

With this method already created, I made another method that will print printStatement() ten times.

The method above ensures that I have access to 10 lines of the statement. Next, I can create a similar method, but this time with printTenTimes() printed ten times, giving me 100 lines of the statement.

With the method above, I now have a method that will print the 100 lines of the statement. Finally, I can call the printHundredTimes() method ten times in the main method, which gives the final code

By thinking of the problem beforehand and breaking down the large problem into smaller pieces, I can find the correct answer in less than 50 lines of code. Nevertheless, if someone were to actually write 1000 lines of code, I would have probably finished writing this 50 line of code program first.

Therefore, to any aspiring computer programmers: don’t forget to ponder about the problem beforehand. Be the philosopher of your code!

Add a comment

Related posts:

HOW TO CONVINCE YOUR PARENTS TO STUDY ABROAD

You have made that big decision to study abroad and are enthusiastic about the plans for the future, but there is one small detail that you have ignored: your parents For many students, their parents…

Feisty Old Broads

This is a song I am writing for my upcoming Broadway-style Musical. These fun lyrics will be put to the tune of the Stevie Wonder classic song ‘For Once in My Life’. It will be performed with two…

We All Have Broken Windows

I got my income tax forms filed on time again this year. That might not seem like a momentous accomplishment. After all, most Americans have to complete this yearly ritual by Tax Day each spring. But…