Tuesday, December 20, 2022

Digest for comp.lang.c++@googlegroups.com - 25 updates in 6 topics

Kaz Kylheku <864-117-4973@kylheku.com>: Dec 20 01:49PM

> 6) What are the three parts of a for statement and which of them are
> required?
 
Check your fingers; I count nine:
 
for ( init ; test ; step ) stmt
1 2 3 4 5 6 7 8 9
 
--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca
David Brown <david.brown@hesbynett.no>: Dec 20 08:23AM +0100

On 19/12/2022 21:54, Paavo Helde wrote:
 
>>    string += c_utf8::from_utf16(utf16arg);
 
> And what does 'c_' mean? Apparently another "universally understood
> abbreviation" which I would not know without context.
 
I'd guess it meant "C string". But presumably if you had to read or use
Scott's code, you /would/ have the context, and then you would know what
it meant.
"Chris M. Thomasson" <chris.m.thomasson.1@gmail.com>: Dec 19 11:39PM -0800

On 12/19/2022 11:11 PM, Chris M. Thomasson wrote:
> On 12/19/2022 10:35 PM, Juha Nieminen wrote:
>> Chris M. Thomasson <chris.m.thomasson.1@gmail.com> wrote:
>>> Here is some older work of mine, are the variable names too verbose?
[...]
> for use in a volumetric renderer:
 
> https://pastebin.com/raw/v1NNbDRz
 
> Some older C99 of mine. When you get some time, does it run for you?
[...]
 
Oh, crap. That one only creates a single slice of the Mandelbulb at z
axis .1. Sorry!
____________________________________
// Gain the field...
void
ct_iterate_mbulb_plane(
struct ct_plot* const plot,
unsigned int n
){
for (long y = 0; y < plot->canvas->height; ++y)
{
for (long x = 0; x < plot->canvas->width; ++x)
{
double complex cz = ct_project_to_xy(plot, x, y);
 
// Well, our per slice coords...
struct ct_vec3 z;
 
z.x = creal(cz);
z.y = cimag(cz);
z.z = 0.1;
 
// Iterate the slice
ct_iterate_mbulb_pixel(plot, z, z, x, y, n);
}
}
}
____________________________________
 
Fixed at z-axis .1
 
 
Sorry. I think I posted my code that dumps out a volumetric that creates
my experimental power stack:
 
https://www.fractalforums.com/index.php?action=gallery;sa=view;id=17187
 
Can you see the comments in the forum? I posted pseudo-code for it
there. Or the resulting compilation of 3d objects created from it?:
 
https://nocache-nocookies.digitalgott.com/gallery/17/11687_15_03_15_8_18_09.jpeg
 
Here is one where I generate a volume:
 
https://pastebin.com/raw/07TWQQYF
 
Notice the following function:
 
/* The Animation Driver
___________________________________*/
void ct_anime(
struct ct_plot* const plot,
unsigned long frame_n,
unsigned long n
){
assert(frame_n > 0);
 
double zmin = 0.;
double zmax = 1.;
double zdif = zmax - zmin;
double zbase = zdif / (frame_n - 1.);
 
double pmin = 2.;
double pmax = 10.;
double pdif = pmax - pmin;
double pbase = pdif / (frame_n - 1.);
 
char fname[256] = { '\0' };
 
for (unsigned long frame_i = 0; frame_i < frame_n; ++frame_i)
{
double zaxis = zmin + zbase * frame_i;
double power = pmin + pbase * frame_i;
 
sprintf(fname, "ct_anime_%lu.ppm", frame_i);
 
printf("ct_anime: %lu of %lu, zaxis(%lf), power(%lf), (%s)\n",
frame_i, frame_n, zaxis, power, fname);
 
fflush(stdout);
 
struct ct_rgb black = { 0, 0, 0 };
ct_plot_clear(plot, &black);
 
ct_iterate_mbulb_plane(plot, zaxis, power, n);
 
ct_canvas_save_ppm(plot->canvas, fname);
}
 
printf("\n\nct_anime complete! %lu frames: \n", frame_n);
fflush(stdout);
}
Paavo Helde <eesnimi@osa.pri.ee>: Dec 20 10:22AM +0200

20.12.2022 08:16 Juha Nieminen kirjutas:
>> it contacts the satellite first.
 
> Most people who write and read code (which is what we are talking about
> here) don't know what HDMI is? Right.
 
Of course. For writing code there is no need to know what HDMI is, ergo,
there exist people who write code and don't know that. I personally know
some.
 
Do you know what FIDA means? (Hint: it's not related to football.)
Should these people avoid the acronym FIDA in their code doing FIDA,
just because some random guy on the internet has not heard about it?
 
 
> I'm sorry, but you are not going to convince me to write less readable
> code by arguing that "most people I know don't know what HDMI is".
> I cannot even understand why you are presenting such a stupid argument.
 
It is not my goal to convince you to write less readable code, quite the
opposite actually. I'm just pointing out that what means 'less readable'
is not universal, but depends on the people and on the context.
 
Nobody here argues with you that one should write readable code and that
over-using of auto or any other thing is bad. It's in the name. The
opinions differ on what is 'readable' and what is 'over-use'.
Keith Thompson <Keith.S.Thompson+u@gmail.com>: Dec 20 01:01AM -0800

> understand than names consisting of full words.
 
> I'm sorry, but I am not going to be convinced of that. I'm not insane.
> (There's another "insult", you're welcome.)
 
Feel free to pretend you've won an argument.
 
*PLONK*
 
--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for XCOM Labs
void Void(void) { Void(); } /* The recursive call of the void */
Muttley@dastardlyhq.com: Dec 20 10:18AM

On Tue, 20 Dec 2022 05:58:34 -0000 (UTC)
>100% code coverage (something that *really* requires understanding what
>every single line of code is doing) as your full-time job, 40 hours a
>week, non-stop, since the 90's?
 
Not many jobs involve green field coding. 90% of them are debugging and/or
adding features to pre-existing code.
 
>You must have the most boring life I can imagine.
 
>Or, alternatively, you don't know what you are talking about.
 
I've coded to SIL4 military level (which IS extremely boring) so I think I have
a vague clue what I'm talking about.
 
>You can't write unit tests for existing code unless you really,
>really understand what the code is doing.
 
No shit. Any more gems from your wealth of experience? Perhaps "You can't
write C++ unless you know C++". Or maybe "Gotos can be dangerous"?
Muttley@dastardlyhq.com: Dec 20 10:21AM

On Tue, 20 Dec 2022 06:23:48 -0000 (UTC)
>What's wrong with people? This is absolutely insane.
 
Nothing is wrong with us, we're simply disagreeing with you. If you have a
problem with that then I would suggest you're suffering from some kind of
narcissistic personality disorder and you should get help.
Juha Nieminen <nospam@thanks.invalid>: Dec 20 10:39AM

> Nobody here argues with you that one should write readable code and that
> over-using of auto or any other thing is bad. It's in the name. The
> opinions differ on what is 'readable' and what is 'over-use'.
 
It's fine to have differences of opinion, but this thread has gone to
quite ridiculous lengths. Some people seem to have taken as their mission
to argue to the end of time how utterly wrong I am.
 
It's not a conversation like "I understand what you are saying, but
here's my differing view on it". A good example of this is trying to
"disprove" what I have been saying by coming up with "counter-examples"
which contain artificially long variable names with a lot of needless
redundancy in them. That's certainly not understanding and acknowledging
what I'm saying (even if one disagrees with it). It's arguing in bad
faith.
Juha Nieminen <nospam@thanks.invalid>: Dec 20 10:44AM

> Feel free to pretend you've won an argument.
 
> *PLONK*
 
I just love this.
 
A: "You have insulted me!!!"
B: "It's not an insult."
C: "Yes it is! It's an insult!"
B: "It wasn't intended as an insult, but fine, if you want to take it
as an insult, fine. I don't really care."
D: "PLONK!!!!!"
 
The more this thread continues, the more insane it becomes.
 
And all this because I expressed my opinion on what I think makes code
harder to understand. Incredible. Has everybody just gone completely
insane all of a sudden? I can't even believe this thread, seriously.
Juha Nieminen <nospam@thanks.invalid>: Dec 20 10:46AM


> Nothing is wrong with us, we're simply disagreeing with you. If you have a
> problem with that then I would suggest you're suffering from some kind of
> narcissistic personality disorder and you should get help.
 
You are the one whining previously about me "insulting" you.
 
But apparently hypocrisy is A-ok.
 
And all this because I expressed my opinion on what makes code less
readable and understandable. This thread is completely insane.
I cannot even believe it.
Juha Nieminen <nospam@thanks.invalid>: Dec 20 10:49AM

> No shit. Any more gems from your wealth of experience? Perhaps "You can't
> write C++ unless you know C++". Or maybe "Gotos can be dangerous"?
 
Are you even aware of how you are acting, because I expressed my
opinion on what makes readable and unreadable code?
 
Just stop for a moment to read what you are writing. Consider what kind
of condescending tone you are using... because someone expressed his
opinion on coding style.
 
(Yes, you are just going to answer "you did it too!" Spare me.)
Muttley@dastardlyhq.com: Dec 20 11:19AM

On Tue, 20 Dec 2022 10:49:42 -0000 (UTC)
>of condescending tone you are using... because someone expressed his
>opinion on coding style.
 
>(Yes, you are just going to answer "you did it too!" Spare me.)
 
Go have a long look in the mirror. This conversation is over.
"Öö Tiib" <ootiib@hot.ee>: Dec 20 03:28AM -0800

On Monday, 19 December 2022 at 17:55:23 UTC+2, Juha Nieminen wrote:
> gets buried in the code and it's harder to find and remember what
> it is. Heaven forbid you mix it with 'j'. Now you are just writing
> obfuscated code.)
 
