LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 08-08-2019, 12:03 PM   #136
GazL
LQ Veteran
 
Registered: May 2008
Posts: 5,794

Rep: Reputation: 3707Reputation: 3707Reputation: 3707Reputation: 3707Reputation: 3707Reputation: 3707Reputation: 3707Reputation: 3707Reputation: 3707Reputation: 3707Reputation: 3707

Quote:
Originally Posted by z80 View Post
Yes, there are reasons to use these statements ...
But you sure don't want to run software using these when that code was written by developers known to ignore bugs.

initctl.c: 407 lines, 3 breaks, 1 continue, 8 gotos and 26 returns
OMG I just looked at it. The switch statement at 132 has a return statement at the end of every single case in it instead of a break, and then at the end of the function where one should return, it's left implicit. I'd be embarrassed to have written that.

There's probably worse in there, I was too traumatised to look any further.
 
2 members found this post helpful.
Old 08-08-2019, 03:52 PM   #137
chrisVV
Member
 
Registered: Aug 2010
Posts: 469

Rep: Reputation: 268Reputation: 268Reputation: 268
Quote:
Originally Posted by GazL View Post
OMG I just looked at it. The switch statement at 132 has a return statement at the end of every single case in it instead of a break, and then at the end of the function where one should return, it's left implicit. I'd be embarrassed to have written that.

There's probably worse in there, I was too traumatised to look any further.
Rubbish. There is nothing wrong a return statement in place of break in a case clause (if the code is indeed returning), and it would be ridiculous to have a trailing return at the end because it would be unreachable.

You have entirely missed the real issue in the code in question: the case clause fall-throughs. The linux kernel is now fall-through clean. It is likely I would be traumatised by looking at your code (if you actually write any) if that is the standard you go by.

Edit On looking at if further the fall-throughs are OK as they have no code of their own, so I will let you off that one (but not the first point).

Last edited by chrisVV; 08-08-2019 at 03:56 PM.
 
3 members found this post helpful.
Old 08-08-2019, 03:54 PM   #138
bifferos
Member
 
Registered: Jul 2009
Posts: 389

Rep: Reputation: 148Reputation: 148
Quote:
Originally Posted by GazL View Post
OMG I just looked at it. The switch statement at 132 has a return statement at the end of every single case in it instead of a break, and then at the end of the function where one should return, it's left implicit. I'd be embarrassed to have written that.
There's nothing wrong with that. Why bother breaking if you can just return immediately? Some code analysis tools would complain about unreachable code if you had a return at the end of the function. IMHO it's only a problem if it's disjointed, i.e. if you had one case returning and one with a break.

But the biggest problem I see with that file is that it's C and not C++, so instead of RAII you get that 'goto fail' nonsense that belongs in the 90s.

EDIT: Sorry Chris, posted that before I saw your post.

Last edited by bifferos; 08-08-2019 at 03:57 PM.
 
1 members found this post helpful.
Old 08-08-2019, 03:56 PM   #139
ttk
Member
 
Registered: May 2012
Location: Sebastopol, CA
Distribution: Slackware64
Posts: 965
Blog Entries: 27

Rep: Reputation: 1354Reputation: 1354Reputation: 1354Reputation: 1354Reputation: 1354Reputation: 1354Reputation: 1354Reputation: 1354Reputation: 1354Reputation: 1354
Yes, what chrisVV said. Splitting code into separate functions and returning early is the clean, well-behaved, recommended alternative to goto.
 
Old 08-08-2019, 04:17 PM   #140
GazL
LQ Veteran
 
Registered: May 2008
Posts: 5,794

Rep: Reputation: 3707Reputation: 3707Reputation: 3707Reputation: 3707Reputation: 3707Reputation: 3707Reputation: 3707Reputation: 3707Reputation: 3707Reputation: 3707Reputation: 3707
Quote:
Originally Posted by chrisVV View Post
Rubbish. There is nothing wrong a return statement in place of break in a case clause (if the code is indeed returning), and it would be ridiculous to have a trailing return at the end because it would be unreachable.

You have entirely missed the real issue in the code in question: the case clause fall-throughs. The linux kernel is now fall-through clean. It is likely I would be traumatised by looking at your code (if you actually write any) if that is the standard you go by.
There may be nothing wrong with it technically, but it's not good practice. What if one changed the return type of that function? One would have to go through dozens of return statements changing them all. Let it break out of the case and then use a single return at the end of the function and you have just one return to modify. Now, as I said, I'm not a devout follower of the one in, one out, structured programming paradigm and I certainly don't mind using an extra return or so in a guard clause or two when it simplifies the code, but that code is IMO taking it a little too far. If you disagree, then that is your right. No need to get nasty about it.

