Back when I was regularly programing in C and/or C++, I regularly had to use #define and #ifdef statements to account for differences in operating systems the code may execute. A simple example is:
#ifdef _SYS5
printf("%s\n", "This is a Unix System 5 system");
#end
#ifdef _DGIX
printf("%s\n", "This is a Digital Unix system");
#endif
#ifdef _SUNOS
printf("%s\n", "This is a SunOS system");
#endif
What the above means is when the code is compiled, only the code relevant to the system type is included. Above, if the code was running on a Unix System 5 system,
"This is a Unix System 5 system"
would be printed. If it was a Digital Unix system,
"This is a Digital Unix system"
would be printed. If it was a SunOS system,
"This is a SunOS system"
would be printed. It was hard, to me, to read code that had a lot of #ifdef's in the code, so what I started to do was write one file for each system. If the code was portable across all systems, there would only be one file. If there was code that had to have different code, I would create files for each system. I used a naming convention such as, "calculate_sys5.c" for System 5 code, "calculate_dgix.c" for Digital Unix code, etc. Essentially I would #ifdef the entire file. I also had a "default" file that would be compiled if none of the systems matched. I always purposefully generated runtime errors in that code so I would know I messed up with the #ifdef. People hated it but it made it easier on me.
So what does that have to do with JavaScript? Well, with the number of browsers out there, when you create JavaScript methods, many times you have to determine what browser and what version of the browser the code is running in before you can make certain calls, especially when you have to get to the DOM. Frankly, just like the #ifdef took some fun out of programming, so does worrying about browser versions and operating systems in JavaScript. Only with JavaScript, I think it is much more aggravating. So, unless I have to, I leave the client side alone.
Recent Comments