I do not know, for me it is no problem to see that i is indexing images
from shorter form just with passing glance. If I somehow forget it
during reading next line (how?) then I can look again.
 
> I don't even understand why this is such a controversial thing.
> Clearer variable names are better. You will have extremely hard time
> convincing me otherwise.
 
That seems clear from this discussion. You avoid reading arguments
of people and act oddly ... like something of it is sacred ... calm down
it is just tool usage.
 
> > Latter feels like stuttering of "image" ridiculously many times. I feel
> > like: "I got it, it is image, stop babbling!" when reading it.
> I don't see that as a huge problem. Repetition does not reduce clarity.
 
It is not huge problem. I can get meaning out from far worse text,
it just takes bit more time to eyeball it and slight frustration of why
they needed to be that boringly repetitive about "image" there.
No biggie.
> with make_unique, then fine. The problem is that the "always use auto"
> people use it with everything, very much in situations where it just
> hides the type for no good reason and at the expense of clarity.
 
I am with you there (like in all written art), brevity may easily be
confusing, ambiguous or contradicting. It just is not direct rule
that brevity=obfuscation and verbosity=clarity.
> what we want to avoid in code. We want clarity in code, not
> obfuscation. We don't want obscure terms and acronyms, we want
> clear full English words that express clearly the meaning.
 
Haven't observed what you claim. Do you have any example of
that "obfuscated language"? That can be so in old jurisdictions
without democracy. There spoken language can evolve significantly
away from juridical language without need of modernising it so
ordinary politicians, members of legislative body understand it.
Otherwise majority of the obfuscation of legalese comes from
overly big verbosity used in hope to be unambiguous even when
shorter formulation would be as unambiguous but have better
clarity.
Juha Nieminen <nospam@thanks.invalid>: Dec 20 11:53AM

>>opinion on coding style.
 
>>(Yes, you are just going to answer "you did it too!" Spare me.)
 
> Go have a long look in the mirror. This conversation is over.
 
And of course you wouldn't spare me.
Juha Nieminen <nospam@thanks.invalid>: Dec 20 12:09PM


> I do not know, for me it is no problem to see that i is indexing images
> from shorter form just with passing glance. If I somehow forget it
> during reading next line (how?) then I can look again.
 