As for your last sentence, think what you will, I'm not going to rise to that bait.
 
1 members found this post helpful.
Old 08-08-2019, 04:28 PM   #141
magicm
Member
 
Registered: May 2003
Distribution: Slackware
Posts: 226

Rep: Reputation: 144Reputation: 144
Meanwhile, back at the original question:
  1. It doesn't seem to add anything new that I needed done.
  2. It replaces a process that a reasonable user-admin could follow and tweek (via scripting) with something opaque to that skill level.
 
2 members found this post helpful.
Old 08-08-2019, 04:31 PM   #142
chrisVV
Member
 
Registered: Aug 2010
Posts: 469

Rep: Reputation: 268Reputation: 268Reputation: 268
Quote:
Originally Posted by GazL View Post
There may be nothing wrong with it technically, but it's not good practice. What if one changed the return type of that function? One would have to go through dozens of return statements changing them all. Let it break out of the case and then use a single return at the end of the function and you have just one return to modify. Now, as I said, I'm not a devout follower of the one in, one out, structured programming paradigm and I certainly don't mind using an extra return or so in a guard clause or two when it simplifies the code, but that code is IMO taking it a little too far. If you disagree, then that is your right. No need to get nasty about it.

As for your last sentence, think what you will, I'm not going to rise to that bait.
Sorry, when you write "OMG I just looked at it ... I'd be embarrassed to have written that" in order to show you are a real slackman complete with six-pack with hairy chest, for code which is absolutely fine in a function returning void (in fact, the best way to write it), not to mention your ridiculous unreachable return statement, then you have to expect to have the position pointed out to you.

Any thread about systemd is bound to end with this kind of "I'm harder than you" drivel.
 
1 members found this post helpful.
Old 08-08-2019, 04:33 PM   #143
GazL
LQ Veteran
 
Registered: May 2008
Posts: 5,794

Rep: Reputation: 3707Reputation: 3707Reputation: 3707Reputation: 3707Reputation: 3707Reputation: 3707Reputation: 3707Reputation: 3707Reputation: 3707Reputation: 3707Reputation: 3707
Quote:
Originally Posted by ttk View Post
Yes, what chrisVV said. Splitting code into separate functions and returning early is the clean, well-behaved, recommended alternative to goto.
I've no objection to guard clauses, but when you have a switch where every single case ends with a return, then why wouldn't you just put a single return after the switch and break out of the case clauses as normal, especially so when that switch is the last thing in the function and will be followed directly by a return anyway.

If you then have to modify the return type of that function at any time, it's just a single change.
 
Old 08-08-2019, 04:37 PM   #144
chrisVV
Member
 
Registered: Aug 2010
Posts: 469

Rep: Reputation: 268Reputation: 268Reputation: 268
Quote:
Originally Posted by GazL View Post
I've no objection to guard clauses, but when you have a switch where every single case ends with a return, then why wouldn't you just put a single return after the switch and break out of the case clauses as normal, especially so when that switch is the last thing in the function and will be followed directly by a return anyway.

If you then have to modify the return type of that function at any time, it's just a single change.
That's a weak self-justification. If you change the return type of the function you will end up rewriting a substantial part of the function logic. In any event, this function is always going to return void. As I say, it is written the correct way.
 
1 members found this post helpful.
Old 08-10-2019, 06:36 AM   #145
GazL
LQ Veteran
 
Registered: May 2008
Posts: 5,794

Rep: Reputation: 3707Reputation: 3707Reputation: 3707Reputation: 3707Reputation: 3707Reputation: 3707Reputation: 3707Reputation: 3707Reputation: 3707Reputation: 3707Reputation: 3707
Quote:
Originally Posted by chrisVV View Post
That's a weak self-justification. If you change the return type of the function you will end up rewriting a substantial part of the function logic. In any event, this function is always going to return void. As I say, it is written the correct way.
I disagree. It may not be an discussion winning point, but it is a valid benefit of the single return approach, and accusing me of self-justification is just another personal attack on me like your previous posts.

I simply don't like that systemd code, as I said you're free to take an alternative view, but I like my case statements to be terminated with a 'break' even if there's a 'return' right ahead of it, and I like my functions to be terminated by a 'return' rather than falling though to an implicit return because I believe it is good style. The reason I believe this is that IMO doing so reinforces program structure to the reader. The compiler may not care, but I as a human do.

My reaction to that code was over-stated, I'll give you that, but I still stand by my belief that it's an ugly style. Again, you are free to disagree, however I'd ask you to disagree sans the personal attacks in future.

Anyway, no one is interested in this argument, especially me, so I'm done arguing with you here.
 
