Space/Science — HabitableZone

Space/Science » in reply to No, that code snippet will actually run...

re: No, that code snippet will actually run...

I didn't say it wouldn't run on all operating systems. If memory serves, you'll get a general protection fault in Windows but a Linux/Unix system may just let you get away with memory corruption. When you write past the end of an array, you're overwriting whatever happens to be in that memory location. If the OS doesn't catch it, you'll have a hell of a time isolating why your program keeps crashing (if it overwrites code) or why your program keeps producing wierd results due to overwritten data.

Like I mentioned, C is still a good language for low level programming such as OS internals due to the low overhead and fast performance. It's also good for embedded controllers that have limited system resources. However, if you're talking about writing GUI applications, C is hardly a good choice, IMO. An object-oriented language like C++ is better for that type of programming. If you're talking about number crunching, developing the math libraries in C and calling them from a C++ shell would be a good compromise.

Optimizing programs can be important, but it's easy to waste a lot of time. There's an old programming axiom that "90% of the work is done by 10% of the code" (although some use 80/20 respectively), primarily in loops. If you optimize those sections, you'll get the greatest return on your optimization effort. Most modern compilers do a pretty good job of optimizing loops, but good algorithm development and programming practice can still improve things somewhat. As for the rest of the program, most of that is spent on I/O, where you're limited by hardware performance or even worse, user input. Optimizing that code is usually a waste of time because the system is waiting on slow devices. What are you going to do, wait faster?

There is no one language that's best for all circumstances, language zealots aside. C is a good language for several domains, but is outdated for mainstream application development.

As your code snippet shows, it's easy to write essentially unreadable code in C that will still function. They even had (and may still have) contests for producing obfuscated C code. However, that code is difficult to maintain and is often fragile. If one of my students turned in code like that, I'd give them an F. If a programmer working for me submitted code like that, they'd get smacked around and perhaps fired. Unmaintainable code has no place in a professional programming environment. I programmed for over 20 years and have no patience for crap code.

Log in or register to post.

The whole thread (45 posts)