I'm not sure how I could convey my experience on both reading (huge
amounts of) other people's code and writing my own code and then
reading it months/later, and noticing how much easier it becomes
to read when, for example, loop variables express what they are
indexing or counting.
 
I understand perfectly that there's this instinct when *writing*
code that using a loop variable name that consists of two full
words feels inconvenient and completely unnecessary. Heck, I myself
still succumb to this from time to time, just because it feels so
much more convenient.
 
However, when reading code, especially code written by others,
the variable stating what it is for just makes it so much easier
to just read and understand the code. It removes one burden of
having to interpret what a single-letter variable means, from
among a bunch of single-character symbols, because the variable
is directly telling you.
 
As mentioned elsewhere, the longer the loop body, and the more
nested loops there are, the more important it becomes to name the
loop variables clearly. My rought estimation/rule of thumb is that
this importance grows about linearly with the length of the loop
body, and exponentially with each nested loop.
 
The worst possible case scenario is having eg. three nested loops,
each using a single-character loop variable, and a significant
amount of code in them. It just clarifies *enormously* if the loop
variables were clearly named. It just does. There is nothing you can
tell me that will convince me to not believe my own eyes.
 
You can argue that if there are so many nested loops and their bodies
are so long that the loop variables get buried in the code and are
to discern, that's indicative that a refactoring of the entire thing
could be in place. Sure. However, using the clearer loop variable
names doesn't exactly hurt in either case.
 
There is no reason to use 'i' as a loop variable. There is no advantage.
You can claim all day long that there is some advantage, but I don't
see how I could get convinced of it, when I see with my own eyes the
difference between it and using a variable that actually says what
it's for.
 
There might be a few situations where using a name like 'i' for a loop
variable (or any variable for that matter) might be warranted, but
they are rare, and even then, I see little disadvantage in using
something clearer. But heaven forbid you use it in a nested loop
with a 'j' as the other loop variable. Now the code becomes genuinely
confusing and obfuscated! I'm not just saying that out of stubborness
or principle. Mixing 'i' and 'j' in the same code, for similar roles,
is really confusing. ('n' and 'm' is not significantly better. 'x'
and 'y' is passable and in some situations it's actually ok, when
we are talking about actual (x, y) cartesian coordinates.)
David Brown <david.brown@hesbynett.no>: Dec 20 01:32PM +0100

On 20/12/2022 07:16, Juha Nieminen wrote:
>> it contacts the satellite first.
 
> Most people who write and read code (which is what we are talking about
> here) don't know what HDMI is? Right.
 
Wikipedia lists about 20 meanings of "GPS". I was using the GNAT
Programming Studio (as a front-end to gdb on embedded systems) long
before "Global Positioning System" was commonly known.
 
You don't get to decide what is "universally understood". No one does.
You don't get to say "this abbreviation or term is universal and we
can use it in code", nor do you get to say "this abbreviation is /not/
universal and you should /not/ use it in code". It's all about context.
 
People should use abbreviations and terms that make sense in the context
of their code. Anything else makes code harder to read. That applies
equally to abbreviations that are /not/ clear from the context, and to
explicit and expanded forms that could easily have been shortened.
David Brown <david.brown@hesbynett.no>: Dec 20 01:32PM +0100

On 20/12/2022 07:09, Juha Nieminen wrote:
> code for yourself, and expecting the reader to do the "homework" in order
> to understand it. The onus is on the reader to do the work to understand
> the code.
 
The onus is on the reader not to be an idiot!
 
I'm sorry, but I don't write code with the expectation that it should be
immediately readable and understandable by every kid who takes a cursory
glance at it.
 
I write my code so that other /programmers/ can use it in their code,
understand it for code reviews, maintain it when I am not around, and
otherwise read, understand and use the code. If some fool wants to come
along and look at a single line, then go crying because they can't see
exactly how everything works from the one line, then they can go cry
elsewhere.
 
Seriously, I have no sympathy for someone who expects the kind of
spoon-feeding you seem to demand. You are just as bad as someone who
thinks "t1" is fine for a global variable name because it is "obvious".
 