1 members found this post helpful.
Old 08-10-2019, 06:48 AM   #146
hitest
Guru
 
Registered: Mar 2004
Location: Prince Rupert, B.C., Canada
Distribution: Slackware, OpenBSD, Debian
Posts: 6,593

Rep: Reputation: 2815Reputation: 2815Reputation: 2815Reputation: 2815Reputation: 2815Reputation: 2815Reputation: 2815Reputation: 2815Reputation: 2815Reputation: 2815Reputation: 2815
Quote:
Originally Posted by chrisVV View Post
Sorry, when you write "OMG I just looked at it ... I'd be embarrassed to have written that" in order to show you are a real slackman complete with six-pack with hairy chest
Ad hominem attacks are inappropriate. Attack the argument, not the person. Your personal attack did not strengthen your position.
 
4 members found this post helpful.
Old 08-10-2019, 07:15 AM   #147
ZhaoLin1457
Member
 
Registered: Jan 2018
Posts: 598

Rep: Reputation: 679Reputation: 679Reputation: 679Reputation: 679Reputation: 679Reputation: 679
Quote:
Originally Posted by hitest View Post
Ad hominem attacks are inappropriate. Attack the argument, not the person.
Just an inoffensive question:

this apply also to the people who derogatory calls a well-known RedHat programmer as "Lennart Voldemort" ?

Last edited by ZhaoLin1457; 08-10-2019 at 07:18 AM.
 
1 members found this post helpful.
Old 08-10-2019, 07:21 AM   #148
hitest
Guru
 
Registered: Mar 2004
Location: Prince Rupert, B.C., Canada
Distribution: Slackware, OpenBSD, Debian
Posts: 6,593

Rep: Reputation: 2815Reputation: 2815Reputation: 2815Reputation: 2815Reputation: 2815Reputation: 2815Reputation: 2815Reputation: 2815Reputation: 2815Reputation: 2815Reputation: 2815
Quote:
Originally Posted by ZhaoLin1457 View Post
this apply also to the people who derogatory calls a well-known RedHat programmer as "Lennart Voldermort" ?
Yes.
 
2 members found this post helpful.
Old 08-10-2019, 07:27 AM   #149
Lysander666
Senior Member
 
Registered: Apr 2017
Location: The Underearth
Distribution: Ubuntu, Debian, Slackware
Posts: 2,149
Blog Entries: 6

Rep: Reputation: 2431Reputation: 2431Reputation: 2431Reputation: 2431Reputation: 2431Reputation: 2431Reputation: 2431Reputation: 2431Reputation: 2431Reputation: 2431Reputation: 2431
Quote:
Originally Posted by ZhaoLin1457 View Post
Just an inoffensive question:
One can't guarantee that something is inoffensive. Offence is taken, not given. One can say that something is not intended to cause offence.

Quote:
Originally Posted by ZhaoLin1457 View Post
this apply also to the people who derogatory calls a well-known RedHat programmer as "Lennart Voldemort" ?
The contexts are different through. Nobody in this thread is arguing directly with Lennart P [to our knowledge].

Last edited by Lysander666; 08-10-2019 at 07:28 AM.
 
4 members found this post helpful.
Old 08-10-2019, 04:19 PM   #150
ChuangTzu
Senior Member
 
Registered: May 2015
Location: Where ever needed
Distribution: Slackware/Salix while testing others
Posts: 1,649

Rep: Reputation: 1791Reputation: 1791Reputation: 1791Reputation: 1791Reputation: 1791Reputation: 1791Reputation: 1791Reputation: 1791Reputation: 1791Reputation: 1791Reputation: 1791
Quote:
Originally Posted by Lysander666 View Post
One can't guarantee that something is inoffensive. Offence is taken, not given. One can say that something is not intended to cause offence.



The contexts are different through. Nobody in this thread is arguing directly with Lennart P [to our knowledge].
Unless of course ZhaoLin is LP , all along I thought it was one of Darth's many (possible) alternative accounts.
 
4 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Q. Can your Linux PC run Crysis? OK, it can. But will it run natively? A. Soon, very soon LXer Syndicated Linux News 0 03-11-2014 11:01 PM
LXer: My Nerd Life: Too Loud, Too Funny, Too Smart, Too Fat LXer Syndicated Linux News 0 01-24-2014 05:21 AM
LXer: Abolishing patents: Too soon or too late? LXer Syndicated Linux News 0 01-09-2013 02:20 PM
Application Assessment for Linux Migration MSquared Linux - Software 1 02-02-2005 05:14 PM
Probed and Attacked - Battle Damage Assessment halifax Linux - Security 2 08-17-2003 08:06 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 10:09 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration