Why I Prefer JavaScript

Many years ago when I started my university studies (more than I would like to think), I elected as my major computer science. I stuck with that major for about 2 semesters and then switched to English. Many people thought it was a drastic switch; from one side of the spectrum to the other. Two majors that are not even closely related.

However, I considered both majors similar. I discovered that the reason I enjoyed English during my undergraduate studies is because I enjoy expressing myself with language. (Now, I may not be that great at it, but I still enjoy it.) I also enjoy seeing (reading) how others express themselves with language.

Well, in that sense I see many similarities between programming and writing. In programming you need to use the syntax and semantics of the language to express what you are trying to accomplish. You not only have to communicate to the computer, but you also need to communicate to other programmers that will need to read and understand your code.

This brings me to the reason that I prefer coding in JavaScript over other languages. JavaScript is a very flexible language. There is never one way to solve a problem. JavaScript includes multiple approaches to coding and doesn’t force you into a single approach. I love the flexibility. I love the freedom. I love to see how different programmers approach a similar problem; the unique techniques they come up with and basically how they express themselves. And I enjoy not only solving the problem, but there is a certain satisfaction when you can solve it in an elegant, expressive way.

This is why I prefer JavaScript. Probably not a reason you expected to hear, but it is the most persuasive reason for me personally.

Why do you use JavaScript?

A Complete List of JavaScript Tutorials

We only publish about half of our JavaScript tutorials in this blog and we want to make sure you have better access to them. So it was decided by the powers that be to create a full list of tutorials on our website. I know, it is not a difficult conclusion to come to; we should have done it a long time ago.

The tutorials are currently organized into 5 categories. As we see the need, we will break them out into more categories. Take a look at the list and find those you would really like to view.

Also, take a moment and suggest a JavaScript tutorial you would like to see by making a comment in the comment section.

Here is a link to the list:

http://www.allthingsjavascript.com/youtube.html

Working with XML Data

The other day I had to work with some XML data in JavaScript. I’ve mostly worked with JSON data, which is easy to work with because you can convert it to a JavaScript object. XML data is not too bad either once you convert it to a Document Object Model.

Browsers have a DOMParser object that will allow you to make that conversion. Once you have the XML data as an XML DOM, you can then use the same commands you use to manipulate an HTML DOM to work with the XML data.

Since I had to work with it, I decided to do a tutorial on it. It is the latest tutorial in the JavaScript Question playlist of the All Things JavaScript YouTube Channel.

The tutorial just went live today. You can view it right here:

What is the Difference Between a Programming Paradigm and a Design Pattern?

When you first start learning to program, your initial focus is on the language. You learn the syntax and the structure. Once you become comfortable and able to put statements together to solve programming problems, you are then free to think more about programming.

As experienced programmers have thought about the best ways to approach the building of an application or the best way to solve a particular problem, they have developed paradigms and design patterns. The smart developers draw on this expertise to improve their own programming skills by adopting paradigms and design patterns.

A paradigm is simply a style or an approach to programming. For example, Object Oriented programming is a paradigm. If you follow this paradigm you use objects to approach the overall program. The objects contain data and behaviors and you connect them in logical ways to successfully solve the task at hand.

Now a design pattern is a tried and tested solution to a common programming pattern. It could be considered a best practice. If you approach a program using an Object Oriented paradigm, there are a number of design patterns you can then draw on to solve specific problems.

So how do we apply this to JavaScript? JavaScript can support many different paradigms and there have been numerous design patterns developed to solve individual problems that arise with each paradigm or across paradigms. JavaScript is flexible. There is not one way to accomplish something and therefore numerous approaches have been developed. You can draw on those approaches and you can mix and match them as needed.

I really like this quote by Angus Croll:

Natural language has no dominant paradigm, and neither does JavaScript. Developers can select from a grab bag of approaches–procedural, functional, and object-oriented–and blend them as appropriate.

Aren’t you glad you are a JavaScript programmer?

 

Making Sense of the Prototype

Over the last couple of weeks in the All Things JavaScript YouTube channel, I have been focussed on creating a couple of tutorials that will help those that are somewhat new to JavaScript understand and grasp prototypes.

I have to admit that when I first started learning JavaScript, I ignored the prototype when it came up. I was mainly doing procedural programming, so I had what I needed and wasn’t looking for another construct. Well, I have since learned that it was a bad idea to ignore it. The prototype is a key concept in JavaScript, and a very powerful feature, but it is a concept that is sometimes neglected by those that are new to JavaScript.

