[SOLVED] Is 2019 Still Too Soon For Intelligent Assessment of SystemD?
SlackwareThis Forum is for the discussion of Slackware Linux.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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.
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).
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.
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.
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.
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.
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.
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.