Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Truth has always been found to promote the best interests of mankind... -- Percy Bysshe Shelley


devel / comp.lang.c / A question about style

SubjectAuthor
* A question about styleOğuz
+* Re: A question about styleÖö Tiib
|`* Re: A question about styleÖö Tiib
| +- Re: A question about styleJames rock
| `- Re: A question about styleOğuz
+* Re: A question about styleStefan Ram
|+- Re: A question about styleStefan Ram
|+* Re: A question about styleBonita Montero
||`- Re: A question about styleMeredith Montgomery
|`* Re: A question about styleStefan Ram
| `* Re: A question about styleStefan Ram
|  `- Re: A question about styleKeith Thompson
+- Re: A question about styleManfred
+- Re: A question about styleBart
+* Re: A question about stylePaul N
|`- Re: A question about styleOğuz
+* Re: A question about styleTim Rentsch
|`- Re: A question about styleOğuz
`- Re: A question about styleJens Schweikhardt

1
A question about style

<sqjivq$get$1@oguzismail.eternal-september.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19681&group=comp.lang.c#19681

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!oguzismail.eternal-september.org!.POSTED!not-for-mail
From: oguzisma...@gmail.com (Oğuz)
Newsgroups: comp.lang.c
Subject: A question about style
Date: Thu, 30 Dec 2021 09:18:33 +0300
Organization: A noiseless patient Spider
Lines: 32
Message-ID: <sqjivq$get$1@oguzismail.eternal-september.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 30 Dec 2021 06:18:34 -0000 (UTC)
Injection-Info: oguzismail.eternal-september.org; posting-host="5ae9c1b1958748c13b2c93f5682e63ae";
logging-data="16861"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18d4OqDAmRL598yXlz1VcuGTH47jNNnZZM="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.14.0
Cancel-Lock: sha1:uaolw2ok3ijaiDu9Wphr8dZUqY0=
Content-Language: en-US
X-Mozilla-News-Host: news://news.eternal-september.org:119
 by: Oğuz - Thu, 30 Dec 2021 06:18 UTC

I have this if-else thingy:

if (!expr[expr_length - 1].is_number) {
if (skip_adj[expr[expr_length - 1].value][op])
return false;
} else if (expr_length > 2 && !expr[expr_length - 2].is_number) {
if (skip_alt[expr[expr_length - 2].value][op])
return false;
else if (expr[expr_length - 3].is_number
&& expr[expr_length - 3].value < expr[expr_length - 1].value
&& skip_alt_asc[expr[expr_length - 2].value][op])
return false;
}

(`expr' is a fixed-size array of structs, I increase `expr_length' as I
fill it in. `skip_*' are two dimensional arrays of booleans, but I don't
have any problem regarding them.)

And it looks ugly; barely readable even with comments. I want it to be
readable at least. Possible emendations I can think of are:

1. Define macros for `expr[expr_length - 1]', `expr[expr_length - 2]',
etc. and use them instead. But, what am I gonna name them?

2. Define a macro `expr_end' for `(expr + expr_length)', and use
`expr_end[-1]', `expr_end[-2]', etc. instead. But I'm afraid this might
still be hard to understand for someone who's not familiar with the code
(e.g. me 3 months later from now).

So, do you guys have better ideas for making this piece of crap a bit
more readable (other than rewriting it in C++)? Thanks in advance.

Re: A question about style

<bcf48015-4952-469d-bf69-899c264c7941n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19684&group=comp.lang.c#19684

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:ac8:5b01:: with SMTP id m1mr25813222qtw.313.1640868143047;
Thu, 30 Dec 2021 04:42:23 -0800 (PST)
X-Received: by 2002:a05:620a:28c8:: with SMTP id l8mr19140601qkp.362.1640868142913;
Thu, 30 Dec 2021 04:42:22 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c
Date: Thu, 30 Dec 2021 04:42:22 -0800 (PST)
In-Reply-To: <sqjivq$get$1@oguzismail.eternal-september.org>
Injection-Info: google-groups.googlegroups.com; posting-host=94.246.251.164; posting-account=pysjKgkAAACLegAdYDFznkqjgx_7vlUK
NNTP-Posting-Host: 94.246.251.164
References: <sqjivq$get$1@oguzismail.eternal-september.org>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <bcf48015-4952-469d-bf69-899c264c7941n@googlegroups.com>
Subject: Re: A question about style
From: oot...@hot.ee (Öö Tiib)
Injection-Date: Thu, 30 Dec 2021 12:42:23 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 42
 by: Öö Tiib - Thu, 30 Dec 2021 12:42 UTC

On Thursday, 30 December 2021 at 08:18:46 UTC+2, oguzism...@gmail.com wrote:
> I have this if-else thingy:
>
> if (!expr[expr_length - 1].is_number) {
> if (skip_adj[expr[expr_length - 1].value][op])
> return false;
> }
> else if (expr_length > 2 && !expr[expr_length - 2].is_number) {
> if (skip_alt[expr[expr_length - 2].value][op])
> return false;
> else if (expr[expr_length - 3].is_number
> && expr[expr_length - 3].value < expr[expr_length - 1].value
> && skip_alt_asc[expr[expr_length - 2].value][op])
> return false;
> }
>
> (`expr' is a fixed-size array of structs, I increase `expr_length' as I
> fill it in. `skip_*' are two dimensional arrays of booleans, but I don't
> have any problem regarding them.)
>
> And it looks ugly; barely readable even with comments. I want it to be
> readable at least. Possible emendations I can think of are:
>
> 1. Define macros for `expr[expr_length - 1]', `expr[expr_length - 2]',
> etc. and use them instead. But, what am I gonna name them?
>
> 2. Define a macro `expr_end' for `(expr + expr_length)', and use
> `expr_end[-1]', `expr_end[-2]', etc. instead. But I'm afraid this might
> still be hard to understand for someone who's not familiar with the code
> (e.g. me 3 months later from now).
>
> So, do you guys have better ideas for making this piece of crap a bit
> more readable (other than rewriting it in C++)? Thanks in advance.

Ugly or not ugly is matter of taste but you seem to try to bike-shed
into aesthetics instead of fixing logical issues?

See: One condition of yours detects that expr_length > 2 its else
however (so case when expr_length is 0, 1 or 2?) does check
expr[expr_length - 3].is_number. That means expr[-3].is_number,
expr[-2].is_number or expr[-1].is_number. So either it was
known before that expr_length > 2 always and so the check was
pointless or you have undefined behavior.

Re: A question about style

<4f9f7be0-2902-4b39-ad0a-4451d05abe83n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19685&group=comp.lang.c#19685

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a05:6214:2aaa:: with SMTP id js10mr24308253qvb.38.1640868442201;
Thu, 30 Dec 2021 04:47:22 -0800 (PST)
X-Received: by 2002:a05:620a:2981:: with SMTP id r1mr21611351qkp.100.1640868442089;
Thu, 30 Dec 2021 04:47:22 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c
Date: Thu, 30 Dec 2021 04:47:21 -0800 (PST)
In-Reply-To: <bcf48015-4952-469d-bf69-899c264c7941n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=94.246.251.164; posting-account=pysjKgkAAACLegAdYDFznkqjgx_7vlUK
NNTP-Posting-Host: 94.246.251.164
References: <sqjivq$get$1@oguzismail.eternal-september.org> <bcf48015-4952-469d-bf69-899c264c7941n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <4f9f7be0-2902-4b39-ad0a-4451d05abe83n@googlegroups.com>
Subject: Re: A question about style
From: oot...@hot.ee (Öö Tiib)
Injection-Date: Thu, 30 Dec 2021 12:47:22 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Lines: 52
 by: Öö Tiib - Thu, 30 Dec 2021 12:47 UTC

On Thursday, 30 December 2021 at 14:42:28 UTC+2, Öö Tiib wrote:
> On Thursday, 30 December 2021 at 08:18:46 UTC+2, oguzism...@gmail.com wrote:
> > I have this if-else thingy:
> >
> > if (!expr[expr_length - 1].is_number) {
> > if (skip_adj[expr[expr_length - 1].value][op])
> > return false;
> > }
> > else if (expr_length > 2 && !expr[expr_length - 2].is_number) {
> > if (skip_alt[expr[expr_length - 2].value][op])
> > return false;
> > else if (expr[expr_length - 3].is_number
> > && expr[expr_length - 3].value < expr[expr_length - 1].value
> > && skip_alt_asc[expr[expr_length - 2].value][op])
> > return false;
> > }
> >
> > (`expr' is a fixed-size array of structs, I increase `expr_length' as I
> > fill it in. `skip_*' are two dimensional arrays of booleans, but I don't
> > have any problem regarding them.)
> >
> > And it looks ugly; barely readable even with comments. I want it to be
> > readable at least. Possible emendations I can think of are:
> >
> > 1. Define macros for `expr[expr_length - 1]', `expr[expr_length - 2]',
> > etc. and use them instead. But, what am I gonna name them?
> >
> > 2. Define a macro `expr_end' for `(expr + expr_length)', and use
> > `expr_end[-1]', `expr_end[-2]', etc. instead. But I'm afraid this might
> > still be hard to understand for someone who's not familiar with the code
> > (e.g. me 3 months later from now).
> >
> > So, do you guys have better ideas for making this piece of crap a bit
> > more readable (other than rewriting it in C++)? Thanks in advance.
> Ugly or not ugly is matter of taste but you seem to try to bike-shed
> into aesthetics instead of fixing logical issues?
>
> See: One condition of yours detects that expr_length > 2 its else
> however (so case when expr_length is 0, 1 or 2?) does check
> expr[expr_length - 3].is_number. That means expr[-3].is_number,
> expr[-2].is_number or expr[-1].is_number. So either it was
> known before that expr_length > 2 always and so the check was
> pointless or you have undefined behavior.

Nah scratch it. My bad i misread your code.

Re: A question about style

<sqkk38$plfh$1@news.mixmin.net>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19688&group=comp.lang.c#19688

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!aioe.org!news.mixmin.net!.POSTED!not-for-mail
From: jamesroa...@gmail.com (James rock)
Newsgroups: comp.lang.c
Subject: Re: A question about style
Date: Thu, 30 Dec 2021 15:40:21 +0000
Organization: Microsoft Unofficial Representative on Newsgroups
Message-ID: <sqkk38$plfh$1@news.mixmin.net>
References: <sqjivq$get$1@oguzismail.eternal-september.org>
<bcf48015-4952-469d-bf69-899c264c7941n@googlegroups.com>
<4f9f7be0-2902-4b39-ad0a-4451d05abe83n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=ascii-us;
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 30 Dec 2021 15:43:36 -0000 (UTC)
Injection-Info: news.mixmin.net; posting-host="9f3e0662dac90d1882b2aff26b6a5f11d87f32af";
logging-data="841201"; mail-complaints-to="abuse@mixmin.net"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:68.0) Gecko/20100101
Thunderbird/91.4.1
In-Reply-To: <4f9f7be0-2902-4b39-ad0a-4451d05abe83n@googlegroups.com>
Content-Language: en-IN
 by: James rock - Thu, 30 Dec 2021 15:40 UTC

On 30/12/2021 12:47, Öö Tiib wrote:
> Nah scratch it. My bad i misread your code.

That's what he said!.

"barely readable even with comments"

Re: A question about style

<sqkmg9$gmr$1@oguzismail.eternal-september.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19689&group=comp.lang.c#19689

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!oguzismail.eternal-september.org!.POSTED!not-for-mail
From: oguzisma...@gmail.com (Oğuz)
Newsgroups: comp.lang.c
Subject: Re: A question about style
Date: Thu, 30 Dec 2021 19:24:41 +0300
Organization: A noiseless patient Spider
Lines: 7
Message-ID: <sqkmg9$gmr$1@oguzismail.eternal-september.org>
References: <sqjivq$get$1@oguzismail.eternal-september.org>
<bcf48015-4952-469d-bf69-899c264c7941n@googlegroups.com>
<4f9f7be0-2902-4b39-ad0a-4451d05abe83n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 30 Dec 2021 16:24:41 -0000 (UTC)
Injection-Info: oguzismail.eternal-september.org; posting-host="5ae9c1b1958748c13b2c93f5682e63ae";
logging-data="17115"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19cLBoq6cwIDSbV8sErmz30Z157HavYiSo="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.14.0
Cancel-Lock: sha1:jN91VMrS9BU0rJVvkKb46vnwSsk=
In-Reply-To: <4f9f7be0-2902-4b39-ad0a-4451d05abe83n@googlegroups.com>
Content-Language: en-US
 by: Oğuz - Thu, 30 Dec 2021 16:24 UTC

On 12/30/21 3:47 PM, Öö Tiib wrote:
> [...]
> Nah scratch it. My bad i misread your code.
>

No problem. At least now I know it's worse than I thought

Re: A question about style

<style-20211230175438@ram.dialup.fu-berlin.de>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19690&group=comp.lang.c#19690

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: ram...@zedat.fu-berlin.de (Stefan Ram)
Newsgroups: comp.lang.c
Subject: Re: A question about style
Date: 30 Dec 2021 16:57:08 GMT
Organization: Stefan Ram
Lines: 52
Expires: 1 Apr 2022 11:59:58 GMT
Message-ID: <style-20211230175438@ram.dialup.fu-berlin.de>
References: <sqjivq$get$1@oguzismail.eternal-september.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de gxbhH9i8VwM+z6SVrbBF8AultITNV3Zi4Ku74dBW23FSg8
X-Copyright: (C) Copyright 2021 Stefan Ram. All rights reserved.
Distribution through any means other than regular usenet
channels is forbidden. It is forbidden to publish this
article in the Web, to change URIs of this article into links,
and to transfer the body without this notice, but quotations
of parts in other Usenet posts are allowed.
X-No-Archive: Yes
Archive: no
X-No-Archive-Readme: "X-No-Archive" is set, because this prevents some
services to mirror the article in the web. But the article may
be kept on a Usenet archive server with only NNTP access.
X-No-Html: yes
Content-Language: en-US
Accept-Language: de-DE, en-US, it, fr-FR
 by: Stefan Ram - Thu, 30 Dec 2021 16:57 UTC

=?UTF-8?B?T8SfdXo=?= <oguzismailuysal@gmail.com> writes:
>1. Define macros for `expr[expr_length - 1]', `expr[expr_length - 2]',
>etc. and use them instead. But, what am I gonna name them?

This is what you need to find out. For the rest of us
without knowledge of the actual meaning of those
expressions, it is even more difficult or impossible to find
good names. These names are the key to improved readability.

I would use functions. They are safer than macros, more
readable, and with inlining not slower either.

I'd start this way: In pseudocode, the code you posted has
the structure:

int f( void ){ return g()? h(): i(); }

with

inline int g( void )
{ return !expr[ expr_length - 1 ].is_number; }

,

inline int h( void )
{ if( skip_adj[ expr[ expr_length - 1 ].value][ op ])
return 0; }

, and

inline int i( void )
{ if
( expr_length > 2 &&
!expr[ expr_length - 2 ].is_number )
if( skip_alt[ expr[ expr_length - 2 ].value][ op ])return 0;
else
if
( expr[ expr_length - 3 ].is_number &&
expr[ expr_length - 3 ].value < expr[ expr_length - 1 ].value &&
skip_alt_asc[ expr[ expr_length - 2 ].value][ op ])
return 0;}

Now, we see that h and i do not always return a definite
value. This needs to be dealt with.

Then, the most important thing, replace "g", "h" and "i" by
good names!

Finally, apply this approach recursively to the function "i"
to decompose it into smaller functions as well.

Re: A question about style

<sqkqit$19s8$1@gioia.aioe.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19692&group=comp.lang.c#19692

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!aioe.org!Puiiztk9lHEEQC0y3uUjRA.user.46.165.242.75.POSTED!not-for-mail
From: non...@add.invalid (Manfred)
Newsgroups: comp.lang.c
Subject: Re: A question about style
Date: Thu, 30 Dec 2021 18:34:21 +0100
Organization: Aioe.org NNTP Server
Message-ID: <sqkqit$19s8$1@gioia.aioe.org>
References: <sqjivq$get$1@oguzismail.eternal-september.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Info: gioia.aioe.org; logging-data="42888"; posting-host="Puiiztk9lHEEQC0y3uUjRA.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.4.1
X-Notice: Filtered by postfilter v. 0.9.2
Content-Language: en-US
 by: Manfred - Thu, 30 Dec 2021 17:34 UTC

On 12/30/2021 7:18 AM, Oğuz wrote:
> I have this if-else thingy:
>
> if (!expr[expr_length - 1].is_number) {
>   if (skip_adj[expr[expr_length - 1].value][op])
>     return false;
> }
> else if (expr_length > 2 && !expr[expr_length - 2].is_number) {
>   if (skip_alt[expr[expr_length - 2].value][op])
>     return false;
>   else if (expr[expr_length - 3].is_number
>       && expr[expr_length - 3].value < expr[expr_length - 1].value
>       && skip_alt_asc[expr[expr_length - 2].value][op])
>     return false;
> }
>
> (`expr' is a fixed-size array of structs, I increase `expr_length' as I
> fill it in. `skip_*' are two dimensional arrays of booleans, but I don't
> have any problem regarding them.)
>
> And it looks ugly; barely readable even with comments. I want it to be
> readable at least. Possible emendations I can think of are:
>
> 1. Define macros for `expr[expr_length - 1]', `expr[expr_length - 2]',
> etc. and use them instead. But, what am I gonna name them?
>
> 2. Define a macro `expr_end' for `(expr + expr_length)', and use
> `expr_end[-1]', `expr_end[-2]', etc. instead. But I'm afraid this might
> still be hard to understand for someone who's not familiar with the code
> (e.g. me 3 months later from now).
>
> So, do you guys have better ideas for making this piece of crap a bit
> more readable (other than rewriting it in C++)? Thanks in advance.

Maybe Öö Tiib still has a point: it's probably more about the logic than
aesthetics - I mean, your code might be logically correct, but it is the
underlying model that is not clear.
Often, in this kind of thing, a clear code is the result of:
- clear requirements
- clear logic modeled upon such requirements
- then, translation of model into code is often also clear.

What makes me wonder most about those lines is that all that if/else
intricacy is done to yield a true/false flag - is this really the best
possible design of what you are trying to do (whatever it may be)?

Re: A question about style

<names-20211230185205@ram.dialup.fu-berlin.de>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19693&group=comp.lang.c#19693

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: ram...@zedat.fu-berlin.de (Stefan Ram)
Newsgroups: comp.lang.c
Subject: Re: A question about style
Date: 30 Dec 2021 17:52:54 GMT
Organization: Stefan Ram
Lines: 60
Expires: 1 Apr 2022 11:59:58 GMT
Message-ID: <names-20211230185205@ram.dialup.fu-berlin.de>
References: <sqjivq$get$1@oguzismail.eternal-september.org> <style-20211230175438@ram.dialup.fu-berlin.de>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de d9bkFy3A/JNrz3P/q9ulMwYYYqtNgjnRTlQ30QiHfY9uzH
X-Copyright: (C) Copyright 2021 Stefan Ram. All rights reserved.
Distribution through any means other than regular usenet
channels is forbidden. It is forbidden to publish this
article in the Web, to change URIs of this article into links,
and to transfer the body without this notice, but quotations
of parts in other Usenet posts are allowed.
X-No-Archive: Yes
Archive: no
X-No-Archive-Readme: "X-No-Archive" is set, because this prevents some
services to mirror the article in the web. But the article may
be kept on a Usenet archive server with only NNTP access.
X-No-Html: yes
Content-Language: en-US
Accept-Language: de-DE, en-US, it, fr-FR
 by: Stefan Ram - Thu, 30 Dec 2021 17:52 UTC

ram@zedat.fu-berlin.de (Stefan Ram) writes:
>These names are the key to improved readability.

Here's an example from a computer program I wrote in a
programming language called "Python". Before refactoring:

ad=600
mx = 1.2
lb = mx*ad
rb = lb + (mx-1)*ad
if i < lb:
cf = i/ad
elif i < rb:
wb = rb-lb
vb = (lb-rb)/mx
cf = (i-lb)/wb + (i-rb)/vb
elif n-i <( 10*ad if vib else ad ):
cf =( n - i )/( 10*ad if vib else ad )
else:
cf= 1

Before reading on, you can try to guess what it does!

After refactoring (some lines now have more than 72 characters):

(The "vib" part was removed since it was not needed anymore.)

def hull_curve_of( frame_number, integral_duration ):
'''
preconditions:
frame_number <= integral_duration
integral_duration > -1
/`-.
ADSR
attack-decay-sustain-release curve
attack: rise to maximum_intensity until end_of_attack,
decay: then fall to 1 until end_of_decay,
sustain: then, sustain the value of 1 until integral_duration - initial_duration,
release: finally, fall to 0 until integral_duration
'''
initial_duration = 600
maximum_intensity = 1.2
end_of_attack = maximum_intensity * initial_duration
end_of_decay = end_of_attack +( maximum_intensity - 1 )* initial_duration
if frame_number < end_of_attack: # A attack from 0 to maximum_intensity, reaching 1 at attack_duration
hull_curve = frame_number / initial_duration
elif frame_number < end_of_decay: # D decay from maximum_intensity to 1
width_of_decay = end_of_decay - end_of_attack
goes_from_0_to_1 =( frame_number - end_of_attack )/width_of_decay
goes_from_maximum_intensity_to_0 = maximum_intensity *( end_of_decay - frame_number )/ width_of_decay
hull_curve = goes_from_0_to_1 + goes_from_maximum_intensity_to_0
elif integral_duration - initial_duration < frame_number: # R release
hull_curve =( integral_duration - frame_number )/ initial_duration
else: # S sustain at 1
hull_curve = 1
return hull_curve

There is still room for improvement, but it's a start!

Re: A question about style

<sqkste$kuu$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19694&group=comp.lang.c#19694

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: bc...@freeuk.com (Bart)
Newsgroups: comp.lang.c
Subject: Re: A question about style
Date: Thu, 30 Dec 2021 18:14:06 +0000
Organization: A noiseless patient Spider
Lines: 36
Message-ID: <sqkste$kuu$1@dont-email.me>
References: <sqjivq$get$1@oguzismail.eternal-september.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 30 Dec 2021 18:14:06 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="50a6f6e5a951aff34d7b2de53679ba6e";
logging-data="21470"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/JrgGKB55xNPOHlKppwP35n12/yzoBFVo="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.4.1
Cancel-Lock: sha1:Fz8TWec0mjIJQZNcWtiwqYbDQkk=
In-Reply-To: <sqjivq$get$1@oguzismail.eternal-september.org>
 by: Bart - Thu, 30 Dec 2021 18:14 UTC

On 30/12/2021 06:18, Oğuz wrote:
> if (!expr[expr_length - 1].is_number) {
>   if (skip_adj[expr[expr_length - 1].value][op])
>     return false;
> }
> else if (expr_length > 2 && !expr[expr_length - 2].is_number) {
>   if (skip_alt[expr[expr_length - 2].value][op])
>     return false;
>   else if (expr[expr_length - 3].is_number
>       && expr[expr_length - 3].value < expr[expr_length - 1].value
>       && skip_alt_asc[expr[expr_length - 2].value][op])
>     return false;
> }

Assuming expr is some sort of stack:

#define A (expr[expr_length-1])
#define B (expr[expr_length-2])
#define C (expr[expr_length-3])

int dummy(void) {
if (!A.is_number) {
if (skip_adj[A.value][op])
return false;
}
else if (expr_length > 2 && !B.is_number) {
if (skip_alt[B.value][op]) {
return false;
}
else if (C.is_number
&& C.value < A.value
&& skip_alt_asc[B.value][op]) {
return false;
}
}
}

Re: A question about style

<sqkul5$mts$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19695&group=comp.lang.c#19695

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c
Subject: Re: A question about style
Date: Thu, 30 Dec 2021 19:43:50 +0100
Organization: A noiseless patient Spider
Lines: 2
Message-ID: <sqkul5$mts$1@dont-email.me>
References: <sqjivq$get$1@oguzismail.eternal-september.org>
<style-20211230175438@ram.dialup.fu-berlin.de>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 30 Dec 2021 18:43:49 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="90b72dc0315508f333fb62cb4b50bd5b";
logging-data="23484"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19ebplas+sK3N7Q46Fwrx3vNqnzn1Zy4UI="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.4.1
Cancel-Lock: sha1:1gPjixH3IBxmerWAC9gzTc9zZCg=
In-Reply-To: <style-20211230175438@ram.dialup.fu-berlin.de>
Content-Language: de-DE
 by: Bonita Montero - Thu, 30 Dec 2021 18:43 UTC

Your coding-style is ugly as hell.
That would be a disqualifcation for any job.

Re: A question about style

<867dblrhng.fsf@levado.to>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19696&group=comp.lang.c#19696

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!aioe.org!PAYdTDNQiHiNVp9In8hKoQ.user.46.165.242.75.POSTED!not-for-mail
From: mmontgom...@levado.to (Meredith Montgomery)
Newsgroups: comp.lang.c
Subject: Re: A question about style
Date: Thu, 30 Dec 2021 16:56:19 -0300
Organization: Aioe.org NNTP Server
Message-ID: <867dblrhng.fsf@levado.to>
References: <sqjivq$get$1@oguzismail.eternal-september.org>
<style-20211230175438@ram.dialup.fu-berlin.de>
<sqkul5$mts$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: gioia.aioe.org; logging-data="51177"; posting-host="PAYdTDNQiHiNVp9In8hKoQ.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
X-Notice: Filtered by postfilter v. 0.9.2
Cancel-Lock: sha1:qNNm3Mw2epEbcbhbBSkw1xW95EU=
 by: Meredith Montgomery - Thu, 30 Dec 2021 19:56 UTC

Bonita Montero <Bonita.Montero@gmail.com> writes:

> Your coding-style is ugly as hell.
> That would be a disqualifcation for any job.

Lol. You forget to cite the source of this quote. Let me help you.

The USENET Guide, chapter 2, section 2.71828182845904523536, ``how to
make new friends on the USENET'', Mark V. Shaney, 1993.

Re: A question about style

<0269f6e4-3438-4739-b37c-483ff4c869b6n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19697&group=comp.lang.c#19697

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:ac8:57c2:: with SMTP id w2mr27772070qta.54.1640895335293;
Thu, 30 Dec 2021 12:15:35 -0800 (PST)
X-Received: by 2002:ad4:5c45:: with SMTP id a5mr29865894qva.7.1640895335123;
Thu, 30 Dec 2021 12:15:35 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c
Date: Thu, 30 Dec 2021 12:15:34 -0800 (PST)
In-Reply-To: <sqjivq$get$1@oguzismail.eternal-september.org>
Injection-Info: google-groups.googlegroups.com; posting-host=2.97.142.119; posting-account=0B-afgoAAABP6274zLUJKa8ZpdIdhsYx
NNTP-Posting-Host: 2.97.142.119
References: <sqjivq$get$1@oguzismail.eternal-september.org>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <0269f6e4-3438-4739-b37c-483ff4c869b6n@googlegroups.com>
Subject: Re: A question about style
From: gw7...@aol.com (Paul N)
Injection-Date: Thu, 30 Dec 2021 20:15:35 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 55
 by: Paul N - Thu, 30 Dec 2021 20:15 UTC

On Thursday, December 30, 2021 at 6:18:46 AM UTC, oguzism...@gmail.com wrote:
> I have this if-else thingy:
>
> if (!expr[expr_length - 1].is_number) {
> if (skip_adj[expr[expr_length - 1].value][op])
> return false;
> }
> else if (expr_length > 2 && !expr[expr_length - 2].is_number) {
> if (skip_alt[expr[expr_length - 2].value][op])
> return false;
> else if (expr[expr_length - 3].is_number
> && expr[expr_length - 3].value < expr[expr_length - 1].value
> && skip_alt_asc[expr[expr_length - 2].value][op])
> return false;
> }
>
> (`expr' is a fixed-size array of structs, I increase `expr_length' as I
> fill it in. `skip_*' are two dimensional arrays of booleans, but I don't
> have any problem regarding them.)
>
> And it looks ugly; barely readable even with comments. I want it to be
> readable at least. Possible emendations I can think of are:
>
> 1. Define macros for `expr[expr_length - 1]', `expr[expr_length - 2]',
> etc. and use them instead. But, what am I gonna name them?
>
> 2. Define a macro `expr_end' for `(expr + expr_length)', and use
> `expr_end[-1]', `expr_end[-2]', etc. instead. But I'm afraid this might
> still be hard to understand for someone who's not familiar with the code
> (e.g. me 3 months later from now).
>
> So, do you guys have better ideas for making this piece of crap a bit
> more readable (other than rewriting it in C++)? Thanks in advance.

How about something like the following? I imagine some of the variables are locals rather than globals so would need to be passed as arguments but this is a rough idea.

int skip(int type, int val, int op) {
switch(type) {
case 1: return skip_adj[val][op];
case 2: return skip_alt[val][op];
default: return skip_alt_asc[val][op]; }

int is_number(int len, int pos) {
return len > pos && !expr[len - pos].is_number; }

....
if (is_number(expr_length, 1)) { // this will do a check on length that the original didn't
if (skip(1, expr[expr_length - 1].value, op)) return false; }
else if (is_number(expr_length, 2) {
if (skip(2, expr[expr_length - 2].value, op)) return false;
else if (expr[expr_length - 3].is_number
&& expr[expr_length - 3].value < expr[expr_length - 1].value
&& skip(3, expr[expr_length - 2].value, op) return false;
}

Re: A question about style

<returns-20211230225942@ram.dialup.fu-berlin.de>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19700&group=comp.lang.c#19700

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: ram...@zedat.fu-berlin.de (Stefan Ram)
Newsgroups: comp.lang.c
Subject: Re: A question about style
Date: 30 Dec 2021 22:00:28 GMT
Organization: Stefan Ram
Lines: 19
Expires: 1 Apr 2022 11:59:58 GMT
Message-ID: <returns-20211230225942@ram.dialup.fu-berlin.de>
References: <sqjivq$get$1@oguzismail.eternal-september.org> <style-20211230175438@ram.dialup.fu-berlin.de>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de 6CfvlNrQNkdNe5XaUwrNCgKy2ZsfHySPufpCwhSGTp5zmf
X-Copyright: (C) Copyright 2021 Stefan Ram. All rights reserved.
Distribution through any means other than regular usenet
channels is forbidden. It is forbidden to publish this
article in the Web, to change URIs of this article into links,
and to transfer the body without this notice, but quotations
of parts in other Usenet posts are allowed.
X-No-Archive: Yes
Archive: no
X-No-Archive-Readme: "X-No-Archive" is set, because this prevents some
services to mirror the article in the web. But the article may
be kept on a Usenet archive server with only NNTP access.
X-No-Html: yes
Content-Language: en-US
Accept-Language: de-DE, en-US, it, fr-FR
 by: Stefan Ram - Thu, 30 Dec 2021 22:00 UTC

ram@zedat.fu-berlin.de (Stefan Ram) writes:
>Now, we see that h and i do not always return a definite
>value. This needs to be dealt with.

I now see that my code does not the same as the original code.
In the case that none of the "return" statements would be
executed, the original code would simply continue to do what
follows it. I could not take that into consideration because
the code that follows it was not available to me.

So, my answer should not be taken literally (that's why
I wrote "pseudocode"). I just wanted to convey the general
idea of:

"Split it into meaningful functions with meaningful
names, and if that is not possible, reorganize the
code so that it becomes possible!".

Re: A question about style

<86ee5tzra5.fsf@linuxsc.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19701&group=comp.lang.c#19701

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: tr.17...@z991.linuxsc.com (Tim Rentsch)
Newsgroups: comp.lang.c
Subject: Re: A question about style
Date: Thu, 30 Dec 2021 14:01:06 -0800
Organization: A noiseless patient Spider
Lines: 84
Message-ID: <86ee5tzra5.fsf@linuxsc.com>
References: <sqjivq$get$1@oguzismail.eternal-september.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Injection-Info: reader02.eternal-september.org; posting-host="0a3a87556a94a586a5bc6690bb7b95d8";
logging-data="420"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+YMSvVFwQFb9XoclqyVQNs56oWnU9ei1A="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:3F/ifDN/qu0XBN1ASUkbhJxRAHo=
sha1:CpJniICbvvVze1F9BhC+4mG7Hd4=
 by: Tim Rentsch - Thu, 30 Dec 2021 22:01 UTC

Oğuz <oguzismailuysal@gmail.com> writes:

> I have this if-else thingy:
>
> if (!expr[expr_length - 1].is_number) {
> if (skip_adj[expr[expr_length - 1].value][op])
> return false;
> }
> else if (expr_length > 2 && !expr[expr_length - 2].is_number) {
> if (skip_alt[expr[expr_length - 2].value][op])
> return false;
> else if (expr[expr_length - 3].is_number
> && expr[expr_length - 3].value < expr[expr_length - 1].value
> && skip_alt_asc[expr[expr_length - 2].value][op])
> return false;
> }
>
> (`expr' is a fixed-size array of structs, I increase `expr_length'
> as I fill it in. `skip_*' are two dimensional arrays of booleans,
> but I don't have any problem regarding them.)
>
> And it looks ugly; barely readable even with comments. I want it
> to be readable at least. [...]

Putting the code in the context of a function body (with a
'return 5;' at the end just to pick a value obviously not
the same as 'false'):

int
original_code(){
if (!expr[expr_length - 1].is_number) {
if (skip_adj[expr[expr_length - 1].value][op])
return false;
}
else if (expr_length > 2 && !expr[expr_length - 2].is_number) {
if (skip_alt[expr[expr_length - 2].value][op])
return false;
else if (expr[expr_length - 3].is_number
&& expr[expr_length - 3].value < expr[expr_length - 1].value
&& skip_alt_asc[expr[expr_length - 2].value][op])
return false;
}
return 5;
}

Assuming no major changes to the code (so stipulating any changes
be kept local to this one function), and taking 'expr' to be an
array of type 'Expression', I would try something along these
lines:

int
possible_revision(){
Expression *e = expr + expr_length;

if( e[-1].is_number ){
if( skip_adj[ e[-1].value ][op] ) return false;

} else if( expr_length > 2 && e[-2].is_number ){
if(
skip_alt[ e[-2].value ][op] || (
e[-3].is_number &&
e[-3].value < e[-1].value &&
skip_alt_asc[ e[-2].value ][op]
)
){
return false;
}
}

return 5;
}

To me this way of writing is cleaner and easier to take in. I
have the sense that I can follow what is being done, even if
exactly what is being accomplished for the caller isn't evident.
Choosing a good name for the function might to a long way towards
addressing the latter question.

Different people have different reactions to various lexical
styles, so that aspect may be somewhat off putting here. If so
then perhaps the example will spark some other ideas. My sense
for this question is that a judicious choice of where to insert
white space, both horizontal and vertical, is a key element of
making the code easier to take in and comprehend.

Re: A question about style

<refactoring-20211231001627@ram.dialup.fu-berlin.de>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19702&group=comp.lang.c#19702

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: ram...@zedat.fu-berlin.de (Stefan Ram)
Newsgroups: comp.lang.c
Subject: Re: A question about style
Date: 30 Dec 2021 23:18:55 GMT
Organization: Stefan Ram
Lines: 57
Expires: 1 Apr 2022 11:59:58 GMT
Message-ID: <refactoring-20211231001627@ram.dialup.fu-berlin.de>
References: <sqjivq$get$1@oguzismail.eternal-september.org> <style-20211230175438@ram.dialup.fu-berlin.de> <returns-20211230225942@ram.dialup.fu-berlin.de>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de Jw1RXtkuNohizZceHTsgaQL0EUPu0K+I95RO19zEInuVm+
X-Copyright: (C) Copyright 2021 Stefan Ram. All rights reserved.
Distribution through any means other than regular usenet
channels is forbidden. It is forbidden to publish this
article in the Web, to change URIs of this article into links,
and to transfer the body without this notice, but quotations
of parts in other Usenet posts are allowed.
X-No-Archive: Yes
Archive: no
X-No-Archive-Readme: "X-No-Archive" is set, because this prevents some
services to mirror the article in the web. But the article may
be kept on a Usenet archive server with only NNTP access.
X-No-Html: yes
Content-Language: en-US
Accept-Language: de-DE, en-US, it, fr-FR
 by: Stefan Ram - Thu, 30 Dec 2021 23:18 UTC

ram@zedat.fu-berlin.de (Stefan Ram) writes:
>"Split it into meaningful functions with meaningful
>names, and if that is not possible, reorganize the
>code so that it becomes possible!".

So, for example:

int f( void )
{
if( rand() < 1 )
{ if( rand() < 2 )return 0;
/* else fall through to continuation */ }
else
{ if( rand() < 3 )return 0;
/* else fall through to continuation */ }

/* continuation */
puts( "A" );
puts( "B" );
puts( "C" );
return 1; }

would become:

int f( void )
{ if( rand() < 1 )
{ if( rand() < 2 )return 0;
else
{ puts( "A" );
puts( "B" );
puts( "C" );
return 1; }}
else
{ if( rand() < 3 )return 0;
else
{ puts( "A" );
puts( "B" );
puts( "C" );
return 1; }}}

. Now, we have code duplication, but then the next step is:

inline int continuation( void )
{ puts( "A" );
puts( "B" );
puts( "C" );
return 1; }

int f( void )
{ if( rand() < 1 )
{ return rand() < 2? 0: continuation();
else
{ return rand() < 3? 0: continuation(); }}

.

Re: A question about style

<87bl0x39o2.fsf@nosuchdomain.example.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19703&group=comp.lang.c#19703

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: Keith.S....@gmail.com (Keith Thompson)
Newsgroups: comp.lang.c
Subject: Re: A question about style
Date: Thu, 30 Dec 2021 16:22:37 -0800
Organization: None to speak of
Lines: 63
Message-ID: <87bl0x39o2.fsf@nosuchdomain.example.com>
References: <sqjivq$get$1@oguzismail.eternal-september.org>
<style-20211230175438@ram.dialup.fu-berlin.de>
<returns-20211230225942@ram.dialup.fu-berlin.de>
<refactoring-20211231001627@ram.dialup.fu-berlin.de>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="535866f7e1f9aa1f9c859c38fe4fa9a9";
logging-data="9426"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX183E9Oer1BkPwDHFRM0kHtt"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:zJUYTA9sg/Pe4tEb0dDCP5Xs2oM=
sha1:NHvUizrubM1nCrASelHKdw6MenE=
 by: Keith Thompson - Fri, 31 Dec 2021 00:22 UTC

ram@zedat.fu-berlin.de (Stefan Ram) writes:
> ram@zedat.fu-berlin.de (Stefan Ram) writes:
>>"Split it into meaningful functions with meaningful
>>names, and if that is not possible, reorganize the
>>code so that it becomes possible!".
>
> So, for example:
>
> int f( void )
> {
> if( rand() < 1 )
> { if( rand() < 2 )return 0;
> /* else fall through to continuation */ }
> else
> { if( rand() < 3 )return 0;
> /* else fall through to continuation */ }
>
> /* continuation */
> puts( "A" );
> puts( "B" );
> puts( "C" );
> return 1; }
>
> would become:
>
> int f( void )
> { if( rand() < 1 )
> { if( rand() < 2 )return 0;
> else
> { puts( "A" );
> puts( "B" );
> puts( "C" );
> return 1; }}
> else
> { if( rand() < 3 )return 0;
> else
> { puts( "A" );
> puts( "B" );
> puts( "C" );
> return 1; }}}
>
> . Now, we have code duplication, but then the next step is:
>
> inline int continuation( void )
> { puts( "A" );
> puts( "B" );
> puts( "C" );
> return 1; }
>
> int f( void )
> { if( rand() < 1 )
> { return rand() < 2? 0: continuation();
> else
> { return rand() < 3? 0: continuation(); }}

You have an unmatched curly brace on that last function definition.

Your unconventional layout makes that very difficult to see.

--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for Philips
void Void(void) { Void(); } /* The recursive call of the void */

Re: A question about style

<sqm6jv$ogf$1@oguzismail.eternal-september.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19706&group=comp.lang.c#19706

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!oguzismail.eternal-september.org!.POSTED!not-for-mail
From: oguzisma...@gmail.com (Oğuz)
Newsgroups: comp.lang.c
Subject: Re: A question about style
Date: Fri, 31 Dec 2021 09:05:51 +0300
Organization: A noiseless patient Spider
Lines: 25
Message-ID: <sqm6jv$ogf$1@oguzismail.eternal-september.org>
References: <sqjivq$get$1@oguzismail.eternal-september.org>
<0269f6e4-3438-4739-b37c-483ff4c869b6n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 31 Dec 2021 06:05:52 -0000 (UTC)
Injection-Info: oguzismail.eternal-september.org; posting-host="49ae0b5e7efc4f2dfbfdd3dd01fe4ea2";
logging-data="25103"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+yl4Locd1MscQg9xiE3mNWCRe3QVzWXYE="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.14.0
Cancel-Lock: sha1:rSvGM+1DLUaaBvljBdWFC5ADYjI=
In-Reply-To: <0269f6e4-3438-4739-b37c-483ff4c869b6n@googlegroups.com>
Content-Language: en-US
 by: Oğuz - Fri, 31 Dec 2021 06:05 UTC

On 12/30/21 11:15 PM, Paul N wrote:
> How about something like the following? I imagine some of the variables are locals rather than globals so would need to be passed as arguments but this is a rough idea.
>
> int skip(int type, int val, int op) {
> switch(type) {
> case 1: return skip_adj[val][op];
> case 2: return skip_alt[val][op];
> default: return skip_alt_asc[val][op]; }
>
> int is_number(int len, int pos) {
> return len > pos && !expr[len - pos].is_number; }
>
> ...
> if (is_number(expr_length, 1)) { // this will do a check on length that the original didn't
> if (skip(1, expr[expr_length - 1].value, op)) return false; }
> else if (is_number(expr_length, 2) {
> if (skip(2, expr[expr_length - 2].value, op)) return false;
> else if (expr[expr_length - 3].is_number
> && expr[expr_length - 3].value < expr[expr_length - 1].value
> && skip(3, expr[expr_length - 2].value, op) return false;
> }
>
>

Yea, I think I'll do it this way. Thank you

Re: A question about style

<sqm6uk$ugv$1@oguzismail.eternal-september.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19707&group=comp.lang.c#19707

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!oguzismail.eternal-september.org!.POSTED!not-for-mail
From: oguzisma...@gmail.com (Oğuz)
Newsgroups: comp.lang.c
Subject: Re: A question about style
Date: Fri, 31 Dec 2021 09:11:31 +0300
Organization: A noiseless patient Spider
Lines: 10
Message-ID: <sqm6uk$ugv$1@oguzismail.eternal-september.org>
References: <sqjivq$get$1@oguzismail.eternal-september.org>
<86ee5tzra5.fsf@linuxsc.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 31 Dec 2021 06:11:32 -0000 (UTC)
Injection-Info: oguzismail.eternal-september.org; posting-host="49ae0b5e7efc4f2dfbfdd3dd01fe4ea2";
logging-data="31263"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+2SjbieW/mrs4FlNI/UCKcWuTGTRr1PnU="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.14.0
Cancel-Lock: sha1:dstMLVx7HVPPkiaBR5aC/yPbtoI=
In-Reply-To: <86ee5tzra5.fsf@linuxsc.com>
Content-Language: en-US
 by: Oğuz - Fri, 31 Dec 2021 06:11 UTC

On 12/31/21 1:01 AM, Tim Rentsch wrote:
> [...] My sense
> for this question is that a judicious choice of where to insert
> white space, both horizontal and vertical, is a key element of
> making the code easier to take in and comprehend.
>

I'm not a fan of horizontal spaces (as in `if( cond )' etc.), but
yeah, I have to admit that your example looks better. Thanks

Re: A question about style

<j3dnj4Fpc6eU1@mid.individual.net>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19787&group=comp.lang.c#19787

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: use...@schweikhardt.net (Jens Schweikhardt)
Newsgroups: comp.lang.c
Subject: Re: A question about style
Date: 2 Jan 2022 13:28:04 GMT
Lines: 21
Sender: Jens Schweikhardt <schweikh@hal9k.schweikhardt.net>
Message-ID: <j3dnj4Fpc6eU1@mid.individual.net>
References: <sqjivq$get$1@oguzismail.eternal-september.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: individual.net OYLkI/Ju14CmPQok0ppzMARq7QrxQWXn+Ebf48NetntwBSNE5w
X-Orig-Path: not-for-mail
Cancel-Lock: sha1:mkQoJXYlTeTATi0Bd8pBEjUEUa4=
User-Agent: tin/2.4.5-20201224 ("Glen Albyn") (FreeBSD/14.0-CURRENT (amd64))
 by: Jens Schweikhardt - Sun, 2 Jan 2022 13:28 UTC

Oğuz <oguzismailuysal@gmail.com> wrote
in <sqjivq$get$1@oguzismail.eternal-september.org>:
....
# 1. Define macros for `expr[expr_length - 1]', `expr[expr_length - 2]',
# etc. and use them instead. But, what am I gonna name them?

You are trying to solve one of the two unsolved problems in computer science.
1. Cache coherency
2. Naming identifiers
3. Off-by-one errors

:-)

expr_last and expr_almost_last?

Regards,

Jens
--
Jens Schweikhardt http://www.schweikhardt.net/
SIGSIG -- signature too long (core dumped)

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor