Re: "A diagram of C23 basic types"

Liste des GroupesRevenir à cl c  
Sujet : Re: "A diagram of C23 basic types"
De : david.brown (at) *nospam* hesbynett.no (David Brown)
Groupes : comp.lang.c
Date : 04. Apr 2025, 16:12:42
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vsostb$3nn12$1@dont-email.me>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
User-Agent : Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.11.0
On 04/04/2025 16:10, Muttley@DastardlyHQ.org wrote:
On Fri, 4 Apr 2025 13:39:06 +0200
David Brown <david.brown@hesbynett.no> wibbled:
On 04/04/2025 11:40, Muttley@DastardlyHQ.org wrote:
On Thu, 3 Apr 2025 15:58:05 +0200
David Brown <david.brown@hesbynett.no> wibbled:
Human readers prefer clear code to comments.  Comments get out of sync -
code does not.
>
Thats not a reason for not using comments.
>
It is a reason for never using a comment when you can express the same
thing in code.
>
If that's your problem, write better code - not more comments.
 Ah, the typical arrogant programmer who thinks their code is so well written
that anyone can understand it and comments arn't required. Glad I don't have
to work on anything you've written.
Arrogance would be judging my code without having seen it.  Writing code that is clear and does not require comments to say what it does is not arrogance - it is good coding.

 
>
Comments should say /why/ you are doing something, not /what/ you are doing.
 Rubbish. A lot of the time what is being done is just as obtuse as why.
That can /occasionally/ be the case.  But if it happens a lot of the time, you are writing poor code.  It's time to refactor or rename.

 
Except its not unreachable is it?
>
It /is/ unreachable.  That's why I wrote it.
 Really?
 int main()
{
colour_to_hex(10);
return 0;
}
UB.  It's /your/ fault.
Most of my code is written on the assumption that the people using it are not incompetent morons.  They may make mistakes in their coding, but not like that.  The code in question is unreachable because the kind of person who could write a call like that would not be working with my code.
There are situations where you want to make your code handle as wide a range of inputs as possible, and provide error returns to help catch mistakes.  Typically that is for boundary or interface code - such as libraries written for other people to use.
For internal code within TU's or parts of a project, such things are just a waste of effort.  They can make it significantly harder to design the code, since you have to figure out what behaviour is appropriate for invalid input - what should a function called "colour_to_hex" do when presented with an input that is not a colour?  Sometimes they are impossible to implement - how do you check the precondition "this is a valid pointer" ?  They limit your functionality and future expansion - if I have specified that inputs other than "red", "green" or "blue" give the result 0x00'00'00, then I can't add "purple" to the list of colours.
There are all sorts of reasons why it is a good idea for functions to have pre-conditions, and for letting calls to the function without satisfying those pre-conditions be undefined behaviour.

 You have no idea how someone might try and use that function in the future.
Yes, I do.

Just assuming they'll always pass parameters within limits is not just
cretinous, its dangerous.
Nope.  It is how software development works.  If you don't understand about function specifications, you might want to read up on some basic computer science.

 
  There's nothing in C to prevent you
calling that function with a value other than defined in the enum so what
happens if there's a bug and it hits unreachable?
>
There's nothing in the English language preventing me from calling you a
"very stable genius" - but I can assure you that it is not going to happen.
 Poor analogy.
 
Oh thats right , its
"undefined" ie , a crash or hidden bug with bugger all info.
>
Welcome to the world of software development.  If I specify a function
as working for input values "red", "green", and "blue", and you choose
to misuse it, that is /your/ fault, not mine.  I write the code to work
with valid inputs and give no promises about what will happen with any
other input.
 Its your fault if it dies in a heap with no info or worse returns but does
some random shit.
If the caller fails to satisfy the pre-conditions of the function, that's the caller's fault.  If the function fails to satisfy the post-conditions when called with correct pre-conditions, that's the function's fault.  That's the contract, and that's the basis of all programming.

Any well written API function should do at least basic
sanity checking on its inputs and return a fail or assert unless its very low
level and speed is the priority eg strlen().
 
At clear boundaries of development responsibility - such as the public functions of a library - then it is often nice to add some extra checking and error feedback to help users of the library find their bugs.