In these two tutorials I have tried to first explain prototype in a way that will make sense. And then I delve into three techniques for setting the prototype of an object.

So quickly to get you started, the prototype is simply a way to link one object to another. Once you have linked your object to another object, which is called the prototype object, you can then access the properties and methods that reside on the prototype object. This mechanism is the essence of prototypal inheritance in JavaScript. This concept allows you to structure code more effectively.

If you have not watched these two tutorials yet, first watch the tutorial that explains prototypes.

Then you can watch how to set the prototype.

Are you making use of prototypes in your JavaScript coding?

Grasping Recursion

For me recursion is one of those concepts that took me a while to grasp. You are accomplishing the same type of thing that is accomplished with a loop, but it is not as easy to understand.

I recently did a tutorial on recursion. It uses a simple example to help you see what is going on with a recursive function. Take a look.

There are certain situations where recursion is very helpful; mainly working with a tree structure. I have used it a lot in the past with XML data. I don’t deal with XML data quite as much anymore, but I still find other tree structures where it is helpful.

Is recursion something you use? In what situations have you used it?

Approach to Projects

Sometimes the most difficult part about a project is starting. It can reduce a lot of stress and put you well ahead if you have a process for starting a project.

For example, something I commonly do is to spend time setting up the structure of the project and the processes needed to test and minify project files. That little bit gets my head into the project and then I can get going. Otherwise, I feel like I languish before I can really get started.

The other day I read a great article at Sitepoint about how to approach projects. I thought it organized all the starting tasks really well. These starting tasks are not only important, but I realized they can accomplish the same thing of getting your head in the project and getting you going in the right direction.

Give it a read here.

What approaches do you take?

Finding JavaScript Libraries and Frameworks

Several weeks ago I wrote about javascripting.com. At that time I had just discovered the site and found it very helpful in providing information about JavaScript libraries and frameworks. Since that time I have created a video on the All Things JavaScript YouTube channel that talks about three sites that can be used for gathering information about libraries and frameworks.

The tutorial not only provides more information on javascripting.com, but also talks about microjs.com and Github’s explore page. If you have found javascripting.com helpful, you may also enjoy the information on the other sites. He is the tutorial that was recently releases on the YouTube channel.

Selecting DOM Elements with Pure JavaScript

When I first encountered jQuery, I loved it because of the simplicity provided for selecting DOM elements. Back then, selecting DOM elements with pure JavaScript was even more involved than it is now.

Because of the ease jQuery provides, it is very easy to rely on it completely. In fact it is not uncommon to see JavaScript questions posted on Stack Exchange that are really questions about jQuery. In some cases the two have become synonymous. However, as of late there has been a push back against jQuery from the JavaScript world saying it has neared the end of its life.

Whether you believe that or not, I feel it is important to not become so reliant on jQuery that you forget basic tasks in JavaScript. Let me give you a scenario. Lets say you need to do some simple JavaScript coding for a basic web page. It may consist of 100 lines or so. As you get working on it, you realize you need to load jQuery because you don’t know how to affect the DOM any other way. That is a huge library to load for something so small. I believe it should be done in pure JavaScript.

In this tutorial we cover how to select DOM elements using pure JavaScript. I think it is a good idea to know the pure JavaScript way of doing certain tasks that might be done with JavaScript libraries and frameworks. What do you think?

Enjoy the tutorial.

Another Book from the You Don’t Know JS Series

Several weeks ago I reviewed the book ES6 & Beyond. I found it to be the best source for ES6 features in JavaScript. I am about finished with another book in the You Don’t Know JS series entitled: this & Object Prototypes.

Kyle Simpson, the author of the You Don’t Know JS series, is very knowledgable when it comes to JavaScript, and he doesn’t disappoint in this book. I especially found the detailed discussion regarding the keyword this very informative. this can be difficult to grasp fully and Kyle deals with it thoroughly. He organizes the discussion in such a way that the concepts affecting this and its value are easy to compartmentalize.

The second part of the book is object prototypes. Before diving into prototypes, he makes sure to cover objects in good detail. So you have a grounding as you dive into prototypes. I also found this section very informative and gained new insights.

If I were forced to point out a negative with the book, it would be the ongoing discussion of whether JavaScript uses the right terms for Object Oriented design, inheritance, and so forth. Kyle prefers the term Delegation Oriented design because of how prototypes actually work. These tangent discussions involved a lot of class theory and were insightful, but I found them less useful for the practical side of my brain which is usually looking for application.

If you would like to deepen your understanding of this and prototypes in JavaScript, it is a must ready. So pick up a copy and jump right in.