Get real. Buy yourself a screen that can display a dozen lines of code
at a time in one window, the file-level and function-level comments in
another, and the program specification and documentation in another.
 
Code must be understood from its context - not as lines standing alone.
Variables, functions, types - they all live in an ecosystem, and if
you want to understand some code, you need to put some effort into
understanding that ecosystem.
 
If the code can't be followed /despite/ knowing its ecosystem and wider
context, or the context is incomprehensible, /then/ you have good
grounds for complaint. And unfortunately there's plenty of code like that.
 
> make it as easy for the reader to understand the code as possible. The
> work to make the code understandable is done by the writer, not the
> reader.
 
Yes. You should try it some time. Writing code as though you are paid
by character is not good enough.
 
 
 
> It still baffles my mind how someone can think that making the code
> more understandable makes it less understandable. There's an amazing
> amount of cognitive dissonance here.
 
What baffles /me/ is that you think you have found a unique way to make
code "understandable" and that everyone else, the world over, gets it
wrong and is trying to undermine you. I'm not sure if it is paranoia or
narcissism, but it is certainly not a good thing.
 
Let's get this straight. /No one/ is saying it is good to make code
"less understandable". I am saying that /your/ attempts at making code
"easy to read" and "easy to understand" can be counter-productive and
can make code /harder/ to read, /harder/ to understand, /less/ clear.
At the risk of stating tautologies, overly long names, excessive
identifiers, failure to use language facilities such as "using" and
"auto" appropriately, all lead to code that is hard to understand.
 
Is that so hard for you to comprehend?
 
> Either you are... well, I don't want to be explicitly offensive...
> or you are just arguing for the sake of arguing. I'll give you the
> benefit of the doubt and assume the latter.
 
I'm quite happy for you to say what you mean - I certainly do. (And I
don't think it is offensive to do so - honest criticism is fine.)
David Brown <david.brown@hesbynett.no>: Dec 20 01:43PM +0100

On 19/12/2022 16:42, Juha Nieminen wrote:
> after the thing it's indexing or counting. You don't have to guess.
> You don't have to remember. It says it directly. It makes it so
> much easier to understand.
 
You are right - I wouldn't believe it.
 
I /do/ believe that if the rest of the code is not clear, the functions
are too long, the logic too convoluted, the documentation too poor, the
code is poorly structured, the layout is poor, or many other failings
for clear code - I /do/ believe that /then/ it might be less bad if the
loop index had a longer name.
 
But if ever I see code where I think "that loop variable should have a
better name than just 'i'", I know that there are many things that are
much more important to making the code clear. And once you fix the
important stuff, the loop variable "i" is usually clearer than any
alternative.
 
Poor legibility of code is a problem - we all agree on that. Making
some identifiers longer or more descriptive is not the solution - at
best it covers up the real problems.
David Brown <david.brown@hesbynett.no>: Dec 20 01:46PM +0100

> as a numerical library would do. In other languages you could make that claim
> about 'var x = a*b', but in C++ it needs to be qualified, in some contexts the type
> is correct for its use, in others it's undefined behavior.
 
Actually, you /do/ know it is the correct type for its use in /that/
line. If "a * b" returns a proxy, then "x" should be that proxy - "auto
x" means you have the correct type.
 
Whether you use that variable correctly later remains to be seen in the
rest of the code. Code cannot be fully understood line by line, it also
cannot be considered fully correct line by line.
Juha Nieminen <nospam@thanks.invalid>: Dec 20 01:49PM

> Writing code as though you are paid
> by character is not good enough.
 
And here we go, once again, with the length argument. It doesn't matter
how many times I repeat that it's not about the length, the same
argument will still come up again, and again, and again, and again.
 
Regardless of whether you are misunderstanding my point inadvertently
or deliberately, this just goes to show that you outright don't *want*
to understand nor acknowledge what I'm trying to say. In other words,
you are just arguing in bad faith.
 
> code "understandable" and that everyone else, the world over, gets it
> wrong and is trying to undermine you. I'm not sure if it is paranoia or
> narcissism, but it is certainly not a good thing.
 
