Posted by Morris Dovey on December 26, 2006, 5:16 pm
| I use BASIC for calcs and TMY2 simulations. Readability is
important,
| and floating point and log and trig functions. The platform cost
isn't
| important for design calcs, but low cost and low power are important
| for things like a smart whole house fan controller.
Readability is more or less a matter of writing code to be readable,
regardless of language. Here's a transliteration of one of your recent
snippets:
#include <stdio.h>
#include <math.h>
int main(void)
{ double panes, sun, loss;
for (panes=1; panes<; panes++)
{ sun = 1000 * pow(0.9, panes);
loss = 24 * (70 - 30) / panes;
printf("%.0lf %8.4lf\n", panes, sun - loss);
}
return 0;
}
Following the Borland example, some implementations of C (for CPUs
without FPUs) include emulation code. I've written a couple of
software floating point libraries in C to do basic operations (add,
subtract, multiply, divide, square root, and sine/cosine) and they're
not exactly socket surgery.
For one-off projects, none of this probably matters very much. OTOH,
if the object is to produce large quantities and to achieve
performance objectives while using a slower uC, then the savings can
be huge.
--
Morris Dovey
DeSoto Solar
DeSoto, Iowa USA
http://www.iedu.com/DeSoto
Posted by Rod Speed on December 27, 2006, 1:27 pm
>> I use BASIC for calcs and TMY2 simulations. Readability is important,
>> and floating point and log and trig functions. The platform cost
>> isn't important for design calcs, but low cost and low power are
>> important for things like a smart whole house fan controller.
> Readability is more or less a matter of writing
> code to be readable, regardless of language.
Yes, but dinosaur Basic is harder to produce clean readable code
with, so that doesnt happen in practice with amateurs like Nick.
> Here's a transliteration of one of your recent snippets:
> #include <stdio.h>
> #include <math.h>
> int main(void)
> { double panes, sun, loss;
> for (panes=1; panes<; panes++)
> { sun = 1000 * pow(0.9, panes);
> loss = 24 * (70 - 30) / panes;
> printf("%.0lf %8.4lf\n", panes, sun - loss);
> }
> return 0;
> }
> Following the Borland example, some implementations of C
> (for CPUs without FPUs) include emulation code. I've written
> a couple of software floating point libraries in C to do basic
> operations (add, subtract, multiply, divide, square root, and
> sine/cosine) and they're not exactly socket surgery.
> For one-off projects, none of this probably matters very much.
The ones handed out to others are just the ones that
need to be readable, if only to check the logic etc.
Corse he should be using a spreadsheet, not a progamming language.
> OTOH, if the object is to produce large quantities
> and to achieve performance objectives while using
> a slower uC, then the savings can be huge.
That has nothing to do with whether code is readable or not.
Posted by Rod Speed on December 27, 2006, 1:53 pm
>>>> I use BASIC for calcs and TMY2 simulations. Readability is
>>>> important, and floating point and log and trig functions. The
>>>> platform cost isn't important for design calcs, but low cost and
>>>> low power are important for things like a smart whole house fan
>>>> controller.
>>> Readability is more or less a matter of writing
>>> code to be readable, regardless of language.
>> Yes, but dinosaur Basic is harder to produce clean readable code
>> with, so that doesnt happen in practice with amateurs like Nick.
> I think it's less a matter of difficulty than motivation.
Its both. Most of those who continue to use a dinosaur Basic cant
even grasp the concept of what decent readable code is about.
> It's possible to use the same techniques to produce
> readability in BASIC source code as are used in other
> programming languages (indentation, whitespace, etc)
The end result is a lot cruder with a primitive language
like dinosaur Basic and a lot more effort that dinosaurs
like Nick cant even manage to grasp as well.
>>> Here's a transliteration of one of your recent snippets:
>>> #include <stdio.h>
>>> #include <math.h>
>>> int main(void)
>>> { double panes, sun, loss;
>>> for (panes=1; panes<; panes++)
>>> { sun = 1000 * pow(0.9, panes);
>>> loss = 24 * (70 - 30) / panes;
>>> printf("%.0lf %8.4lf\n", panes, sun - loss);
>>> }
>>> return 0;
>>> }
>>> Following the Borland example, some implementations of C
>>> (for CPUs without FPUs) include emulation code. I've written
>>> a couple of software floating point libraries in C to do basic
>>> operations (add, subtract, multiply, divide, square root, and
>>> sine/cosine) and they're not exactly socket surgery.
>>> For one-off projects, none of this probably matters very much.
>> The ones handed out to others are just the ones that
>> need to be readable, if only to check the logic etc.
> There's more to the issue if the code is anything other than just a
> throw-away "doodle". Readability is an important part of "maintainability".
Corse it is, but that isnt what we are discussing with what Nick produces.
> When code is revisited (for correction, expansion of function,
> etc) it needs to be readily understood by the maintainer,
> who may or may not be the original author.
Yes, and in the situation being discussed, what Nick produces,
it isnt the original author that needs the readabilty, its those who
are either deciding if the code is appropriate, or those that need
to change it to make it more appropriate to their circumstances,
what they are attempting to model etc.
> If the code is such a mess that it can't be understood/maintained,
> the best that can be hoped for is to re-develop from scratch (expensive);
> and the very worst that can happen is that a maintainer "take his best shot"
> at patching in something he hopes will effect the appropriate change(s).
> This latter usually has the effect of making the code still less
> maintainable - and frequently introduces a fresh set of problems.
Sure, but thats a separate issue to what is being discussed, what Nick
produces and what language is more appropriate for that sort of thing.
> All this is difficult for people who only dabble at coding to grasp.
Yep, and most never will.
>> Corse he should be using a spreadsheet, not a progamming language.
>>> OTOH, if the object is to produce large quantities
>>> and to achieve performance objectives while using
>>> a slower uC, then the savings can be huge.
>> That has nothing to do with whether code is readable or not.
> You're right - readability is only one of the factors that
> contribute to the worth of a program. Still, it /is/ important.
Not with what is being discussed, what Nick produces.
> In the context of Nick's stated objective, the ability to
> produce a reliable controller at a cost that allows the
> greatest number of people to afford and use it /is/ the point.
That isnt what is being discussed either, its his turds he drops
which purport to show that a particular approach to a design
is viable in the sense that it will achieve the results wanted.
Posted by Rod Speed on December 27, 2006, 1:56 pm
> Jeff wrote
>> 2) Whatever the language chosen for any of our solar projects, on whatever
platform, it would
>> have more than enough speed to suit our needs. The most critical thing any of
us do is Duane's
>> trackers and I doubt even they need much horsepower.
> Duane's trackers are, at worst, a couple of logic gates and
> don't even require a microcontroller, let alone source code.
> I wonder... What solar application would require a CPU?
It may not require it, but it would normally be a better result
with one, if only to handle the unusual situations better.
Posted by daestrom on December 28, 2006, 12:36 pm
> |
> | >> I use BASIC for calcs and TMY2 simulations. Readability is
> important,
> | >> and floating point and log and trig functions. The platform cost
> | >> isn't important for design calcs, but low cost and low power are
> | >> important for things like a smart whole house fan controller.
> |
> | > Readability is more or less a matter of writing
> | > code to be readable, regardless of language.
> |
> | Yes, but dinosaur Basic is harder to produce clean readable code
> | with, so that doesnt happen in practice with amateurs like Nick.
> I think it's less a matter of difficulty than motivation. It's
> possible to use the same techniques to produce readability in BASIC
> source code as are used in other programming languages (indentation,
> whitespace, etc)
> | > Here's a transliteration of one of your recent snippets:
> |
> | > #include <stdio.h>
> | > #include <math.h>
> |
> | > int main(void)
> | > { double panes, sun, loss;
> |
> | > for (panes=1; panes<; panes++)
> | > { sun = 1000 * pow(0.9, panes);
> | > loss = 24 * (70 - 30) / panes;
> | > printf("%.0lf %8.4lf\n", panes, sun - loss);
> | > }
> | > return 0;
> | > }
> |
> | > Following the Borland example, some implementations of C
> | > (for CPUs without FPUs) include emulation code. I've written
> | > a couple of software floating point libraries in C to do basic
> | > operations (add, subtract, multiply, divide, square root, and
> | > sine/cosine) and they're not exactly socket surgery.
> |
> | > For one-off projects, none of this probably matters very much.
> |
> | The ones handed out to others are just the ones that
> | need to be readable, if only to check the logic etc.
> There's more to the issue if the code is anything other than just a
> throw-away "doodle". Readability is an important part of
> "maintainability". When code is revisited (for correction, expansion
> of function, etc) it needs to be readily understood by the maintainer,
> who may or may not be the original author. If the code is such a mess
> that it can't be understood/maintained, the best that can be hoped for
> is to re-develop from scratch (expensive); and the very worst that can
> happen is that a maintainer "take his best shot" at patching in
> something he hopes will effect the appropriate change(s). This latter
> usually has the effect of making the code still less maintainable -
> and frequently introduces a fresh set of problems.
> All this is difficult for people who only dabble at coding to grasp.
Having had to maintain other people's code, (some of it 20 year old FORTRAN
'66), I can certainly agree with this. Heck, over the years I've had to go
back and maintain my own old code and sometimes wished I had done a better
job 15 years ago when I wrote it the first time :-) The more spaghetti, the
more likely a 'fix' is going to create yet another problem.
Another thing to consider though is reusability. Nick often starts a new
thread with a new simulation of a new idea. All well and good, but often
leaves out some detail of the model that may/may-not be relevent. If
something like reusable objects were his mainstay, then each 'refinement' to
a particular piece would not be lost each time he 'starts over'.
Furthermore, when a project uncovers a need for a refinement to the modeling
of something (say, adding radiant heat transfer to/from a surface where
before only conduction/convection were modeled), all previous
models/projects can quickly be recompiled/linked to use this new refinement.
(as long as the interface is maintained, and even if it needs to be changed,
it's simpler than starting from scratch). But Nick's code often 'reinvents
the wheel' each time. That's prone to errors.
Good production-quality coding is not easy. Often, it's a choice between
'what we have time to do', and 'what we should do'. Forcing oneself to
refactor, split off another class, cut-out duplicate code and put in a
separate subroutine/function/method, etc... is the price one pays for
maintainability and reliability. Somewhat like fully normalizing a database
structure (no duplicate information!!!), once in a while good structures
cost a couple of CPU cycles. But more often then not it also prevents/finds
bugs before it goes to testing, much less production. But even so, a few
careful 'GOTO's, just like an extra column in a table, can sometimes be
justified for performance.
daestrom
>> and floating point and log and trig functions. The platform cost
>> isn't important for design calcs, but low cost and low power are
>> important for things like a smart whole house fan controller.
> Readability is more or less a matter of writing
> code to be readable, regardless of language.