Stop Blindly Following W3Schools!

Posted on Leave a comment

I started out learning to create websites by reverse engineering web pages that I found and liked online. The way I got started with CSS is an interesting story. I started developing static websites at a young age. I produced mostly ugly pages by myself and a wee-bit jazzy ones using something like Macromedia DreamWeaver. I hadn’t yet discovered the mystical world of stylesheets.

In the summer of 2006, it had only been a few days since France’s heart-wrenching loss in the final of FIFA football World Cup when I was absentmindedly browsing some WC pictures that I had painstakingly downloaded over my super-slow Internet connection. That delightful little folder of my favorite images was inside SUSE Linux. Whether it was version 9 or 10, I cannot remember.

As I was a KDE junkie, I naturally had the folder open in Konqueror, KDE’s default web and file browser. While scrolling through the list and mindlessly clicking this button and that menu, I stumbled across an option to generate a gallery out of images. I curiously clicked this option and, *boom*, there it was — a gallery of all photos in the folder in the form of a web page. What a beautiful web page it was. The page had supporting files, full-sized images, thumbnails, and an intriguing file with .css extension.

Clicking the CSS file opened it in my text editor. “Interesting, a .css file is only a text file,” I said to myself. Most of the contents in that file didn’t make sense to me, but there were these other pieces that seemed quite obvious such as background-color, color and font-family properties. In my reverse engineering fashion, I made a few changes here and there and refreshed the web page in browser. *Boom*, some of my changes were actually reflected. This seemingly innocuous incident created a minor explosion of curiosity in my mind.

Out came a new tab in Firefox, hastily typed were the letters “google.com” in address bar, and with a thud was hammered the Enter button on keyboard. A big search text box appeared in the next few seconds. What did I type in it? CSS, of course silly. To where did the very first search result point? W3Schools, of course silly. And so began my journey of learning CSS from the most popular web development learning resource on planet. I regret it to this day. My regretful mistake didn’t end at CSS, it was augmented by my learning HTML, advanced HTML and even JavaScript from W3Schools.

Out came a new tab in Firefox, hastily typed were the letters “google.com” in address bar, and with a thud was hammered the Enter button on keyboard.

Fast-forwarding to present times, just a couple of days ago I was listening to episode #7 (Online Resources for JavaScript Developers) of JavaScript Jabber, a popular podcast series for the lovers of the beautiful language. It was in it where a couple of web experts echoed my feelings about W3Schools. Just to be clear, when I was learning from the “great” W3Schools, I didn’t have any such feelings. In fact, I deemed every word and example on the website a work of experts, which they probably were. However, my feelings changed drastically when I “grew up” and started to discover most of my coding style that was derived from W3Schools was composed of a collection of anti-patterns.

In order to appeal to a wider section of audience and to make things simple, examples listed on W3Schools tutorials dumbed down so much that best practices were sacrificed. Take for instance their use of event handler attributes, such as onclick and onfocus, all the while blatantly ignoring the principle of separation of concerns. This was not even mentioned as a cautionary note to the initiated. Tricks and lies such as this put me back in my career by at least a couple of years.

<button onclick="var hello='world'; alert(hello);">Click me</button>

For years W3Schools piggybacked on the “W3” name to maintain its popularity. Meanwhile, other respected developer resources such as Mozilla Developer Network (MDN) took a diametrically opposite approach of going into deep discussions about each aspect of building blocks of the web. That looked scary initially, but with time your eyes and mind adjusted. I recently finished Part I and II of an exhaustive JavaScript resource called JavaScript.info. It also takes a profound approach similar to MDN’s. In fact, it encourages one to read W3C’s original specifications on various matters. Yes, it’s time consuming but hugely rewarding when applying your learning into practice.

I would like to conclude this rather loooong blog post by saying this:

Do not follow W3Schools or any such simplified online resource without questions. Be extra careful, use common sense, and do compare your learning from other (more detailed) sources. Do not let the details scare you away. Embrace detaily things. But don’t follow even the detaily things blindly.

My customizations are now a WordPress child theme

Posted on Leave a comment

This website uses a theme called Storefront. It’s a minimalistic yet elegant theme from Automattic (the creators of WordPress). I literally browsed hundreds of modern and ‘top’ themes at various sources before falling for this one. It was a good fit in its vanilla form and required only little customizations to suit my needs.

Yesterday I logged into my WP admin after a few days and saw several updates piled up. Storefront was one of them. I didn’t upgrade right away for I knew my customizations would be go away with its previous version. I had committed the cardinal sin of modifying the theme directly.

When I found out about the concept of child themes, I said to myself, “shit, I should have guessed already.” A child theme is one that contains files and assets you want changed in a ‘parent’ theme. So, rather than directly editing style.css or functions.php in a parent theme, one can create a child theme and add their modifications there. That’s what I did then. I created a child theme called Storefront AB, derived from the beautiful Storefront theme.

That was fun. It’s live now!

WordPress is a beautiful, sophisticated software, built to scale to millions of websites globally. A lack of something like the concept of child theme didn’t just feel right. I should have trusted my instincts earlier.

Rails: Two different layouts with two different CSS frameworks

Posted on Leave a comment

I have said it before. Rails is awesome. I find myself creating a new web application in Rails rather than, say, ASP.NET or even PHP much more often. It is intuitive and uncomplicated. Command-line tools and pre-handpicked components allow me to focus more on writing code and implementing business logic.

While working on a Rails application, I was faced with a (reasonably) common situation — having one layout for the end-users and another for administrators. I had my admin pages all written and finished. My CSS framework of choice at the time I started was Ink, mostly because of its fresh UX and Bootstrap‘s aging grid system. When I was about to start with end-user pages, I found out about the release of Bootstrap v4.0.0 (something I had been waiting for since long). The examples made using this version were very much in line with what I wanted for my own purpose. I had made a decision: use Bootstrap for end-user pages and stick to Ink for the admin interface. Realizing this decision in Rails was not as easy as I had thought.

As good as the Rails documentation is, I frequently find myself wanting for more code snippets and examples for things that are apparently presumed to be too basic to explain. After stackoverflowing into the problem and applying some common sense, I came up with the following solution.

Continue reading Rails: Two different layouts with two different CSS frameworks

Tutorial: AJAX with jQuery

Posted on 1 Comment

jQuery is a very powerful JavaScript framework, and to put in their own terms, is The Write Less, Do More JavaScript library. jQuery’s slogan indeed holds true to its claim, as you’ll discover as soon as you start coding using jQuery. Although jQuery has an extensive set of API and a collection of many functions in its arsenal, I would be concentrating more on the AJAX capabilities of jQuery in this tutorial.

Most of the modern websites, irrespective of whether they offer a simple or a complex interface, usually use AJAX for some task or the other. While designing in order to cater to today’s needs, it becomes almost indispensable to use AJAX to make the end-user experience faster and more pleasant. So, if you had been deferring the use of AJAX till now owing to it’s complexity in raw JavaScript, here is your chance to start using it with utmost ease.

It is really amazing to see how much simplified AJAX is with jQuery. The developers have seemingly (and painstakingly) done a lot of hard work behind the scenes to make it easy for the web developer to implement even the most complex JavaScript concepts, including AJAX.

For the purpose of demostrating AJAX, I’ll be making use of a simple web application (that I designed using HTML, PHP, jQuery, CSS and MySQL). I call it the Albums Database.

Continue reading Tutorial: AJAX with jQuery