Re: So You Think You Can Const?

Liste des GroupesRevenir à cl c 
Sujet : Re: So You Think You Can Const?
De : julio (at) *nospam* diegidio.name (Julio Di Egidio)
Groupes : comp.lang.c
Date : 10. Jan 2025, 04:05:05
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vlq2p2$2dkpd$19@dont-email.me>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14
User-Agent : Mozilla Thunderbird
On 10/01/2025 03:51, Julio Di Egidio wrote:
On 10/01/2025 03:14, Julio Di Egidio wrote:
On 10/01/2025 02:43, Tim Rentsch wrote:
Julio Di Egidio <julio@diegidio.name> writes:
On 10/01/2025 00:37, Julio Di Egidio wrote:
On 10/01/2025 00:23, Ben Bacarisse wrote:
Julio Di Egidio <julio@diegidio.name> writes:
On 09/01/2025 02:09, Ben Bacarisse wrote:
Julio Di Egidio <julio@diegidio.name> writes:
>
static AvlTree_t const *AvlTree_node(
  void const *pk, AvlTree_t const *pL, AvlTree_t const *pR
) {
  AvlTree_t *pT;
>
  pT = malloc(sizeof(AvlTree_t));
>
  if (!pT) {
  return NULL;
  }
>
  pT->pk = pk;
  pT->pL = pL;
  pT->pR = pR;
>
  return pT;
}
>
Just on a side issue, I prefer to make tests like this positive
so I'd write:
  static AvlTree_t const *AvlTree_node(
  void const *pk, AvlTree_t const *pL, AvlTree_t const *pR
  ) {
  AvlTree_t *pT = malloc(*pT);
  if (pT) {
  pT->pk = pk;
  pT->pL = pL;
  pT->pR = pR;
  }
  return pT;
  }
I'm not going to "make a case" for this (though I will if you
want!) -- I just think it helps to see lots of different styles.
>
That is *more* error prone,
>
I would be happy for you to expand on why you say that.
>
all the more so if it's not a 5 liner...
>
There is no such thing as expanding 40 years of professional
experience in software engineering and programming and doing it
properly since day one:  just think about that code and what I said
for what it's worth, in particular I haven't mentioned 5 liners by
chance, things are quite more complicated not in vitro.
>
And please do not hold a grudge about that:  it's not me who was
trying to say how to write code... ;)
>
BTW, I hadn't mention it, but have you noticed the second one is
misindented?  Between me and you, I can tell how long a piece of
code will take to break when in production by just looking at
it...  A lot of fun.  :)
>
The indentation was correct in Ben's original posting.
>
The misindentation first appeared in your followup to that
posting, where the quoted portion had been changed to remove a
blank line and over-indent the if().
>
But indeed the point is what happens in the long run: if you look above mine is still better indented... :)  But of course it is not indentation per se the problem: for example check the return value as soon as the function returns a possibly null pointer or an error value is certainly more widely applicable, and quite less error prone, especially if it's
 I meant: immediately check the return value and bail out if needed.  The other approach does not even simplify on the clean-up, by the way...
 
not a 5 liner...  Anyway, I also truly believe there is no point in belabouring the point: it's the overall picture that one must get to see.
A last one for the more theoretically inclined: every "if" is a code path, but not all code paths are "if"s...
Cheers,
-Julio

Date Sujet#  Auteur
7 Jan 25 * So You Think You Can Const?174Julio Di Egidio
7 Jan 25 +* Re: So You Think You Can Const?80Kaz Kylheku
8 Jan 25 i`* Re: So You Think You Can Const?79Julio Di Egidio
8 Jan 25 i +- Re: So You Think You Can Const?1Julio Di Egidio
8 Jan 25 i `* Re: So You Think You Can Const?77Ben Bacarisse
8 Jan 25 i  +- Re: So You Think You Can Const?1David Brown
8 Jan 25 i  +* Re: So You Think You Can Const?72Julio Di Egidio
8 Jan 25 i  i+* Re: So You Think You Can Const?64Julio Di Egidio
8 Jan 25 i  ii+- Re: So You Think You Can Const?1Chris M. Thomasson
9 Jan 25 i  ii`* Re: So You Think You Can Const?62Ben Bacarisse
9 Jan 25 i  ii +* Re: So You Think You Can Const?4Kaz Kylheku
9 Jan 25 i  ii i`* Re: So You Think You Can Const?3David Brown
9 Jan 25 i  ii i +- Re: So You Think You Can Const?1Chris M. Thomasson
15 Jan 25 i  ii i `- Re: So You Think You Can Const?1Julio Di Egidio
9 Jan 25 i  ii +* Re: So You Think You Can Const?54Julio Di Egidio
10 Jan 25 i  ii i`* Re: So You Think You Can Const?53Ben Bacarisse
10 Jan 25 i  ii i +* Re: So You Think You Can Const?46Julio Di Egidio
10 Jan 25 i  ii i i+* Re: So You Think You Can Const?44Julio Di Egidio
10 Jan 25 i  ii i ii`* Re: So You Think You Can Const?43Tim Rentsch
10 Jan 25 i  ii i ii +* Re: So You Think You Can Const?38Julio Di Egidio
10 Jan 25 i  ii i ii i+* Re: So You Think You Can Const?36Julio Di Egidio
10 Jan 25 i  ii i ii ii+- Re: So You Think You Can Const?1Julio Di Egidio
13 Jan 25 i  ii i ii ii`* Re: So You Think You Can Const?34James Kuyper
13 Jan 25 i  ii i ii ii +* Re: So You Think You Can Const?32David Brown
13 Jan 25 i  ii i ii ii i+* Re: So You Think You Can Const?29Julio Di Egidio
13 Jan 25 i  ii i ii ii ii`* Re: So You Think You Can Const?28David Brown
13 Jan 25 i  ii i ii ii ii +* Re: So You Think You Can Const?26Julio Di Egidio
13 Jan 25 i  ii i ii ii ii i`* Re: So You Think You Can Const?25David Brown
14 Jan 25 i  ii i ii ii ii i +* Re: So You Think You Can Const?22Julio Di Egidio
14 Jan 25 i  ii i ii ii ii i i+* Re: So You Think You Can Const?16bart
14 Jan 25 i  ii i ii ii ii i ii`* Re: So You Think You Can Const?15David Brown
14 Jan 25 i  ii i ii ii ii i ii +* Re: So You Think You Can Const?7James Kuyper
14 Jan 25 i  ii i ii ii ii i ii i+- Re: So You Think You Can Const?1Dan Cross
14 Jan 25 i  ii i ii ii ii i ii i`* Re: So You Think You Can Const?5David Brown
14 Jan 25 i  ii i ii ii ii i ii i `* Re: So You Think You Can Const?4James Kuyper
15 Jan 25 i  ii i ii ii ii i ii i  `* Re: So You Think You Can Const?3James Kuyper
15 Jan 25 i  ii i ii ii ii i ii i   `* Re: So You Think You Can Const?2David Brown
15 Jan 25 i  ii i ii ii ii i ii i    `- Re: So You Think You Can Const?1Julio Di Egidio
14 Jan 25 i  ii i ii ii ii i ii +* Re: So You Think You Can Const?2Chris M. Thomasson
14 Jan 25 i  ii i ii ii ii i ii i`- Re: So You Think You Can Const?1Chris M. Thomasson
15 Jan 25 i  ii i ii ii ii i ii `* Re: So You Think You Can Const?5Julio Di Egidio
15 Jan 25 i  ii i ii ii ii i ii  +- Re: So You Think You Can Const?1Julio Di Egidio
15 Jan 25 i  ii i ii ii ii i ii  `* Re: So You Think You Can Const?3Kaz Kylheku
15 Jan 25 i  ii i ii ii ii i ii   `* Re: So You Think You Can Const?2Julio Di Egidio
15 Jan 25 i  ii i ii ii ii i ii    `- Re: So You Think You Can Const?1Julio Di Egidio
14 Jan 25 i  ii i ii ii ii i i+- Re: So You Think You Can Const?1James Kuyper
14 Jan 25 i  ii i ii ii ii i i`* Re: So You Think You Can Const?4Keith Thompson
15 Jan 25 i  ii i ii ii ii i i `* Re: So You Think You Can Const?3Kenny McCormack
15 Jan 25 i  ii i ii ii ii i i  `* Re: So You Think You Can Const?2Julio Di Egidio
15 Jan 25 i  ii i ii ii ii i i   `- Re: So You Think You Can Const?1Kaz Kylheku
15 Jan 25 i  ii i ii ii ii i `* Re: So You Think You Can Const?2Julio Di Egidio
15 Jan 25 i  ii i ii ii ii i  `- Re: So You Think You Can Const?1Kaz Kylheku
15 Jan 25 i  ii i ii ii ii `- Re: So You Think You Can Const?1Julio Di Egidio
15 Jan 25 i  ii i ii ii i`* Re: So You Think You Can Const?2Julio Di Egidio
15 Jan 25 i  ii i ii ii i `- Re: So You Think You Can Const?1Julio Di Egidio
15 Jan 25 i  ii i ii ii `- Re: So You Think You Can Const?1Julio Di Egidio
13 Jan 25 i  ii i ii i`- Re: So You Think You Can Const?1Tim Rentsch
15 Jan 25 i  ii i ii `* Re: So You Think You Can Const?4Julio Di Egidio
18 Jan 25 i  ii i ii  `* Re: So You Think You Can Const?3Tim Rentsch
19 Jan 25 i  ii i ii   `* Re: So You Think You Can Const?2Julio Di Egidio
20 Jan 25 i  ii i ii    `- Re: So You Think You Can Const?1Chris M. Thomasson
10 Jan 25 i  ii i i`- Re: So You Think You Can Const?1Ben Bacarisse
12 Jan 25 i  ii i +* Re: So You Think You Can Const?5Waldek Hebisch
12 Jan 25 i  ii i i+* Re: So You Think You Can Const?3Julio Di Egidio
13 Jan 25 i  ii i ii`* Re: So You Think You Can Const?2David Brown
13 Jan 25 i  ii i ii `- Re: So You Think You Can Const?1James Kuyper
13 Jan 25 i  ii i i`- Re: So You Think You Can Const?1David Brown
15 Jan 25 i  ii i `- Re: So You Think You Can Const?1Julio Di Egidio
15 Jan 25 i  ii +- Re: So You Think You Can Const?1Julio Di Egidio
15 Jan 25 i  ii `* Re: So You Think You Can Const?2Julio Di Egidio
15 Jan 25 i  ii  `- Re: So You Think You Can Const?1Chris M. Thomasson
8 Jan 25 i  i+* Re: So You Think You Can Const?2James Kuyper
8 Jan 25 i  ii`- Re: So You Think You Can Const?1James Kuyper
8 Jan 25 i  i+* Re: So You Think You Can Const?2Tim Rentsch
9 Jan 25 i  ii`- Re: So You Think You Can Const?1Julio Di Egidio
8 Jan 25 i  i+- Re: So You Think You Can Const?1Chris M. Thomasson
9 Jan 25 i  i`* Re: So You Think You Can Const?2Ben Bacarisse
9 Jan 25 i  i `- Re: So You Think You Can Const?1Julio Di Egidio
8 Jan 25 i  +* Re: So You Think You Can Const?2Tim Rentsch
9 Jan 25 i  i`- Re: So You Think You Can Const?1Ben Bacarisse
15 Jan 25 i  `- Re: So You Think You Can Const?1Julio Di Egidio
8 Jan 25 +* Re: So You Think You Can Const?35David Brown
8 Jan 25 i+* Re: So You Think You Can Const?4Ben Bacarisse
8 Jan 25 ii`* Re: So You Think You Can Const?3David Brown
15 Jan 25 ii `* Re: So You Think You Can Const?2Julio Di Egidio
15 Jan 25 ii  `- Re: So You Think You Can Const?1Julio Di Egidio
8 Jan 25 i+* What is wrong with malloc? (Was: So You Think You Can Const?)28Julio Di Egidio
8 Jan 25 ii+* Re: What is wrong with malloc? (Was: So You Think You Can Const?)25David Brown
8 Jan 25 iii+* Re: What is wrong with malloc? (Was: So You Think You Can Const?)2Julio Di Egidio
8 Jan 25 iiii`- Re: What is wrong with malloc? (Was: So You Think You Can Const?)1David Brown
8 Jan 25 iii+* Re: What is wrong with malloc? (Was: So You Think You Can Const?)13Phillip
8 Jan 25 iiii+- Re: What is wrong with malloc? (Was: So You Think You Can Const?)1Tim Rentsch
8 Jan 25 iiii+* Re: What is wrong with malloc?10Keith Thompson
8 Jan 25 iiiii`* Re: What is wrong with malloc?9Phillip
8 Jan 25 iiiii `* Re: What is wrong with malloc?8Keith Thompson
9 Jan 25 iiiii  `* Re: What is wrong with malloc?7Phillip
9 Jan 25 iiiii   +* Re: What is wrong with malloc?4Keith Thompson
9 Jan 25 iiiii   i+- Re: What is wrong with malloc?1Phillip
9 Jan 25 iiiii   i`* Re: What is wrong with malloc?2Michael S
9 Jan 25 iiiii   i `- Re: What is wrong with malloc?1Phillip
9 Jan 25 iiiii   `* Re: What is wrong with malloc?2David Brown
9 Jan 25 iiii`- Re: What is wrong with malloc? (Was: So You Think You Can Const?)1David Brown
8 Jan 25 iii+* Re: What is wrong with malloc?3Keith Thompson
9 Jan 25 iii`* Re: What is wrong with malloc? (Was: So You Think You Can Const?)6Julio Di Egidio
8 Jan 25 ii`* Re: What is wrong with malloc? (Was: So You Think You Can Const?)2James Kuyper
8 Jan 25 i+- Re: So You Think You Can Const?1Kaz Kylheku
8 Jan 25 i`- Re: So You Think You Can Const?1Keith Thompson
8 Jan 25 +* Re: So You Think You Can Const?51Andrey Tarasevich
8 Jan 25 +- Re: So You Think You Can Const?1Tim Rentsch
13 Jan 25 +- Re: So You Think You Can Const?1Chris M. Thomasson
15 Jan 25 +* Re: So You Think You Can Const?4Lawrence D'Oliveiro
26 Jan 25 `- Re: So You Think You Can Const?1Lawrence D'Oliveiro

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal