Re: Compiler warnings

Jack, W8TEE
 

Writing that in plain ansi C is just more error prone work than it needs to be.

What is your suggestion to fix that?

There are elements of C++ that I don't like and tend to be misused (e.g., multiple inheritance). However, one can practice the OOP concept of encapsulation even within the confines of ANSI C, and that's a very good thing. Perhaps the two biggest mistakes I see made by beginning programmers are 1) the reliance on globally-scoped variables and 2) trying to write functions that do too much (i.e., they are not "cohesive"). A globally defined variable means that every single statement in the program has the ability to change that variable. It's like placing a hooker at the top of the program and giving every statement in the program a $50 bill and, after something goes wrong, trying to find out who the father of the error is. Encapsulation at least lessens the scope of the error search.

If you can't tell someone what a function does in two sentences or less, it is not cohesive. Another tip off is a function that has a bunch of variables passed to it, especially variables that are little more than flag variables. Writing Swiss Army knife functions may seem like a good idea, but they are almost always too complex for the task at hand and, because they try to do too much, they are rarely reusable.

Just paying attention to those two things as you write code will make the code less error-prone. Personally, I've used a lot of different languages over the years and I still think C is the best. There must be some agreement, otherwise it wouldn't be the first language most companies resurrect on a new processor and it wouldn't have lasted over 40 years.

Jack, W8TEE

On Monday, July 2, 2018, 12:08:58 PM EDT, ajparent1/KB1GMX <kb1gmx@...> wrote:


As someone that cut their teeth is the '70s with K&R C the biggest thing I see is poor programming
not poor programming languages.  I also grew up in systems where resources are scarce and 
adding them was expensive.  So pardon me if I think 32K of code space, 1k of eeprom and 2K
of ram is a lot of space.  Sure beats 8749 with 2K of program Eprom, 128byts of ram and a timer.

OOP is not a bad word but it may be very stupid in a machine with maybe 2K of ram, code
accordingly.  The problem is coders (not programmers) that figure if it doesn't fit use a bigger
chip.  Then again if the objects are small it can be useful.  For example a Arduino Mega2650
running a two axis (elevation and azimuth) antenna control that serves out position and
tracking as a web page.  No it isn't full and it even gets the TLEs for the Sat to track via
the web page.  One of these days I need GPS and a electronic compass so it knows
where it is and what way is north so I can move it with out calibrating it afterwards.
Writing that in plain ansi C is just more error prone work than it needs to be.


Allison

Join BITX20@groups.io to automatically receive all group messages.