The following are general guidelines to proper coding practice in Web programming. All programming assignments must follow these good practice guidelines (and so should real-world code).
[ Naming | Structure | DoC | Validation | Mobile-First ]
All file names should be lowercase and contain ONLY letters, numbers, dash, underscore, and one period for the extension. File names should start with a letter and should NOT contain spaces.
aka Separation of Concerns
[ back to top ]
Web programming generally requires working in multiple languages (sometimes simultaneously). Depending on the task at hand you may work in one or more of the following and all within the same Web application.
Because of the use of multiple languages that have very little in common but work together very closely, many developers are tempted to mix languages. DO NOT DO THIS! Even if you see it done by an experienced programmer, or in a textbook, or in an online resource - it is still wrong.
Division (or Separation) of concerns is a design principle for separating an application into distinct "modules", so that each section directly addresses a separate concern, no more, no less. In Web programming our “concerns” are:
Those concerns are further broken down into even smaller concpets until each concern is a single, easily quantifieable concept.
Concerns should not mix. Examples of mixing client-side concerns:
In the code above all of the following violates Separation of Concerns.
This code done properly would look like this.
The code above contains pure HTML. i.e. The “concern” of structuring the page has been separated from formatting and functionality. Then in separate files we add the CSS and JavaScript.
File: main.css
File: main.js
Those files above can now be linked to our HTML using the link tag like so.
Now our concerns are properly separated. This has many advantages.
The following is an example of mixing client-side and server-side concerns. This code will process the PHP portion on the server, and then deliver the result along with the client-side code back to the browser. Do not do this! This is one of the worst examples of mixing concerns as it both violates language and functionality concerns, but also client and server concerns. Correcting this and creating properly structured code will be discussed in class.
Input validation and security are some of the most important topics in Web development. The following are best practice guidelines for real-world applications and required for assignments in Web Development classes.
Mobile-First: Mobile-First means we assume all default CSS and styling is for a mobile device. We code for a very small screen first, not worrying about what it looks like on Desktops. Then when we're done with that, we go back and make exceptions for Desktop view using media queries. Mobile-First is a coding process and has nothing to do with Mobile-Friendly or Responsive design. It is simply stating what we code first as the default case. Read all of the following to learn about Mobile-First.
Mobile Friendly: Mobile-Friendly is a design style that says your pages look well designed and tailored to very small screens. It is not a coding style, it is a design style. It does not mean your application looks bad on large screens, it simply means you application also looks good on mobile devices.
Responsive: Responsive web applications
are one's for which the pages automatically resize based on
the device you are using to view the page
and will also resize dynamically when the browser window is resized.
For example, this site is responsive. Try resizing the window and you will see the page resizes and restructures to keep up with window size.
A simple test for a responsive site is to look for a horizontal scrollbar when the window is made narrower. If you see a horizontal scrollbar anywhere above about 180px, the site is not responsive (or at least not properly responsive). You should not see a horizontal scrollbar on your sites except possibly at extremely small and unrealistic resolutions (180px and below).
All elements in a responsive site should re-arrange and re-size dynamically with window size and with device changes so as to be optimal for that screen/window size.
Mobile-First, Mobile-Friendly, and Responsive are NOT the same things. Mobile-first simply says your CSS is structured so that mobile css is default and other CSS is secondary. Mobile-Friendly says your application looks good and is also tailored to small screens. Responsiveness is how your pages respond dynamically to screen size changes.
It is possible to write Mobile-First and not Mobile-Friendly, or Mobile-Friendly and not Responsive, or any combination of the three concepts described here, however there would be no point to it because it would make a poor quality site and code that is difficult to maintain.
For example, you can write Desktop-First and Responsive, but your code would be much more complex and harder to maintain. You can write Mobile-Friendly and not Responsive, however your code would look terrible on desktop,
Although you can mix and match any <device>-first, <device>-friendly, and responsive or not-responsive, the current accepted best practice today is Mobile-First, Mobile-Friendly, and Responsive.All code produced in Web Development classes must be Mobile-First, Mobile-Friendly, and Responsive.