It's been a little over a year now since I began to take coding seriously (I've a free ebook all about it!). I often think, "What could I have done differently that would have helped me to learn to code faster?"

I think it’s very helpful to look back on your coding journey, and try to pinpoint those things you found beneficial and those that were a waste of time. Those positive practice should be shared with those just starting out in hopes to help them learn to code faster without wasting time.

Today I was thinking what I would tell a CodeNewbie (of which I still consider myself) to help them suceed more effectively in their coding journey.

This post looks to answer this thought with three points that I think will help anyone grasp the concept of coding, no matter the language or platform, and ultimately learn to code faster.

Learn To Code Faster With These 3 Concepts

1. Pseudocode

Anyone with a logical brain can do pseudocode. Actually we do it every day.

When I started to code I just couldn’t understand pseudocode. Perhaps I was reading the wrong tutorials.

It seemed really difficult because I kept coming to different conclusions than the one teaching it (not knowing that this was okay!).

I was told I needed to paraphrase the code before I actually write it, but then they went on to mention Markdown, and the best way to write it, and I got caught up in all the steps involved and it just seemed something I couldn’t quite grasp.

A year later I realized I was seriously overthinking it. It’s rather simple and at the same time extremely helpful.

Think if you had a dentist appointment at 3:00.  Its currently 2:00 and you are already out on the town. You need to get groceries, deposit a check, and make it to the appointment by 3:00.

You might plan things like this:

  • I need to get groceries and deposit a check by 3:00
  • Which one is futher away? The bank. Go to the bank first.
  • Which grocery store is closer to the dentist office? Wal-Mart. Go there next.
  • It will be 2:30 when I arrive at Wal-Mart. The dentist office is 5 minutes away. I will have 25 minutes left to shop.
  • In order to be done in 25 minutes I can only grab the essentials. Grab the essentials in the grocery section only.
  • Leave Wal-Mart by 2:55.
  • Arrive at the dentist office at 3 p.m.

Now perhaps that’s a beastly example, but you get the point. There were no directions involved. There was no exact mileage. There were no additional conditions checking for traffic or road work.

Instead, there was a paraphrased outline of our plan to get groceries, cash a check, and make it to the dentist office within an hour.

Paraphrased. Thats the key.

Pseudocode is not a programming language. There is no syntax or rules. Its a summary of steps needed to reach a conclusion.

Thats it!! Don’t overthink it.

And at the same time, do not underestimate it.

It will, without doubt, help you learn to code faster!

Now lets give a coding example:

Lets say you had two forms on your website. Form A and Form B. And you want to get the number of rooms from Form A and repeat a set of fields on Form B based on how many rooms there were on form A.

So if there were 3 rooms in Form A, a section of Form B would repeat 3 times. If there were 2 rooms in Form A, the section in Form B would repeat only 2 times.

Now, to do pseudocode it doesn’t matter if this is accomplished with PHP, JavaScript, or Python. We don’t need syntax or code, we just need some paraphrased logic.

Our pseudocode may go something like this:

  • Check to see if there is a Form A
  • Get the number of rooms from Form A
  • Create 10 sections in Form B as 10 will be the max number.
  • Give each section a class like room-1, room-2, room-3, etc.
  • Take the number of rooms from Form A and loop through Form B hiding the sections that are greater than the number on the class (room-2, room-3, etc.).

Thats very basic, but you get the point.

Now that I have some pseudocode, we can take this and use the syntax of our language to make it happen.

How do we do this? What if I don’t know the language?

No worries! Why? Because all we need to know are the concepts that nearly all code shares i some way:

Lets look at that.

2. Concepts

Here is an example:

Javascript has a for loop. You get the hang of that, and then you learn the while loop. Someone has you work on their site and its in PHP. Well, PHP has a for loop…..and a while loop. Then you begin to explore python and see also that they have a for loop AND a while loop!!

Javascript has an if statement that can be paired with an else if, PHP an elseif, and Python an elsif. Different terms, same concept.

They all three have “if” statements.

They all three have strings, variables, methods, functions…….!

What’s the difference? Syntax!! (Hang on, we will talk about this in the final section.)

The key is to nail down these fundamental concepts and get a good grasp on them.

Here are a few to summarize that you must know:

Strings

A string is a sequence of characters between two single or double quotes.

“Hello World!”

