PDA

View Full Version : Good Guidelines to follow when Programming


FreezeWarp
04-17-2008, 10:42 PM
This thread was posted to save my work.

1. Make sure it is usable on Internet Explorer 5+, Opera 7+, Firefox 1+, and Safari/Konqueror (uncommon, not as important)
....a. Keep the languages you use compliant with all browsers. NEVER use CSS3 and HTML 5
....b. Use common image forms, don't use .fbm (Fuzzy Bitmap), or .ic1, .ic2, .ic3 (Low, Medium, and High Resolution Image Graphic)
....c. Be careful with Microsoft fonts. Macs and Linux Users can't use them unless they don't load software like OpenOffice.
....d. And use code fixes for different browsers. However, you probably won't use one for anything but internet Explorer (are we surprised?).
2. Keep things fast. Here is a good formula:
....a. Use CSS for the graphic element. Stay away from images if you are merely trying to get data across.
....b. Use minimal Javascript, though still use it as you can't do nothing if you don't use some of it.
....d. Absolutely NEVER use FLASH if it loads automatically.
....e. Everything else should be HTML and Database (php, mysql) as that should be all you need

Kaboom
04-17-2008, 10:50 PM
Certain things are done in different ways on different browsers, just so you know.

Kaboom
06-16-2008, 08:51 AM
BUMP!
Here are my responses to your suggestions:

1. Make sure it is usable on Internet Explorer 5+, Opera 7+, Firefox 1+, and Safari/Konqueror (uncommon, not as important)
You can in fact detect a user's browser (see http://www.adamhaskell.net/getinfo.php for details) and redirect to a different page if you have browser-specific elements. This saves time for 1.d.

....a. Keep the languages you use compliant with all browsers. NEVER use CSS3 and HTML 5
There is no problem with using these latest versions, as long as you only use elements which exist in previous versions. If you must use new elements, use the getinfo stuff to make sure the user can view it and redirect if not. (As a side note, I prefer HTML5 because the doctype tag is simply <!DOCTYPE HTML>

....b. Use common image forms, don't use .fbm (Fuzzy Bitmap), or .ic1, .ic2, .ic3 (Low, Medium, and High Resolution Image Graphic)
The recommended image format is PNG. However, BMP is better for icons, JPG is excellent for photos, and GIF is the only format to support animations. An interesting note: the GIF format is patented, so theroretically you should be paying royalties every time you use it!

....c. Be careful with Microsoft fonts. Macs and Linux Users can't use them unless they don't load software like OpenOffice.
Use Microsoft fonts if you will, but be sure to define a substitute font in case the user doesn't have the font installed. This applies to all fonts, and you should always have a failsafe defined (such as Times or Arial)

....d. And use code fixes for different browsers. However, you probably won't use one for anything but internet Explorer (are we surprised?).
You can have completely different pages which are redirected to depending on browser (see above), but be aware that it isn't foolproof.


2. Keep things fast. Here is a good formula:
....a. Use CSS for the graphic element. Stay away from images if you are merely trying to get data across.
How about: use CSS for everything! Avoid local styling wherever possible (use classes instead). Also, most attributes in tags are deprecated to make way for CSS. Use it now to avoid having to redo everything in a few years' time!

....b. Use minimal Javascript, though still use it as you can't do nothing if you don't use some of it.
If you have a page which requires JS, be sure to use <NOSCRIPT> to display a message if JS is off. Another trick to be used in conjunction is to use JS to generate the page, which means that there will be no errors or ugly content if JS is off.

....d. Absolutely NEVER use FLASH if it loads automatically.
That should be left to your own judgement. FLASH can be good, but can also be very bad. Use at your own risk!

....e. Everything else should be HTML and Database (php, mysql) as that should be all you need
Words of great wisdom!

Another comment: You can use the getinfo stuff to make sure that the user's browser supports elements such as tables, JS, frames and the like. However, I noticed the PSP returns NULL when asked if it supports JS, frames..., so I advise checking if it's a WAP device beforehand.
Also: You can use the PHP trigger_error( $error_msg, $error_level) method to alert people to potential problems. $err_msg is the error message to display, and $error_level is one of the following:
- E_USER_NOTICE: The lowest level. Outputs a notice and continues running.
- E_USER_WARNING: Same as above, but used to designate a potentially fatal error.
- E_USER_ERROR: A fatal error, the script stops and the page is displayed as it has been built so far.

Any questions: do PM me!

DX-MON
06-16-2008, 09:02 AM
The recommended image format is PNG. However, BMP is better for icons, JPG is excellent for photos, and GIF is the only format to support animations. An interesting note: the GIF format is patented, so theroretically you should be paying royalties every time you use it!

Kaboom, your comment about GIF is WRONG, the patent ran out 4 years ago.....

see http://en.wikipedia.org/wiki/GIF for more on that format and it's now run-out patent.

Also, it wasn't the format itself that was patented, it was a compression method it could employ that was, the LZW algorithm.

Kaboom
06-16-2008, 09:06 AM
Oh, did it? Never mind, nobody cared anyway! I always use PNG except for anims. It interlaces better, I think... and the W3C "wishes web designers use it".

DX-MON
06-16-2008, 09:09 AM
Now, for my 2 cents on good programming practices, this time it's C/C++....


Don't use a compressed format (no if (a == b) {
statements;
})
if you have to use brackets, use the form if (a == b)
{
statements;
}
as from that it's always clear as to what each braket belongs to.
Always comment upon the code, not just for others sakes, but for yours in the future
Whenever you have to do complex things, split it up into separate functions
NEVER with hold on using switch/select statements
If you're thinking that you've not got enough checking happening in your code, you don't.... never think that lots of if statemnts are bad, they aren't.
too many functions are bad, you're probably repeating something, or not optimizing it properly.


If you do the above in C/C++ then you will get good, optimized code out of any compiler, and it'll always be easy to debug.

FreezeWarp
06-16-2008, 01:53 PM
@Kaboom - I have to disagree with displaying pages differently for different browsers. It works, but it takes up space and time and in all honesty, should you need to?

In addition, CSS can slow a page's load if used too much. I really can't phrase what I'm trying to say right (so don't start shooting at me), but rarely use inline css and only add names in an external file if they will reoccur often.

Kaboom
06-16-2008, 03:05 PM
Space is not a problem with Bluehost (and I think others), since you get infinity bytes of it. As for time, it takes at most half a second to get the browser data and to redirect, since there's nothing sent to the browser. Therefore, give or take a second, the loading time is unchanged.

As for CSS, it is much faster than the deprecated attributes, as long as you use it efficiently.

PS I'm not shooting you, I'm making suggestions based on yours :p

FreezeWarp
06-16-2008, 03:07 PM
Space is not a problem with Bluehost (and I think others), since you get infinity bytes of it. As for time, it takes at most half a second to get the browser data and to redirect, since there's nothing sent to the browser. Therefore, give or take a second, the loading time is unchanged.

As for CSS, it is much faster than the deprecated attributes, as long as you use it efficiently.

PS I'm not shooting you, I'm making suggestions based on yours :p
Actually I was referring to the coders time, its just not worth it. It'd be much faster if the browsers were all made to standards.

True, though a lot of depreciated values really aren't good in the first place, such as blink tags.

Kaboom
06-16-2008, 03:13 PM
Argh, not the dreaded <BLINK>! Anyway, anyone can do that with JS and it would work with no problems at all on all browsers, not just Netscape.

As for the matter of the programmer's time, I'd say it depended more on patience...