But then you're arrogant, so no surprise really.
 
Also FWIW, putting seperators in the hex values makes it less readable to me
not more.
>
>
Again, that's /your/ problem.
 See above.
 

Date Sujet#  Auteur
2 Apr 25 * "A diagram of C23 basic types"296Alexis
2 Apr 25 +* Re: "A diagram of C23 basic types"4Lawrence D'Oliveiro
3 Apr 25 i`* Re: "A diagram of C23 basic types"3BGB
3 Apr 25 i `* Re: "A diagram of C23 basic types"2Lawrence D'Oliveiro
4 Apr 25 i  `- Re: "A diagram of C23 basic types"1BGB
2 Apr 25 +* Re: "A diagram of C23 basic types"9Janis Papanagnou
2 Apr 25 i+* Re: "A diagram of C23 basic types"6Kaz Kylheku
3 Apr 25 ii`* Re: "A diagram of C23 basic types"5Janis Papanagnou
3 Apr 25 ii +* Re: "A diagram of C23 basic types"3David Brown
3 Apr 25 ii i`* Re: "A diagram of C23 basic types"2Janis Papanagnou
3 Apr 25 ii i `- Re: "A diagram of C23 basic types"1BGB
3 Apr 25 ii `- Re: "A diagram of C23 basic types"1BGB
2 Apr 25 i+- Re: "A diagram of C23 basic types"1David Brown
3 Apr 25 i`- Re: "A diagram of C23 basic types"1Tim Rentsch
2 Apr 25 +* Re: "A diagram of C23 basic types"276bart
2 Apr 25 i+* Re: "A diagram of C23 basic types"250Muttley
2 Apr 25 ii+* Re: "A diagram of C23 basic types"220David Brown
2 Apr 25 iii+* Re: "A diagram of C23 basic types"216Muttley
2 Apr 25 iiii+* Re: "A diagram of C23 basic types"142Thiago Adams
2 Apr 25 iiiii`* Re: "A diagram of C23 basic types"141Muttley
2 Apr 25 iiiii +* Re: "A diagram of C23 basic types"139bart
2 Apr 25 iiiii i+* Re: "A diagram of C23 basic types"58Muttley
2 Apr 25 iiiii ii+* Re: "A diagram of C23 basic types"5Janis Papanagnou
3 Apr 25 iiiii iii+* Re: "A diagram of C23 basic types"2Janis Papanagnou
3 Apr 25 iiiii iiii`- Re: "A diagram of C23 basic types"1Janis Papanagnou
3 Apr 25 iiiii iii`* Re: "A diagram of C23 basic types"2David Brown
3 Apr 25 iiiii iii `- Re: "A diagram of C23 basic types"1BGB
3 Apr 25 iiiii ii+* Re: "A diagram of C23 basic types"49bart
3 Apr 25 iiiii iii+* Re: "A diagram of C23 basic types"46Kaz Kylheku
3 Apr 25 iiiii iiii+* Re: "A diagram of C23 basic types"43Keith Thompson
3 Apr 25 iiiii iiiii+* Re: "A diagram of C23 basic types"41BGB
3 Apr 25 iiiii iiiiii`* Re: "A diagram of C23 basic types"40Kaz Kylheku
3 Apr 25 iiiii iiiiii +* Re: "A diagram of C23 basic types"36bart
4 Apr 25 iiiii iiiiii i+* Re: "A diagram of C23 basic types"31Lawrence D'Oliveiro
9 Apr 25 iiiii iiiiii ii`* Re: "A diagram of C23 basic types"30Michael S
9 Apr 25 iiiii iiiiii ii +* Re: "A diagram of C23 basic types"21David Brown
9 Apr 25 iiiii iiiiii ii i+* Re: "A diagram of C23 basic types"17BGB
9 Apr 25 iiiii iiiiii ii ii`* Re: "A diagram of C23 basic types"16bart
10 Apr 25 iiiii iiiiii ii ii `* Re: "A diagram of C23 basic types"15David Brown
10 Apr 25 iiiii iiiiii ii ii  +* Re: "A diagram of C23 basic types"5Michael S
12 Apr06:43 iiiii iiiiii ii ii  i`* Re: "A diagram of C23 basic types"4Lawrence D'Oliveiro
12 Apr15:10 iiiii iiiiii ii ii  i +- Re: "A diagram of C23 basic types"1James Kuyper
12 Apr16:21 iiiii iiiiii ii ii  i `* Re: "A diagram of C23 basic types"2David Brown
12 Apr20:27 iiiii iiiiii ii ii  i  `- Re: "A diagram of C23 basic types"1BGB
10 Apr 25 iiiii iiiiii ii ii  +* Re: "A diagram of C23 basic types"4Muttley
10 Apr 25 iiiii iiiiii ii ii  i`* Re: "A diagram of C23 basic types"3bart
10 Apr 25 iiiii iiiiii ii ii  i +- Re: "A diagram of C23 basic types"1Muttley
12 Apr06:44 iiiii iiiiii ii ii  i `- Re: "A diagram of C23 basic types"1Lawrence D'Oliveiro
10 Apr 25 iiiii iiiiii ii ii  +* Re: "A diagram of C23 basic types"4bart
10 Apr 25 iiiii iiiiii ii ii  i`* Re: "A diagram of C23 basic types"3David Brown
10 Apr 25 iiiii iiiiii ii ii  i `* Re: "A diagram of C23 basic types"2bart
10 Apr 25 iiiii iiiiii ii ii  i  `- Re: "A diagram of C23 basic types"1David Brown
10 Apr 25 iiiii iiiiii ii ii  `- Re: "A diagram of C23 basic types"1BGB
9 Apr 25 iiiii iiiiii ii i`* Re: "A diagram of C23 basic types"3Keith Thompson
12 Apr06:42 iiiii iiiiii ii i `* Re: "A diagram of C23 basic types"2Lawrence D'Oliveiro
12 Apr21:46 iiiii iiiiii ii i  `- Re: "A diagram of C23 basic types"1Keith Thompson
9 Apr 25 iiiii iiiiii ii +* Re: "A diagram of C23 basic types"7Tim Rentsch
9 Apr 25 iiiii iiiiii ii i+* Re: "A diagram of C23 basic types"3Keith Thompson
14 Apr10:10 iiiii iiiiii ii ii`* Re: "A diagram of C23 basic types"2Tim Rentsch
14 Apr12:08 iiiii iiiiii ii ii `- Re: "A diagram of C23 basic types"1Keith Thompson
10 Apr 25 iiiii iiiiii ii i`* Re: "A diagram of C23 basic types"3Michael S
14 Apr09:59 iiiii iiiiii ii i `* Re: "A diagram of C23 basic types"2Tim Rentsch
14 Apr10:44 iiiii iiiiii ii i  `- Re: "A diagram of C23 basic types"1Michael S
9 Apr 25 iiiii iiiiii ii `- Re: "A diagram of C23 basic types"1Kaz Kylheku
4 Apr 25 iiiii iiiiii i`* Re: "A diagram of C23 basic types"4Waldek Hebisch
4 Apr 25 iiiii iiiiii i +* Re: "A diagram of C23 basic types"2Keith Thompson
4 Apr 25 iiiii iiiiii i i`- Re: "A diagram of C23 basic types"1Waldek Hebisch
8 Apr 25 iiiii iiiiii i `- Re: "A diagram of C23 basic types"1Lawrence D'Oliveiro
3 Apr 25 iiiii iiiiii +* Re: "A diagram of C23 basic types"2Keith Thompson
4 Apr 25 iiiii iiiiii i`- Re: "A diagram of C23 basic types"1Kaz Kylheku
4 Apr 25 iiiii iiiiii `- Re: "A diagram of C23 basic types"1Michael S
4 Apr 25 iiiii iiiii`- Re: "A diagram of C23 basic types"1Lawrence D'Oliveiro
3 Apr 25 iiiii iiii+- Re: "A diagram of C23 basic types"1Muttley
3 Apr 25 iiiii iiii`- Re: "A diagram of C23 basic types"1Keith Thompson
3 Apr 25 iiiii iii+- Re: "A diagram of C23 basic types"1David Brown
4 Apr 25 iiiii iii`- Re: "A diagram of C23 basic types"1Lawrence D'Oliveiro
3 Apr 25 iiiii ii`* Re: "A diagram of C23 basic types"3Muttley
4 Apr 25 iiiii ii `* Re: "A diagram of C23 basic types"2Muttley
4 Apr 25 iiiii ii  `- Re: "A diagram of C23 basic types"1Muttley
4 Apr 25 iiiii i`* Re: "A diagram of C23 basic types"80Lawrence D'Oliveiro
4 Apr 25 iiiii i +- Re: "A diagram of C23 basic types"1Keith Thompson
7 Apr 25 iiiii i +* Re: "A diagram of C23 basic types"29candycanearter07
7 Apr 25 iiiii i i+* Re: "A diagram of C23 basic types"27Janis Papanagnou
8 Apr 25 iiiii i ii+- Re: "A diagram of C23 basic types"1candycanearter07
14 Apr05:33 iiiii i ii`* Re: "A diagram of C23 basic types"25Lawrence D'Oliveiro
14 Apr18:40 iiiii i ii `* Re: "A diagram of C23 basic types"24candycanearter07
14 Apr18:46 iiiii i ii  +* Re: "A diagram of C23 basic types"2Kaz Kylheku
15 Apr08:41 iiiii i ii  i`- Re: "A diagram of C23 basic types"1Janis Papanagnou
14 Apr19:36 iiiii i ii  `* Re: "A diagram of C23 basic types"21BGB
14 Apr23:15 iiiii i ii   +- Re: "A diagram of C23 basic types"1Keith Thompson
14 Apr23:33 iiiii i ii   `* Re: "A diagram of C23 basic types"19Lawrence D'Oliveiro
14 Apr23:56 iiiii i ii    +* Re: "A diagram of C23 basic types"12Keith Thompson
15 Apr00:41 iiiii i ii    i+* Re: "A diagram of C23 basic types"7Lawrence D'Oliveiro
15 Apr01:57 iiiii i ii    ii+- Re: "A diagram of C23 basic types"1Keith Thompson
15 Apr04:25 iiiii i ii    ii`* Re: "A diagram of C23 basic types"5James Kuyper
15 Apr05:11 iiiii i ii    ii +* Re: "A diagram of C23 basic types"2Lawrence D'Oliveiro
15 Apr15:06 iiiii i ii    ii i`- Re: "A diagram of C23 basic types"1James Kuyper
15 Apr06:00 iiiii i ii    ii `* Re: "A diagram of C23 basic types"2BGB
15 Apr18:29 iiiii i ii    ii  `- Re: "A diagram of C23 basic types"1BGB
15 Apr02:46 iiiii i ii    i`* Re: "A diagram of C23 basic types"4Chris M. Thomasson
15 Apr05:14 iiiii i ii    i +- Re: "A diagram of C23 basic types"1Lawrence D'Oliveiro
15 Apr15:19 iiiii i ii    i `* Re: "A diagram of C23 basic types"2James Kuyper
15 Apr01:43 iiiii i ii    `* Re: "A diagram of C23 basic types"6BGB
8 Apr 25 iiiii i i`- Re: "A diagram of C23 basic types"1Lawrence D'Oliveiro
7 Apr 25 iiiii i `* Re: "A diagram of C23 basic types"49bart
4 Apr 25 iiiii `- Re: "A diagram of C23 basic types"1Lawrence D'Oliveiro
2 Apr 25 iiii+* Re: "A diagram of C23 basic types"2Michael S
2 Apr 25 iiii`* Re: "A diagram of C23 basic types"71David Brown
2 Apr 25 iii`* Re: "A diagram of C23 basic types"3Kaz Kylheku
2 Apr 25 ii`* Re: "A diagram of C23 basic types"29Waldek Hebisch
5 Apr 25 i`* Re: "A diagram of C23 basic types"25Philipp Klaus Krause
3 Apr 25 +* Re: "A diagram of C23 basic types"2Michael S
11 Apr17:34 +* Re: "A diagram of C23 basic types"2Tim Rentsch
11 Apr17:48 `* Re: "A diagram of C23 basic types"2Tim Rentsch

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal