MC Press Online

Thursday, Mar 23rd

Last updateFri, 17 Mar 2017 12pm

You are here: Home ARTICLES Mobile Mobile - Other Oops! Five Common Mistakes Newbie Mobile Web App Developers Make

Mobile - Other

Oops! Five Common Mistakes Newbie Mobile Web App Developers Make

Support MC Press - Visit Our Sponsors

 

FORUMS
Element Break 290x14

Don't Miss the Latest Books

Visit The MC Press Bookstore

Element Break 290x14

Transform yourself, but watch out for the pitfalls.

This article is not a big pointing finger to shame you about errors you make when you start creating your first mobile apps. This article is meant as a guideline to help you avoid some pitfalls in your work.

As you might know, I am an “old” RPG programmer who has learned some PHP and JavaScript and other web techniques along the way. I do not do Java or Objective-C. I am not very good at object-oriented programming, so my profile would not get me an interview, never mind a job, at Google or Apple.

“But what can you do then?” you might ask. Well, I can read data from an IBM i (DB2), MySQL, or MS SQL database, combine the data, and by using some general tools, publish it in a web browser running on some device. My users can then use the information daily, saving them both time and money.

I have written quite a few articles in MC Press Online about jQuery, Bootstrap, and other web tools over the years, so I will use this article to sum up some of the things I have struggled with along the way.

One comment before I start: Numerous tools are out there that can help you do most of the work, so you do not have to learn all the nuts and bolts of HTML, CSS, and JavaScript. But that requires a budget, as these are not free. In my case, there was no budget, so that was not an option; I had to dig into learning something. Also, as a programmer, I wanted to learn some new tricks.

First Mistake to Avoid: HTML Is Not That Difficult to Master

Learning a new language (if you can call HTML that) can be a challenge, but you should spend some time learning HTML. The fun thing about learning it is that you can enter some code and right away you can see the result in your browser. Learn the tables (take divs later) and the ways to add pictures, links, iframes—all the basic stuff to place data on a website.

Many great sites out there offer the basic knowledge to learn HTML. One of the ones I can recommend is w3schools.com. They offer tutorials as well as quizzes to test your skills. If you want to lean back and enjoy a film, YouTube of course is the place. Do a search for “HTML basic” or “learn HTML,” and you will find a lot of nice people just sitting there waiting to teach you.

Second Mistake to Avoid: Cascading Style Sheets (CSS) Is a Must These Days

CSS is not really a language. It is more the glue that makes your HTML elements display correctly on the page or even in print. Using CSS, you can control where HTML elements can be placed and what size and color they have.

CSS should be stored in external stylesheets and can then serve as the layout master for various webpages, so you’ll be more productive and it will be easy to maintain the layout of the page.

CSS has classes, not like in an OO language, but still it is a way of adding layout properties to various HTML elements in an easy way.

Again, there are many places to learn it. And again, w3schools does a great job. Please note that I have no interest in the site for personal reasons. I just find it very easy to use, and it has a good way of explaining things. Of course, both YouTube and Google can point you to the right CSS place for you.

I repeat: In my opinion, CSS is essential if you want to create a nice-looking webpage in 2017.

Third Mistake to Avoid: JavaScript Adds Dynamic Functionality to Your Page

You must learn and understand JavaScript!

Facebook, Google, and MC Press Online (just to mention a few) would not be working if it weren’t for JavaScript.

If you want to do things like real-time field validation, setting colors, making changes to HTML elements, and making dynamic pages, JavaScript is the language to use.

JavaScript is big, and it has a pretty loose syntax, which sometimes makes it hard to read and understand.
This means that you should carefully plan a programming standard for things that you just not are used to if you are an RPG programmer.

The reason is that JavaScript is interpreted at runtime by the browser, so you do not have a compiler in front of you to catch syntax errors and such, like you have with a compiled programming language.

As an example, you do not have to end a JavaScript line with a semicolon (;). The line will be nicely understood by the browser. That might not seem like a big thing, but it sure can complicate things when it comes to readability and debugging.

One thing that you will notice very soon is that variables and function names are case-sensitive. This means that “customerName” and “CustomerName” are two different variables. In my world, there is no right or wrong on how you decide to construct your variable names. In the old days, I used to underscore (_) my variables, but these days I use camelCase. I have stolen this habit from when I am looking around the Internet for help; it seems to be what most JavaScript programmers do, and I do not want to invent the wheel myself again. JavaScript is not very strict about variables and their types, because you simply do not declare the type of a variable when you start to use it. You can assign a date in one line, a string in the next, and a numeric in the third, and you can work with the variable just fine; that is something very new for an RPG programmer, but when you get started you will soon get the hang of it.

Again, there are many pages to learn from, and again I really think that w3school does a very good job, so have a look here: JavaScript Style Guide and Coding Conventions and JavaScript Tutorial. Also, Stack Overflow is a page you will stumble across. It has answers to almost anything, and Google will help you find the correct page.

Fourth Mistake to Avoid: Your DB Skills Can Serve Data to Web Apps

You need data for your web apps. Not so long ago, the data on your IBM i was all you needed, but that sure is not the case anymore. Today, data is spread all around, in MySQL or MS SQL databases, in Excel files, in CSV files, in XML files, in JSON objects, in web services…and you need to master them all in order to provide your users with the needed information. So you need some tools in your tool belt to bring the data to the web page surface.

The way I do it is very simple. On the IBM i, I use RPG CGI. I use the web APIs provided by IBM to read data from the database and then transform it into either HTML or XML, and I let Apache do the job of sending the data to the requester and then let the web page handle the result and present the data to the user. To me, writing to a display file or to the browser is the same thing. Although the output format is different, it is the same cycle: get some input, read data, process it, and output.

When it comes to the other DB sources mentioned above, you must learn a language that can act the same way as RPG. In my case, PHP was the one. It is pretty easy to learn the basics, and there are so many examples of all you can ever think of on the Internet and even on MC Press Online. Our own David Shirey has written some great tips about the secrets of PHP.

I use PHP the same way as I use RPG: get some input, read the data, process it, and output. This way, the retrieving of data will be transparent to the web app.  “Why is that important?” you might ask. Well, that way, you can change the database layer very easily and even have the same web app running on various databases.

Fifth Mistake to Avoid: Libraries and Frameworks Are Not Bad Things

When you get the hang of JavaScript and CSS, start using frameworks and libraries.

Until now, I have just mentioned “basic” stuff that you must learn and pitfalls to avoid in order to show some data on a webpage. But when it comes to mobile devices like smartphones and tablets, things change radically.  You are now facing things like responsive design, small bandwidth signals, different web browser engines, and all kinds of display sizes.

I once tried to make my pages fit the requirements by hand-coding it, but it was such a daunting task that I never got it to work the correct way. Then I got involved in a project where somebody spoke about something called jQuery, and that became my savior when it came to creating dynamic functionality.

One of the most important things to learn when starting to use jQuery is AJAX. To me, that is the cornerstone in all web programming, and it is a must to master (in my opinion).

To handle all the responsive tasks, Bootstrap is the one for me. It takes a little effort to get the hang of, but when you learn the grid system and the main classes, you are on your way.

I have also written articles about jQuery Mobile, and I like that very much, but the thing about it is that it fits only mobile devices and does not look very good on a PC.

So, to avoid any mistakes, I have a golden rule: If your web app is to run just on a mobile device, jQuery Mobile is a great solution, but if you want to use it on both PCs and mobile devices, Bootstrap is a very good solution.

Let’s Sum It Up

I know this has been a very long article, and I really hope that you still are with me to this point. Creating web apps and trying to avoid mistakes are not as easy as it might seem.

To me, it has been a journey of transforming myself from a green-screen programmer who (still) loves DDS and RPG and the way the IBM i just helps you do things in an easy and structured way to a web/mobile programmer in a world of various databases, web technologies, new ways of designing screens, and security issues you never have to deal with in a IBM i world.

It might sound like a lot of work, and sure it is, but I tell you it is all worth it. And the first time you enter a URL that fetches data from various platforms and you see the result on your smartphone, your heart will make an extra beat.

Jan Jorgensen

Jan Jorgensen is one of the owners of www.reeft.dk, which specializes in mobile and i5 solutions. He works with RPG, HTML, JavaScript, Perl, and PHP. You can reach him at jj@reeft.dk

 

More Articles By This Author
Related Articles
BLOG COMMENTS POWERED BY DISQUS