Integers

Integers are numbers (not strings)

4

Variables

A symbolic name associated with a value and whose associated value may be changed

a = 4
a is the variable

Conditionals / If statements

Tells a program to execute different actions depending on whether a condition is true or false

if (10 < 20) {

print(“This is right!”)

}

For Loops

Handy, if you want to run the same code over and over again, each time with a different value.

for (i = 0; i < 5; i++) {

text += “The number is ” + i + “<br>”;

}

While Loops

Used to repeat a specific block of code an unknown number of times, until a condition is met.

while (i < 10) {
text += “The number is ” + i;
i++;
}

Functions

A function is a block of organized, reusable code that is used to perform a single, related action. Can be called.

function myFunction() {

echo “This is my function!”;

}

myFunction();

These concepts are found in most languages. If you understand what they are and how they work, you are prepared to tackle any coding situation, given that you know the Syntax.

And that leads us to the final step in helping you code faster:

3. Syntax

Documentation is your best friend.

You will never outgrow the Documentation of a language.

You will still use Documentation as an expert.

It is your friend. The sooner you make your acquaintance, the faster you will learn.

Why?

Because you now understand pseudocode (logic paraphrased). And you understand the fundamental concepts of coding, all that is left is for you to write it out correctly.

PHP, JavaScript (though not “official”), Python, content management systems like WordPress, all have documentation created for you to reference as you write code in that language.

Becoming a good coder happens when you learn to read and benefit from the documentation.

Another benefit of consulting the sources files of a language is that you always get the right answer, not a long list of opinions from a Google search (though Google searches are wonderful).

Example #1

Let me give an example of how helpful being able to read documentation is:

Let’s say I’m in WordPress and on my blog page I want to have the category show up below the title of every blog post listed. So my loop is showing my latest 6 posts and I want each of their respective categories listed below the post title.

I could go to Google and search for “how to add the categories to my blog post” and get an answer that I can copy and paste.

But even better is to go to the Codex and get the answer that I need, in addition to all the different uses of the code available.

So in order to do this I need to use WordPress’s built in function the_category();

As I consult the docs I can glean many things:

What it does:

“Displays a link to the category or categories a post belongs to. This tag must be used within The Loop.”

Great! This will display a link the the category or categories that I need. AND it works inside the loop, which I need as well.

Its usage:

<?php the_category( $separator, $parents, $post_id ); ?>

This is the best part. This tells me that there are three built in arguments that I can use with the explanation of each one. Well what if you are not sure how to use them? No prob! For example, lets look at the $separator.

<?php the_category( ‘, ‘ ); ?>

This separates each category with a comma and then a space. It also tells us that this separator is a string, this the quotes.

There are also the WordPress developer docs that give us more info, such as the actual code behind the function. Taking time to look over this will help you learn to code faster.

Example #2

Lets look at another example in WordPress: the_post_thumbnail()

It’s Use

Looking at the documentation we see its use:

“Display the post thumbnail.”

It’s arguments:

the_post_thumbnail( string|array $size = ‘post-thumbnail’, string|array $attr = ” )

This tells us it takes two arguments:

  1. The size of the image
  2. Attributes that we can define

It also gives us a number of examples to help explain including this nifty one:

the_post_thumbnail( ‘thumbnail’, array( ‘class’ => ‘alignleft’ ) );

The thumbnail size will be “thumbnail,” which is a default WordPress image size and it will assign the image a class of alignleft, which will align it left.

These attributes can be combined as an array and passed as an argument:

$attr = array(
‘src’ => $src,
‘class’ => “your-css-class”,
‘alt’ => “your alt text”
);

There are also a handful of examples that explain how this function can be implemented in a more advanced situation. .

You not only get all of the syntax info well defined, but you get practical examples.

So hopefully you see that there is no substitute from the source documentation. Google search will help you find the right documentation and help you immensely, but a habit of checking the documentation will no doubt help you become a better coder and untimaltely helping you learn to code fast and with better accuracy.

Conclusion

So in retrospect, these are three concepts that I think can help any CodeNewbie learn to code faster. If I would have grasped these concepts sooner, no doubt I would have wasted less time.

I hope these will help you do the same.

Looking back on your coding journey, what are the things that boosted you forward helping you learn to code faster, and what were the things that held you up? Let’s discuss!

 

Comments