What the fuck are you talking about? Nowhere have I said or even implied
that this is my own original idea that nobody else has ever had and
nobody else knows or understands. I know lots of people who fully agree
with these ideas. These ideas are pretty much as old as computer
programming itself. I am merely recounting my own experiences on this
and confirming the validity of these ideas.
 
There are several people *in this very thread* who partially or fully
agree with the title of the thread (ie. that the overuse of 'auto',
which is sadly common, is detrimental to program readability). I know
many people who think very similarly about variable and function naming.
I wouldn't be surprised if very similar ideas couldn't be found in
programming books and papers all the way back to the 70's and 60's.
 
What I would actually find a bit surprising if there were books and
papers arguing for the opposite, ie. what you are saying.
Muttley@dastardlyhq.com: Dec 20 10:11AM

On Mon, 19 Dec 2022 18:28:10 -0600
>> A Ford Transit can pull up to 3.5 tons which is 7700lbs.
 
>My F-150 can tow up to 13,000 lbs. And has a 38 USA gallon tank for the
>resulting 8 mpg.
 
Another thing in which europe and the USA differ. You can't tow a 6 ton load
using a 2.5 ton vehicle in Europe for obvious control reasons no matter what
engine its got but then you guys also allow geriatrics with only a car license
to drive 10 ton converted buses (also known as RVs) and towing a car to boot!
 
I guess in the US safety comes a poor 2nd place to lifestyle.
Muttley@dastardlyhq.com: Dec 20 10:14AM

On Mon, 19 Dec 2022 19:28:53 -0800
>big boat got out of control and the driver could not control it. I
>cannot remember if he had breaks on his trailer or not. Iirc, this is a
>report of the shit storm:
 
No, but I have a Class 1 HGV license which means I can drive trucks up to 44
tons in the UK and I wouldn't let someone with only a car license anywhere near
those sorts of loads. But the safety rules are ... different ... in the US.
"Öö Tiib" <ootiib@hot.ee>: Dec 20 01:36AM -0800


> hey and if we are going to have revisions how about adding yes and no, we now have true and false.
 
The "true"/"false" sound most neutral, abstract and mathematical. Every other
dual meaning like "yes"/"no", "on"/"off", "in"/"out", "is"/"isn't", "correct"/"incorrect",
"enabled"/"disabled" etc. are context-dependent and confusing in other context.
As we have boolean it is pointless to add those others to language for confusion.
"Öö Tiib" <ootiib@hot.ee>: Dec 20 01:14AM -0800

On Tuesday, 20 December 2022 at 01:45:30 UTC+2, red floyd wrote:
> try to go on with the corrupted system, and test other functions. With
> the 60-fold reduction in program load, they'd restart clean, reload the
> database, and continue with the testing, guaranteeing a good system.
 
I have had also interesting experience. Tool made around 2004 preparing
some files took hours to run. Only few people on planet ran it only few
times per month. The time complexity was unreasonable and also lack
of concurrent processing but no one really cared ... what mattered was
that it worked correctly.
 
Then around 2011 arose an idea that same algorithm is useful elsewhere
and for wider audience only performance is unacceptable for that. So there
was budget and we optimized it to take counted seconds. All was fine, we
could use it for other purpose.
 
But the developers responsible for original tool wanted the improved
algorithm too. Because better is better. I gave it to them. They put it in.
The first reaction to that was opposition and weird FUD. Maybe we had
changed outcome, lost correctness, lost quality or compression rate of
output. :D Optimization can take some convenient "work hours" away
from someone. So be careful with it. ;)
Frederick Virchanza Gotham <cauldwell.thomas@gmail.com>: Dec 19 11:49PM -0800

On Thursday, December 15, 2022 at 9:27:16 AM UTC, Frederick Virchanza Gotham wrote:
 
> ++g_count;
> a = b;
> }
 
That should be:
 
a = std::forward<K>(b);
You received this digest because you're subscribed to updates for this group. You can change your settings on the group membership page.
To unsubscribe from this group and stop receiving emails from it send an email to comp.lang.c+++unsubscribe@googlegroups.com.

No comments: