imo c in some way is to make programmer not thing liek in assembler when
you need to hardly mentally focus but you use some plain c constructions
(it is not on all c becouse some c is really convoluted ;c)
if so you need easy if an sometimes those if else
ladders are not enough plain imo
this mean some needs some other construction that should be easier to read
see for example this code
if(dodge <1.)
{
ÿ if(dodge < .5)
ÿ{ÿ slog("%s easily dodged attack...",ÿ being[k].name); }
ÿ else if(dodge > .9)
ÿ{ÿ slog("%s hardly dodged attack...",ÿ being[k].name); }
ÿ else
ÿÿ slog("%s dodgedÿ attack...",ÿ being[k].name);
ÿ return 1;
ÿÿÿÿÿÿÿ }
imo its not readable, switch is also bad here, some needs something
other here soem other if realated construction
imo c in some way is to make programmer not thing liek in assembler when
you need to hardly mentally focus but you use some plain c constructions
(it is not on all c becouse some c is really convoluted ;c)
if so you need easy if an sometimes those if else
ladders are not enough plain imo
this mean some needs some other construction that should be easier to read
see for example this code
if(dodge <1.)It's not the if-else that is the problem here; the example is dominated
{
ÿ if(dodge < .5)
ÿ{ÿ slog("%s easily dodged attack...",ÿ being[k].name); }
ÿ else if(dodge > .9)
ÿ{ÿ slog("%s hardly dodged attack...",ÿ being[k].name); }
ÿ else
ÿÿ slog("%s dodgedÿ attack...",ÿ being[k].name);
ÿ return 1;
ÿÿÿÿÿÿÿ }
imo its not readable, switch is also bad here, some needs something
other here soem other if realated construction
On 05/09/2026 12:43, fir wrote:
imo c in some way is to make programmer not thing liek in assemblerIt's not the if-else that is the problem here; the example is dominated
when you need to hardly mentally focus but you use some plain c
constructions (it is not on all c becouse some c is really convoluted ;c)
if so you need easy if an sometimes those if else
ladders are not enough plain imo
this mean some needs some other construction that should be easier to
read
see for example this code
if(dodge <1.)
{
ÿÿ if(dodge < .5)
ÿÿ{ÿ slog("%s easily dodged attack...",ÿ being[k].name); }
ÿÿ else if(dodge > .9)
ÿÿ{ÿ slog("%s hardly dodged attack...",ÿ being[k].name); }
ÿÿ else
ÿÿÿ slog("%s dodgedÿ attack...",ÿ being[k].name);
ÿÿ return 1;
ÿÿÿÿÿÿÿÿ }
imo its not readable, switch is also bad here, some needs something
other here soem other if realated construction
by those slog calls.
However your coding style doesn't help, with badly placed and
inconsistent use of braces. The logic here is this:
ÿ #define sdodge(x) slog("%s" x "dodged attack...", being[k], name)
ÿ if (dodge < 1.0) {
ÿÿÿÿÿÿÿÿÿÿ if (dodge < 0.5) sdodge("easily ");
ÿÿÿÿÿ else if (dodge > 0.9) sdodge("hardly ");
ÿÿÿÿÿ elseÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ sdodge("");
ÿÿÿÿÿ return 1;
ÿ }
Switch is not going to be useful in this case, unless you call a
function that takes 'dodge' and returns a 1/2/3 category code.
bart pisze:
On 05/09/2026 12:43, fir wrote:
imo c in some way is to make programmer not thing liek in assemblerIt's not the if-else that is the problem here; the example is
when you need to hardly mentally focus but you use some plain c
constructions (it is not on all c becouse some c is really convoluted
;c)
if so you need easy if an sometimes those if else
ladders are not enough plain imo
this mean some needs some other construction that should be easier to
read
see for example this code
if(dodge <1.)
{
ÿÿ if(dodge < .5)
ÿÿ{ÿ slog("%s easily dodged attack...",ÿ being[k].name); }
ÿÿ else if(dodge > .9)
ÿÿ{ÿ slog("%s hardly dodged attack...",ÿ being[k].name); }
ÿÿ else
ÿÿÿ slog("%s dodgedÿ attack...",ÿ being[k].name);
ÿÿ return 1;
ÿÿÿÿÿÿÿÿ }
imo its not readable, switch is also bad here, some needs something
other here soem other if realated construction
dominated by those slog calls.
However your coding style doesn't help, with badly placed and
inconsistent use of braces. The logic here is this:
ÿÿ #define sdodge(x) slog("%s" x "dodged attack...", being[k], name)
ÿÿ if (dodge < 1.0) {
ÿÿÿÿÿÿÿÿÿÿÿ if (dodge < 0.5) sdodge("easily ");
ÿÿÿÿÿÿ else if (dodge > 0.9) sdodge("hardly ");
ÿÿÿÿÿÿ elseÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ sdodge("");
ÿÿÿÿÿÿ return 1;
ÿÿ }
Switch is not going to be useful in this case, unless you call a
function that takes 'dodge' and returns a 1/2/3 category code.
my coding style here is bad i know (this dodge variable is wrong as its
more like "hit quality" above 1 its hit the more the better , below 1 is miss , 0.9 meand berelly missed etc
but the if ladders ARE shit and are not quick (brainless) readable
ifs block is like "serial"
if(a<2)
if(a>3)
if(a<0)
if(a>4)
if(a<9)
here
ehen you need also "going-thru" but something like "switch" indeed
but it should be probbaly switch ifÿ not weird switch construction
if else block is also "serial" (and its reading proces is also "serial")
and you dont need "serial"
i dont know what world it should be but something like case but with no
head of switch
case(a<1) {}
case(a>3) {}
case(a<8) {}
caseÿÿÿÿÿÿ {}
you need also this tail but preferably it could be the ame keyword
maybe (though here case dont fits becouse it should mean not "any case"
but "other case"
it also should go thru all cases that "catched" the condition
but should not go down like in classic switch (classic switch i dont
like and i dont use - i use this if else ladders but i dislike its readibility)
ÿ if(dodge < .5)
ÿÿ{ÿ slog("%s easily dodged attack...",ÿ being[k].name); }
ÿÿ else if(dodge > .9)
ÿÿ{ÿ slog("%s hardly dodged attack...",ÿ being[k].name); }
ÿÿ else
ÿÿÿ slog("%s dodgedÿ attack...",ÿ being[k].name);
fir pisze:
ÿÿ if(dodge < .5)
ÿÿÿ{ÿ slog("%s easily dodged attack...",ÿ being[k].name); }
ÿÿÿ else if(dodge > .9)
ÿÿÿ{ÿ slog("%s hardly dodged attack...",ÿ being[k].name); }
ÿÿÿ else
ÿÿÿÿ slog("%s dodgedÿ attack...",ÿ being[k].name);
eventually check my oryginal example here i could use if block which is
okay readable
ÿÿ if(dodge < .5) slog("a");
ÿÿ if(dodge > .9) slog("b");
ÿÿ slog("c");
but it is impossible becouse i want "a" or "b" or "c" not "ab" "ac"
so i could turn it into if-else block but then its not readable
or ake it yet more complex.. and all ot those 3 cases are wrong when
this solution i postulate would go welll
ÿÿ case (dodge < .5) slog("a");
ÿÿ case (dodge > .9) slog("b");
ÿÿ othercase slog("c");
fir pisze:
fir pisze:
ÿÿ if(dodge < .5)
ÿÿÿ{ÿ slog("%s easily dodged attack...",ÿ being[k].name); }
ÿÿÿ else if(dodge > .9)
ÿÿÿ{ÿ slog("%s hardly dodged attack...",ÿ being[k].name); }
ÿÿÿ else
ÿÿÿÿ slog("%s dodgedÿ attack...",ÿ being[k].name);
eventually check my oryginal example here i could use if block which is
okay readable
ÿÿÿ if(dodge < .5) slog("a");
ÿÿÿ if(dodge > .9) slog("b");
ÿÿÿ slog("c");
but it is impossible becouse i want "a" or "b" or "c" not "ab" "ac"
so i could turn it into if-else block but then its not readable
or ake it yet more complex.. and all ot those 3 cases are wrong when
this solution i postulate would go welll
ÿÿÿ case (dodge < .5) slog("a");
ÿÿÿ case (dodge > .9) slog("b");
ÿÿÿ othercase slog("c");
yet tu note the diference if-else blocks exit on first occurance
if blocks go thru all
what you need here (to assume and thus not READ IN like in convoluted assembly) in neitrer one orÿ another
you need like if block and then othercase keyword branch which will
go only if no one "if block" catched
- (and this is probably minimal syntax for so called switch - which in
turn is wrong in c becouse is not minimal and breaks the strict rules
here imo (probably))
fir pisze:
fir pisze:
fir pisze:
ÿÿ if(dodge < .5)
ÿÿÿ{ÿ slog("%s easily dodged attack...",ÿ being[k].name); }
ÿÿÿ else if(dodge > .9)
ÿÿÿ{ÿ slog("%s hardly dodged attack...",ÿ being[k].name); }
ÿÿÿ else
ÿÿÿÿ slog("%s dodgedÿ attack...",ÿ being[k].name);
eventually check my oryginal example here i could use if block which is
okay readable
ÿÿÿ if(dodge < .5) slog("a");
ÿÿÿ if(dodge > .9) slog("b");
ÿÿÿ slog("c");
but it is impossible becouse i want "a" or "b" or "c" not "ab" "ac"
so i could turn it into if-else block but then its not readable
or ake it yet more complex.. and all ot those 3 cases are wrong when
this solution i postulate would go welll
ÿÿÿ case (dodge < .5) slog("a");
ÿÿÿ case (dodge > .9) slog("b");
ÿÿÿ othercase slog("c");
yet tu note the diference if-else blocks exit on first occurance
if blocks go thru all
what you need here (to assume and thus not READ IN like in convoluted
assembly) in neitrer one orÿ another
you need like if block and then othercase keyword branch which will
go only if no one "if block" catched
- (and this is probably minimal syntax for so called switch - which in
turn is wrong in c becouse is not minimal and breaks the strict rules
here imo (probably))
one could also say it could be resolved by make extended else
like
x
.if () [}
.if () {}
if () {}
if () {}
.else {}
this else catches if all of those .if not catched not only one
OR it may suggest an option for logical combining ifs
if(a) {}
& if(b) {}
| if(c) {}
else {} //alse work only on logical combination
so there are some new possibilities here
fir pisze:
fir pisze:
fir pisze:
fir pisze:
ÿÿ if(dodge < .5)
ÿÿÿ{ÿ slog("%s easily dodged attack...",ÿ being[k].name); }
ÿÿÿ else if(dodge > .9)
ÿÿÿ{ÿ slog("%s hardly dodged attack...",ÿ being[k].name); }
ÿÿÿ else
ÿÿÿÿ slog("%s dodgedÿ attack...",ÿ being[k].name);
eventually check my oryginal example here i could use if block which is >>>> okay readable
ÿÿÿ if(dodge < .5) slog("a");
ÿÿÿ if(dodge > .9) slog("b");
ÿÿÿ slog("c");
but it is impossible becouse i want "a" or "b" or "c" not "ab" "ac"
so i could turn it into if-else block but then its not readable
or ake it yet more complex.. and all ot those 3 cases are wrong when
this solution i postulate would go welll
ÿÿÿ case (dodge < .5) slog("a");
ÿÿÿ case (dodge > .9) slog("b");
ÿÿÿ othercase slog("c");
yet tu note the diference if-else blocks exit on first occurance
if blocks go thru all
what you need here (to assume and thus not READ IN like in convoluted
assembly) in neitrer one orÿ another
you need like if block and then othercase keyword branch which will
go only if no one "if block" catched
- (and this is probably minimal syntax for so called switch - which
in turn is wrong in c becouse is not minimal and breaks the strict
rules here imo (probably))
one could also say it could be resolved by make extended else
like
x
.if () [}
.if () {}
if () {}
if () {}
.else {}
this else catches if all of those .if not catched not only one
OR it may suggest an option for logical combining ifs
if(a) {}
& if(b) {}
| if(c) {}
else {} //alse work only on logical combination
so there are some new possibilities here
so this 'classical' switch im talking here would be
ÿ if(){}
or if() {}
orÿ if() {}
or if() {}
else {}
i dont know if thi logical keywords would be more handy or just this improved switch would be most handy
On 05/09/2026 12:43, fir wrote:
imo c in some way is to make programmer not thing liek in assemblerIt's not the if-else that is the problem here; the example is dominated
when you need to hardly mentally focus but you use some plain c
constructions (it is not on all c becouse some c is really convoluted ;c)
if so you need easy if an sometimes those if else
ladders are not enough plain imo
this mean some needs some other construction that should be easier to
read
see for example this code
if(dodge <1.)
{
ÿÿ if(dodge < .5)
ÿÿ{ÿ slog("%s easily dodged attack...",ÿ being[k].name); }
ÿÿ else if(dodge > .9)
ÿÿ{ÿ slog("%s hardly dodged attack...",ÿ being[k].name); }
ÿÿ else
ÿÿÿ slog("%s dodgedÿ attack...",ÿ being[k].name);
ÿÿ return 1;
ÿÿÿÿÿÿÿÿ }
imo its not readable, switch is also bad here, some needs something
other here soem other if realated construction
by those slog calls.
However your coding style doesn't help, with badly placed and
inconsistent use of braces. The logic here is this:
ÿ #define sdodge(x) slog("%s" x "dodged attack...", being[k], name)
ÿ if (dodge < 1.0) {
ÿÿÿÿÿÿÿÿÿÿ if (dodge < 0.5) sdodge("easily ");
ÿÿÿÿÿ else if (dodge > 0.9) sdodge("hardly ");
ÿÿÿÿÿ elseÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ sdodge("");
ÿÿÿÿÿ return 1;
ÿ }
Switch is not going to be useful in this case, unless you call a
function that takes 'dodge' and returns a 1/2/3 category code.
On 05/09/2026 14:10, bart wrote:
On 05/09/2026 12:43, fir wrote:
imo c in some way is to make programmer not thing liek in assemblerIt's not the if-else that is the problem here; the example is
when you need to hardly mentally focus but you use some plain c
constructions (it is not on all c becouse some c is really convoluted
;c)
if so you need easy if an sometimes those if else
ladders are not enough plain imo
this mean some needs some other construction that should be easier to
read
see for example this code
if(dodge <1.)
{
ÿÿ if(dodge < .5)
ÿÿ{ÿ slog("%s easily dodged attack...",ÿ being[k].name); }
ÿÿ else if(dodge > .9)
ÿÿ{ÿ slog("%s hardly dodged attack...",ÿ being[k].name); }
ÿÿ else
ÿÿÿ slog("%s dodgedÿ attack...",ÿ being[k].name);
ÿÿ return 1;
ÿÿÿÿÿÿÿÿ }
imo its not readable, switch is also bad here, some needs something
other here soem other if realated construction
dominated by those slog calls.
However your coding style doesn't help, with badly placed and
inconsistent use of braces. The logic here is this:
ÿÿ #define sdodge(x) slog("%s" x "dodged attack...", being[k], name)
ÿÿ if (dodge < 1.0) {
ÿÿÿÿÿÿÿÿÿÿÿ if (dodge < 0.5) sdodge("easily ");
ÿÿÿÿÿÿ else if (dodge > 0.9) sdodge("hardly ");
ÿÿÿÿÿÿ elseÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ sdodge("");
ÿÿÿÿÿÿ return 1;
ÿÿ }
Switch is not going to be useful in this case, unless you call a
function that takes 'dodge' and returns a 1/2/3 category code.
Your bracing style is also questionable - for many reasons, it is common
in style guides to recommend braces whenever you have "else" clauses,
and even more so when macros are involved.
And while refactoring out the common code is a good idea, it is almost always best to use functions for the job.
static void sdodge(int being_index, const char * adj) {
ÿÿÿÿslog("%sÿ %sdodged attack...", being[being_index].name, adj);
}
ÿÿÿÿ...
ÿÿÿÿif (dodge < 1.0) {
ÿÿÿÿÿÿÿ if (dodge < 0.5) {
ÿÿÿÿÿÿÿÿÿÿÿ sdodge(k, "easily ");
ÿÿÿÿÿÿÿ } else if (dodge > 0.9) {
ÿÿÿÿÿÿÿÿÿÿÿ sdodge(k, "hardly ");
ÿÿÿÿÿÿÿ } else {
ÿÿÿÿÿÿÿÿÿÿÿ sdodge(k, "");
ÿÿÿÿÿÿÿ }
ÿÿÿÿÿÿÿ return 1;
ÿÿÿÿ}
ÿÿÿÿ...
This is easier to change if you need to add more to the different
clauses, or if sdodge() needs more statements.
It is also possible to use the tertiary operator, which some people
might feel is clearer :
ÿÿÿÿ...
ÿÿÿÿif (dodge < 1.0) {
ÿÿÿÿÿÿÿ sdodge(k, (dodge < 0.5) ? "easily " :
ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ (dodge > 0.9) ? "hardly " :
ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ "");
ÿÿÿÿÿÿÿ return 1;
ÿÿÿÿ}
ÿÿÿÿ...
Even better, perhaps, the classification part could be pulled out :
typedef enum { dodge_easy, dodge_medium, dodge_hard } dodge_style_t;
const char * dodge_adjectives[] = { "easily ", "", "hardly " };
dodge_style_t dodge_style_from_frac(double x) {
ÿÿÿÿif (dodge < 0.5) return dodge_easy;
ÿÿÿÿif (dodge > 0.9) return dodge_hard;
ÿÿÿÿreturn dodge_medium;
}
ÿÿÿÿ...
ÿÿÿÿif (dodge < 1.0) {
ÿÿÿÿÿÿÿ slog("%sÿ %sdodged attack...", being[k].name,
ÿÿÿÿÿÿÿÿÿÿÿ dodge_adjectives[dodge_style_from_frac[dodge]));
ÿÿÿÿÿÿÿ return 1;
ÿÿÿÿ}
ÿÿÿÿ...
Now it's a lot easier to change things if other dodge styles are added,
or the boundaries are changed - there are fewer "magic numbers" in the
main code.
On 05/09/2026 14:10, bart wrote:
On 05/09/2026 12:43, fir wrote:
imo c in some way is to make programmer not thing liek in assembler
when you need to hardly mentally focus but you use some plain c
constructions (it is not on all c becouse some c is really
convoluted ;c)
if so you need easy if an sometimes those if else
ladders are not enough plain imo
this mean some needs some other construction that should be easier to
read
see for example this code
if(dodge <1.)
{
ÿÿ if(dodge < .5)
ÿÿ{ÿ slog("%s easily dodged attack...",ÿ being[k].name); }
ÿÿ else if(dodge > .9)
ÿÿ{ÿ slog("%s hardly dodged attack...",ÿ being[k].name); }
ÿÿ else
ÿÿÿ slog("%s dodgedÿ attack...",ÿ being[k].name);
ÿÿ return 1;
ÿÿÿÿÿÿÿÿ }
imo its not readable, switch is also bad here, some needs something
other here soem other if realated construction
It's not the if-else that is the problem here; the example is
dominated by those slog calls.
However your coding style doesn't help, with badly placed and
inconsistent use of braces. The logic here is this:
ÿÿ #define sdodge(x) slog("%s" x "dodged attack...", being[k], name)
ÿÿ if (dodge < 1.0) {
ÿÿÿÿÿÿÿÿÿÿÿ if (dodge < 0.5) sdodge("easily ");
ÿÿÿÿÿÿ else if (dodge > 0.9) sdodge("hardly ");
ÿÿÿÿÿÿ elseÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ sdodge("");
ÿÿÿÿÿÿ return 1;
ÿÿ }
Switch is not going to be useful in this case, unless you call a
function that takes 'dodge' and returns a 1/2/3 category code.
Your bracing style is also questionable - for many reasons, it is common
in style guides to recommend braces whenever you have "else" clauses,
and even more so when macros are involved.
And while refactoring out the common code is a good idea, it is almost always best to use functions for the job.
static void sdodge(int being_index, const char * adj) {
ÿÿÿÿslog("%sÿ %sdodged attack...", being[being_index].name, adj);
}
ÿÿÿÿ...
ÿÿÿÿif (dodge < 1.0) {
ÿÿÿÿÿÿÿ if (dodge < 0.5) {
ÿÿÿÿÿÿÿÿÿÿÿ sdodge(k, "easily ");
ÿÿÿÿÿÿÿ } else if (dodge > 0.9) {
ÿÿÿÿÿÿÿÿÿÿÿ sdodge(k, "hardly ");
ÿÿÿÿÿÿÿ } else {
ÿÿÿÿÿÿÿÿÿÿÿ sdodge(k, "");
ÿÿÿÿÿÿÿ }
ÿÿÿÿÿÿÿ return 1;
ÿÿÿÿ}
ÿÿÿÿ...
This is easier to change if you need to add more to the different
clauses, or if sdodge() needs more statements.
It is also possible to use the tertiary operator, which some people
might feel is clearer :
ÿÿÿÿ...
ÿÿÿÿif (dodge < 1.0) {
ÿÿÿÿÿÿÿ sdodge(k, (dodge < 0.5) ? "easily " :
ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ (dodge > 0.9) ? "hardly " :
ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ "");
ÿÿÿÿÿÿÿ return 1;
ÿÿÿÿ}
ÿÿÿÿ...
Even better, perhaps, the classification part could be pulled out :
typedef enum { dodge_easy, dodge_medium, dodge_hard } dodge_style_t;
const char * dodge_adjectives[] = { "easily ", "", "hardly " };
dodge_style_t dodge_style_from_frac(double x) {
ÿÿÿÿif (dodge < 0.5) return dodge_easy;
ÿÿÿÿif (dodge > 0.9) return dodge_hard;
ÿÿÿÿreturn dodge_medium;
}
ÿÿÿÿ...
ÿÿÿÿif (dodge < 1.0) {
ÿÿÿÿÿÿÿ slog("%sÿ %sdodged attack...", being[k].name,
ÿÿÿÿÿÿÿÿÿÿÿ dodge_adjectives[dodge_style_from_frac[dodge]));
ÿÿÿÿÿÿÿ return 1;
ÿÿÿÿ}
ÿÿÿÿ...
Now it's a lot easier to change things if other dodge styles are added,
or the boundaries are changed - there are fewer "magic numbers" in the
main code.
On 2026-09-05 16:16, David Brown wrote:
On 05/09/2026 14:10, bart wrote:
On 05/09/2026 12:43, fir wrote:
imo c in some way is to make programmer not thing liek in assembler
when you need to hardly mentally focus but you use some plain c
constructions (it is not on all c becouse some c is really
convoluted ;c)
if so you need easy if an sometimes those if else
ladders are not enough plain imo
(Your "English" is really hard to decipher. - I suggest to use Google
to translate your texts from your native language into something that
is much better understandable and post that translation. - The Google translator is easily accessible from your browser.)
this mean some needs some other construction that should be easier
to read
see for example this code
if(dodge <1.)
{
ÿÿ if(dodge < .5)
ÿÿ{ÿ slog("%s easily dodged attack...",ÿ being[k].name); }
ÿÿ else if(dodge > .9)
ÿÿ{ÿ slog("%s hardly dodged attack...",ÿ being[k].name); }
ÿÿ else
ÿÿÿ slog("%s dodgedÿ attack...",ÿ being[k].name);
ÿÿ return 1;
ÿÿÿÿÿÿÿÿ }
I'd use a function to encapsulate the logging statements; they all
have the same basic structure and you'd avoid all the duplicates.
Janis Papanagnou wrote:
On 2026-09-05 16:16, David Brown wrote:
On 05/09/2026 14:10, bart wrote:
On 05/09/2026 12:43, fir wrote:
imo c in some way is to make programmer not thing liek in assembler >>>>> when you need to hardly mentally focus but you use some plain c
constructions (it is not on all c becouse some c is really
convoluted ;c)
if so you need easy if an sometimes those if else
ladders are not enough plain imo
(Your "English" is really hard to decipher. - I suggest to use Google
to translate your texts from your native language into something that
is much better understandable and post that translation. - The Google
translator is easily accessible from your browser.)
this mean some needs some other construction that should be easier
to read
see for example this code
if(dodge <1.)
{
ÿÿ if(dodge < .5)
ÿÿ{ÿ slog("%s easily dodged attack...",ÿ being[k].name); }
ÿÿ else if(dodge > .9)
ÿÿ{ÿ slog("%s hardly dodged attack...",ÿ being[k].name); }
ÿÿ else
ÿÿÿ slog("%s dodgedÿ attack...",ÿ being[k].name);
ÿÿ return 1;
ÿÿÿÿÿÿÿÿ }
I'd use a function to encapsulate the logging statements; they all
have the same basic structure and you'd avoid all the duplicates.
What I'd do here is:
d=0
if (dodge<1)
ÿÿÿ d = 3
if (dodge<0.9)
ÿÿÿ d = 2
if (dodge<0.5)
ÿÿÿ d = 1
switch (d)
{
ÿÿÿ case 1:
ÿÿÿÿÿÿÿ slog("%s easily dodged attack...",ÿ being[k].name);
ÿÿÿÿÿÿÿ return 1;
ÿÿÿ case 2:
ÿÿÿÿÿÿÿ slog("%s hardly dodged attack...",ÿ being[k].name);
ÿÿÿÿÿÿÿ return 1;
ÿÿÿ case 3:
ÿÿÿÿslog("%s dodgedÿ attack...",ÿ being[k].name);
ÿÿÿÿÿÿÿ return 1;
}
This is pretty easy to read but, it also shows that there are tens of millions of ways to do this.
// u l i e n
[...]
What I'd do here is:
d=0
if (dodge<1)
ÿÿÿ d = 3
if (dodge<0.9)
ÿÿÿ d = 2
if (dodge<0.5)
ÿÿÿ d = 1
switch (d)
{
ÿÿÿ case 1:
ÿÿÿÿÿÿÿ slog("%s easily dodged attack...",ÿ being[k].name);
ÿÿÿÿÿÿÿ return 1;
ÿÿÿ case 2:
ÿÿÿÿÿÿÿ slog("%s hardly dodged attack...",ÿ being[k].name);
ÿÿÿÿÿÿÿ return 1;
ÿÿÿ case 3:
ÿÿÿÿslog("%s dodgedÿ attack...",ÿ being[k].name);
ÿÿÿÿÿÿÿ return 1;
}
This is pretty easy to read but, it also shows that there are tens of millions of ways to do this.
On 2026-09-05 16:16, David Brown wrote:There isn't enough info to see how to write an effective function.
On 05/09/2026 14:10, bart wrote:
On 05/09/2026 12:43, fir wrote:
imo c in some way is to make programmer not thing liek in assembler
when you need to hardly mentally focus but you use some plain c
constructions (it is not on all c becouse some c is really
convoluted ;c)
if so you need easy if an sometimes those if else
ladders are not enough plain imo
(Your "English" is really hard to decipher. - I suggest to use Google
to translate your texts from your native language into something that
is much better understandable and post that translation. - The Google translator is easily accessible from your browser.)
this mean some needs some other construction that should be easier
to read
see for example this code
if(dodge <1.)
{
ÿÿ if(dodge < .5)
ÿÿ{ÿ slog("%s easily dodged attack...",ÿ being[k].name); }
ÿÿ else if(dodge > .9)
ÿÿ{ÿ slog("%s hardly dodged attack...",ÿ being[k].name); }
ÿÿ else
ÿÿÿ slog("%s dodgedÿ attack...",ÿ being[k].name);
ÿÿ return 1;
ÿÿÿÿÿÿÿÿ }
I'd use a function to encapsulate the logging statements; they all
have the same basic structure and you'd avoid all the duplicates.
imo its not readable, switch is also bad here, some needs something
other here soem other if realated construction
As I wrote in some recent post; "I don't think that situation isn't
under control of the individual software writer; you could change
that situation." - Here as well; you have the the possibility to
structure your code. - And while (what you wrote above) "some c is
really convoluted" might be in principle true you seem to expose
some fundamental lack of capability to appropriately structure your
code. (In this case, BTW, a switch to another language with more
structuring options would also not help. Your problem here isn't
primarily or basically a "C" issue.)
It's not the if-else that is the problem here; the example is
dominated by those slog calls.
However your coding style doesn't help, with badly placed and
inconsistent use of braces. The logic here is this:
ÿÿ #define sdodge(x) slog("%s" x "dodged attack...", being[k], name)
(It's beyond me why one would prefer macros to a function here.
But your basic idea to extract the invariant is of course sensible.)
On 05/09/2026 18:03, Janis Papanagnou wrote:
On 2026-09-05 16:16, David Brown wrote:
On 05/09/2026 14:10, bart wrote:
There isn't enough info to see how to write an effective function.
ÿÿ #define sdodge(x) slog("%s" x "dodged attack...", being[k], name)
(It's beyond me why one would prefer macros to a function here.
But your basic idea to extract the invariant is of course sensible.)
But if 'being[]' and 'name' are locals (or 'k' if 'being' is global),
then the function will need those extra parameters. In that case, the
sdodge calls will not be so different from the original slog calls.
On 06/09/2026 01:06, bart wrote:
On 05/09/2026 18:03, Janis Papanagnou wrote:
On 2026-09-05 16:16, David Brown wrote:
On 05/09/2026 14:10, bart wrote:
There isn't enough info to see how to write an effective function.
ÿÿ #define sdodge(x) slog("%s" x "dodged attack...", being[k], name)
(It's beyond me why one would prefer macros to a function here.
But your basic idea to extract the invariant is of course sensible.)
But if 'being[]' and 'name' are locals (or 'k' if 'being' is global),
then the function will need those extra parameters. In that case, the
sdodge calls will not be so different from the original slog calls.
All we can do is suggest different ideas and ways to arrange such code,
and maybe the OP will see something he feels is a good fit for his
needs.ÿ As you say, we are missing a lot of information about the rest
of the code - we don't know what data is "global" or local, when any of these parts might be re-used, how likely it is that the details or
boundary points will be changed, and countless other details.
In general, I am very sceptical about using macros for this kind of
thing.ÿ It is correct that they let you implicitly pass local data into
the macro in a way that functions do not - but that can make the
structure a lot harder to follow, and becomes fragile for changes.ÿ So
while it is definitely something that can occasionally be helpful, I
think it is rarely the best solution.
If the OP is happy with compiler extensions, a possibility here is gcc nested functions - these can capture such local variables in a safer and more structured manner, keeping the details within the function itself.
(Or he could use C++ and lambdas for a similar effect.ÿ There are
proposals to add lambdas to C, but they are not standardised yet.)
David Brown pisze:
On 06/09/2026 01:06, bart wrote:lol, adding almbdas to c that would be a trash... if the populist will
On 05/09/2026 18:03, Janis Papanagnou wrote:
On 2026-09-05 16:16, David Brown wrote:
On 05/09/2026 14:10, bart wrote:
There isn't enough info to see how to write an effective function.(It's beyond me why one would prefer macros to a function here.
ÿÿ #define sdodge(x) slog("%s" x "dodged attack...", being[k], name) >>>>
But your basic idea to extract the invariant is of course sensible.)
But if 'being[]' and 'name' are locals (or 'k' if 'being' is global),
then the function will need those extra parameters. In that case, the
sdodge calls will not be so different from the original slog calls.
All we can do is suggest different ideas and ways to arrange such
code, and maybe the OP will see something he feels is a good fit for
his needs.ÿ As you say, we are missing a lot of information about the
rest of the code - we don't know what data is "global" or local, when
any of these parts might be re-used, how likely it is that the details
or boundary points will be changed, and countless other details.
In general, I am very sceptical about using macros for this kind of
thing.ÿ It is correct that they let you implicitly pass local data
into the macro in a way that functions do not - but that can make the
structure a lot harder to follow, and becomes fragile for changes.ÿ So
while it is definitely something that can occasionally be helpful, I
think it is rarely the best solution.
If the OP is happy with compiler extensions, a possibility here is gcc
nested functions - these can capture such local variables in a safer
and more structured manner, keeping the details within the function
itself. (Or he could use C++ and lambdas for a similar effect.ÿ There
are proposals to add lambdas to C, but they are not standardised yet.)
touch c it would be a heavy disaster (they touched it already too much)
what i strongly need is those long t = 'somethin'; here to this tags
could work up to 8 lengthÿ (or 16 if some cpu has 128 bit ints)
On 06/09/2026 11:12, fir wrote:
David Brown pisze:
On 06/09/2026 01:06, bart wrote:lol, adding almbdas to c that would be a trash... if the populist will
On 05/09/2026 18:03, Janis Papanagnou wrote:
On 2026-09-05 16:16, David Brown wrote:
On 05/09/2026 14:10, bart wrote:
There isn't enough info to see how to write an effective function.(It's beyond me why one would prefer macros to a function here.
ÿÿ #define sdodge(x) slog("%s" x "dodged attack...", being[k], name) >>>>>
But your basic idea to extract the invariant is of course sensible.)
But if 'being[]' and 'name' are locals (or 'k' if 'being' is
global), then the function will need those extra parameters. In that
case, the sdodge calls will not be so different from the original
slog calls.
All we can do is suggest different ideas and ways to arrange such
code, and maybe the OP will see something he feels is a good fit for
his needs.ÿ As you say, we are missing a lot of information about the
rest of the code - we don't know what data is "global" or local, when
any of these parts might be re-used, how likely it is that the
details or boundary points will be changed, and countless other details. >>>
In general, I am very sceptical about using macros for this kind of
thing.ÿ It is correct that they let you implicitly pass local data
into the macro in a way that functions do not - but that can make the
structure a lot harder to follow, and becomes fragile for changes.
So while it is definitely something that can occasionally be helpful,
I think it is rarely the best solution.
If the OP is happy with compiler extensions, a possibility here is
gcc nested functions - these can capture such local variables in a
safer and more structured manner, keeping the details within the
function itself. (Or he could use C++ and lambdas for a similar
effect.ÿ There are proposals to add lambdas to C, but they are not
standardised yet.)
touch c it would be a heavy disaster (they touched it already too much)
what i strongly need is those long t = 'somethin'; here to this tags
could work up to 8 lengthÿ (or 16 if some cpu has 128 bit ints)
I used to have both of those (in my language), so I could write 'ABCDEFGHIJKLMNOP' which had an u128 type. I've now dropped 128-bit
types as they were not that useful to me (only for implementing 128-
types within the compiler!).
I still have 'ABCDEFGH'.
C however limits such constants to the size of 'int', which is rarely
bigger than 32 bits, so it can only have 'ABCD' (and C itself may only guarantee 'A').
(My C compiler is different, in allowing 'ABCDEFGH'; I think it yields a 64-bit type in this case.)
So, given the current limitations, then what are you suggesting? Are
these just ideas for C extensions, or for a new language?
If you need such features now, then putting these ideas out there is not going to be of immediate help.
I suggest, if you really need those features soon (this is including the
new 'match' statements), that you write a special preprocessor which
takes programs written in this enhanced C, and generates standard C.
So, 'ABCDEFGH' will be converted to perhaps 0x4847464544434241.
On 06/09/2026 11:12, fir wrote:
David Brown pisze:
On 06/09/2026 01:06, bart wrote:lol, adding almbdas to c that would be a trash... if the populist will
On 05/09/2026 18:03, Janis Papanagnou wrote:
On 2026-09-05 16:16, David Brown wrote:
On 05/09/2026 14:10, bart wrote:
There isn't enough info to see how to write an effective function.(It's beyond me why one would prefer macros to a function here.
ÿÿ #define sdodge(x) slog("%s" x "dodged attack...", being[k], name) >>>>>
But your basic idea to extract the invariant is of course sensible.)
But if 'being[]' and 'name' are locals (or 'k' if 'being' is
global), then the function will need those extra parameters. In that
case, the sdodge calls will not be so different from the original
slog calls.
All we can do is suggest different ideas and ways to arrange such
code, and maybe the OP will see something he feels is a good fit for
his needs.ÿ As you say, we are missing a lot of information about the
rest of the code - we don't know what data is "global" or local, when
any of these parts might be re-used, how likely it is that the
details or boundary points will be changed, and countless other details. >>>
In general, I am very sceptical about using macros for this kind of
thing.ÿ It is correct that they let you implicitly pass local data
into the macro in a way that functions do not - but that can make the
structure a lot harder to follow, and becomes fragile for changes.
So while it is definitely something that can occasionally be helpful,
I think it is rarely the best solution.
If the OP is happy with compiler extensions, a possibility here is
gcc nested functions - these can capture such local variables in a
safer and more structured manner, keeping the details within the
function itself. (Or he could use C++ and lambdas for a similar
effect.ÿ There are proposals to add lambdas to C, but they are not
standardised yet.)
touch c it would be a heavy disaster (they touched it already too much)
what i strongly need is those long t = 'somethin'; here to this tags
could work up to 8 lengthÿ (or 16 if some cpu has 128 bit ints)
I used to have both of those (in my language), so I could write 'ABCDEFGHIJKLMNOP' which had an u128 type. I've now dropped 128-bit
types as they were not that useful to me (only for implementing
128-types within the compiler!).
I still have 'ABCDEFGH'.
C however limits such constants to the size of 'int', which is rarely
bigger than 32 bits, so it can only have 'ABCD' (and C itself may only guarantee 'A').
(My C compiler is different, in allowing 'ABCDEFGH'; I think it yields a 64-bit type in this case.)
So, given the current limitations, then what are you suggesting? Are
these just ideas for C extensions, or for a new language?
If you need such features now, then putting these ideas out there is not going to be of immediate help.
I suggest, if you really need those features soon (this is including the
new 'match' statements), that you write a special preprocessor which
takes programs written in this enhanced C, and generates standard C.
So, 'ABCDEFGH' will be converted to perhaps 0x4847464544434241.
On 06/09/2026 13:54, bart wrote:
On 06/09/2026 11:12, fir wrote:
David Brown pisze:
On 06/09/2026 01:06, bart wrote:lol, adding almbdas to c that would be a trash... if the populist
On 05/09/2026 18:03, Janis Papanagnou wrote:
On 2026-09-05 16:16, David Brown wrote:
On 05/09/2026 14:10, bart wrote:
ÿÿ #define sdodge(x) slog("%s" x "dodged attack...", being[k], >>>>>>>> name)
(It's beyond me why one would prefer macros to a function here.
But your basic idea to extract the invariant is of course sensible.) >>>>> There isn't enough info to see how to write an effective function.
But if 'being[]' and 'name' are locals (or 'k' if 'being' is
global), then the function will need those extra parameters. In
that case, the sdodge calls will not be so different from the
original slog calls.
All we can do is suggest different ideas and ways to arrange such
code, and maybe the OP will see something he feels is a good fit for
his needs.ÿ As you say, we are missing a lot of information about
the rest of the code - we don't know what data is "global" or local,
when any of these parts might be re-used, how likely it is that the
details or boundary points will be changed, and countless other
details.
In general, I am very sceptical about using macros for this kind of
thing.ÿ It is correct that they let you implicitly pass local data
into the macro in a way that functions do not - but that can make
the structure a lot harder to follow, and becomes fragile for
changes. So while it is definitely something that can occasionally
be helpful, I think it is rarely the best solution.
If the OP is happy with compiler extensions, a possibility here is
gcc nested functions - these can capture such local variables in a
safer and more structured manner, keeping the details within the
function itself. (Or he could use C++ and lambdas for a similar
effect.ÿ There are proposals to add lambdas to C, but they are not
standardised yet.)
will touch c it would be a heavy disaster (they touched it already
too much)
what i strongly need is those long t = 'somethin'; here to this tags
could work up to 8 lengthÿ (or 16 if some cpu has 128 bit ints)
I used to have both of those (in my language), so I could write
'ABCDEFGHIJKLMNOP' which had an u128 type. I've now dropped 128-bit
types as they were not that useful to me (only for implementing 128-
types within the compiler!).
I still have 'ABCDEFGH'.
C however limits such constants to the size of 'int', which is rarely
bigger than 32 bits, so it can only have 'ABCD' (and C itself may only
guarantee 'A').
(My C compiler is different, in allowing 'ABCDEFGH'; I think it yields
a 64-bit type in this case.)
So, given the current limitations, then what are you suggesting? Are
these just ideas for C extensions, or for a new language?
If you need such features now, then putting these ideas out there is
not going to be of immediate help.
I suggest, if you really need those features soon (this is including
the new 'match' statements), that you write a special preprocessor
which takes programs written in this enhanced C, and generates
standard C.
So, 'ABCDEFGH' will be converted to perhaps 0x4847464544434241.
I forgot to say that there are various things you can use in standard C, such as a function, or perhaps a macro, that will convert a string "ABCDEFGH" to a 64-bit integer. Some care will be needed with "ABCDE"
for example to ensure zero-padding.
You might also look at string interning.
If stuck with a language there are always workarounds! (I prefer purer solutions.)
bart pisze:
On 06/09/2026 11:12, fir wrote:
David Brown pisze:
On 06/09/2026 01:06, bart wrote:lol, adding almbdas to c that would be a trash... if the populist
On 05/09/2026 18:03, Janis Papanagnou wrote:
On 2026-09-05 16:16, David Brown wrote:
On 05/09/2026 14:10, bart wrote:
ÿÿ #define sdodge(x) slog("%s" x "dodged attack...", being[k], >>>>>>>> name)
(It's beyond me why one would prefer macros to a function here.
But your basic idea to extract the invariant is of course sensible.) >>>>> There isn't enough info to see how to write an effective function.
But if 'being[]' and 'name' are locals (or 'k' if 'being' is
global), then the function will need those extra parameters. In
that case, the sdodge calls will not be so different from the
original slog calls.
All we can do is suggest different ideas and ways to arrange such
code, and maybe the OP will see something he feels is a good fit for
his needs.ÿ As you say, we are missing a lot of information about
the rest of the code - we don't know what data is "global" or local,
when any of these parts might be re-used, how likely it is that the
details or boundary points will be changed, and countless other
details.
In general, I am very sceptical about using macros for this kind of
thing.ÿ It is correct that they let you implicitly pass local data
into the macro in a way that functions do not - but that can make
the structure a lot harder to follow, and becomes fragile for
changes. So while it is definitely something that can occasionally
be helpful, I think it is rarely the best solution.
If the OP is happy with compiler extensions, a possibility here is
gcc nested functions - these can capture such local variables in a
safer and more structured manner, keeping the details within the
function itself. (Or he could use C++ and lambdas for a similar
effect.ÿ There are proposals to add lambdas to C, but they are not
standardised yet.)
will touch c it would be a heavy disaster (they touched it already
too much)
what i strongly need is those long t = 'somethin'; here to this tags
could work up to 8 lengthÿ (or 16 if some cpu has 128 bit ints)
I used to have both of those (in my language), so I could write
'ABCDEFGHIJKLMNOP' which had an u128 type. I've now dropped 128-bit
types as they were not that useful to me (only for implementing 128-
types within the compiler!).
I still have 'ABCDEFGH'.
C however limits such constants to the size of 'int', which is rarely
bigger than 32 bits, so it can only have 'ABCD' (and C itself may only
guarantee 'A').
(My C compiler is different, in allowing 'ABCDEFGH'; I think it yields
a 64-bit type in this case.)
So, given the current limitations, then what are you suggesting? Are
these just ideas for C extensions, or for a new language?
If you need such features now, then putting these ideas out there is
not going to be of immediate help.
I suggest, if you really need those features soon (this is including
the new 'match' statements), that you write a special preprocessor
which takes programs written in this enhanced C, and generates
standard C.
So, 'ABCDEFGH' will be converted to perhaps 0x4847464544434241.
I STRONGLY NEED IT AND C STRONGLY NEED IT
IT OR YET BETTER SOME GENERALISATION OF IT
i already was writing on it but may repeat
i name it adhoc enum : 'sjhbshj' is an adhoc enum i mean you could
write anyting (though possibly alphanumeric) between '' and compare it
to another ''
On 06/09/2026 11:12, fir wrote:
David Brown pisze:
On 06/09/2026 01:06, bart wrote:lol, adding almbdas to c that would be a trash... if the populist will
On 05/09/2026 18:03, Janis Papanagnou wrote:
On 2026-09-05 16:16, David Brown wrote:
On 05/09/2026 14:10, bart wrote:
There isn't enough info to see how to write an effective function.(It's beyond me why one would prefer macros to a function here.
ÿÿ #define sdodge(x) slog("%s" x "dodged attack...", being[k], name) >>>>>
But your basic idea to extract the invariant is of course sensible.)
But if 'being[]' and 'name' are locals (or 'k' if 'being' is
global), then the function will need those extra parameters. In that
case, the sdodge calls will not be so different from the original
slog calls.
All we can do is suggest different ideas and ways to arrange such
code, and maybe the OP will see something he feels is a good fit for
his needs.ÿ As you say, we are missing a lot of information about the
rest of the code - we don't know what data is "global" or local, when
any of these parts might be re-used, how likely it is that the
details or boundary points will be changed, and countless other details. >>>
In general, I am very sceptical about using macros for this kind of
thing.ÿ It is correct that they let you implicitly pass local data
into the macro in a way that functions do not - but that can make the
structure a lot harder to follow, and becomes fragile for changes.
So while it is definitely something that can occasionally be helpful,
I think it is rarely the best solution.
If the OP is happy with compiler extensions, a possibility here is
gcc nested functions - these can capture such local variables in a
safer and more structured manner, keeping the details within the
function itself. (Or he could use C++ and lambdas for a similar
effect.ÿ There are proposals to add lambdas to C, but they are not
standardised yet.)
touch c it would be a heavy disaster (they touched it already too much)
what i strongly need is those long t = 'somethin'; here to this tags
could work up to 8 lengthÿ (or 16 if some cpu has 128 bit ints)
I used to have both of those (in my language), so I could write 'ABCDEFGHIJKLMNOP' which had an u128 type. I've now dropped 128-bit
types as they were not that useful to me (only for implementing 128-
types within the compiler!).
I still have 'ABCDEFGH'.
C however limits such constants to the size of 'int', which is rarely
bigger than 32 bits, so it can only have 'ABCD' (and C itself may only guarantee 'A').
(My C compiler is different, in allowing 'ABCDEFGH'; I think it yields a 64-bit type in this case.)
So, given the current limitations, then what are you suggesting? Are
these just ideas for C extensions, or for a new language?
If you need such features now, then putting these ideas out there is not going to be of immediate help.
I suggest, if you really need those features soon (this is including the
new 'match' statements), that you write a special preprocessor which
takes programs written in this enhanced C, and generates standard C.
So, 'ABCDEFGH' will be converted to perhaps 0x4847464544434241.
| Sysop: | Tetrazocine |
|---|---|
| Location: | Melbourne, VIC, Australia |
| Users: | 9 |
| Nodes: | 8 (0 / 8) |
| Uptime: | 245:24:22 |
| Calls: | 220 |
| Files: | 21,513 |
| Messages: | 83,782 |