Den 2021-01-08 kl. 21:02, skrev Eli the Bearded:
> I've been doing some Arduino programming recently, and while I'm writing
> C, it's clearly C++ overall because of the libraries I'm using, some of
> which are overloading stuff.
And the compiler used is g++.
So yes it is a kind of c++
> One of those does things I find awkward
> because it tries to invoke the int method at times I don't want. Eg
> it wants zero to be the ASCII zero instead of ASCII null unless I write
> it as "byte(0)".
And that is of course since you are not used o a (more) strongly typed
language. But in the end - it is much better to fight the compiler than
to work with the debugger. Strongly typed and successful compilation
usually means correct execution.
But with strongly typed I do not mean c++ and Java - they are strong typed.
Strongly - that is Ada - is where you can have numeric ranges like
type latitude_type is new Float range -90.0 .. 90.0;
type longitude_type is new Float range -180.0 .. 180.0;
type country_type is (dk,uk,se,de,it,bu,sa,...);
and get compile time error for the following
function Where_Am_I(longitude : longitude_type;
latitude : latitude_type) return Country_Type;
longitude : longitude_type := 42.0;
latitude : latitude_type := 25.0;
country : country_type;
in a not strongly types language
country := Where_Am_I(latitude, longitude);
would pass - even if arguments are reversed and, even worse - return
sa (saudi arabia). which is just plain wrong compared to the declarations.
In a strongly types language - the compiler would say no - you pass in
the wrong types compared to the definition.
a correct call
country := Where_Am_I(longitude,latitude);
will return bu (Bulgaria)
The compiler would save you from
* disaster if this was a plane and the code was about the destination
and length there and how much fuel to put in.
* it protects you against badly written unit tests where swapping
coordinates would yield the same country
* it makes it NOT to go to production
* It makes it unnecessary to spend hours or days in the debugger.
In short - a very strongly typed language is your best friend when
programming anything having more than 1_000_000 locs.
without it - it becomes a nightmare to maintain.
--
Björn
--- SoupGate-Win32 v1.05
* Origin: Agency HUB, Dunedin - New Zealand | FidoUsenet Gateway (3:770/3)
|