Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
xzzy
Mar 5, 2009

They probably have LINUX KERNEL DEVELOPER listed on their resume too. You can confirm it by looking at the commit logs!

Adbot
ADBOT LOVES YOU

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe

That one is actually fine, if not quite complete. The original code looks like this:

C code:
if (<some condition>) {
  <do something>;
  return;
} else {
  /* there's a comment here */
  <do something else>;
}
and the change makes it:

C code:
if (<some condition>) {
  <do something>;
  return;
}
  /* there's a comment here */
<do something else>;
Some people prefer this style, some dislike it, but the only thing objectively wrong with the change is that they didn't re-indent the comment.

Now, I personally try to reject patches like this as a code reviewer, for several reasons. First, sometimes it's much clearer and more consistent to write something as an else clause, especially when it's at the end of a longer chain of clauses, and there's no particular reason to dispute the original author on that point. Second, it's not uncommon for future changes to need to re-indent that clause anyway, e.g. to turn it into an else if. And third, it's kindof a waste of time to debate this level of code-formatting style, and once you accept one patch like this, you're probably going to see a hundred more. But maybe some project out there appreciates it, I dunno.

The larger issue here is that this person is clearly just trying to apply every suggestion made by a tool they don't understand, probably so that they can later claim "contributed many bug fixes to the android project" on their CV.

ExcessBLarg!
Sep 1, 2001

xzzy posted:

They probably have LINUX KERNEL DEVELOPER listed on their resume too. You can confirm it by looking at the commit logs!
I'd love it if they provided links to patches on their resume. I'd take one look at the patch and dismiss the guy with prejudice. Don't need to waste any more time on him.

Deep Dish Fuckfest
Sep 6, 2006

Advanced
Computer Touching


Toilet Rascal
This guy is gonna have the last laugh when a linker decides to place a string literal at 0x00 and you guys all get hosed over!

KernelSlanders
May 27, 2013

Rogue operating systems on occasion spread lies and rumors about me.

xzzy posted:

No, it's stupider than that. He read the output from a linter and took what it said literally.

Yet the linter wasn't smart enough to see that he was comparing two literals?

Volmarias
Dec 31, 2002

EMAIL... THE INTERNET... SEARCH ENGINES...

pseudorandom name posted:

checkpatch said Comparison to NULL could be written "!data"

:aaaaa:

It actually took a minute for this to sink in for me.

HappyHippo
Nov 19, 2003
Do you have an Air Miles Card?

xzzy posted:

Obfuscated code isn't necessarily bad code though, other than being completely unintelligible.

I think a challenge that makes code reviewers shake with anger could be pretty funny. I'm not sure I could be creatively stupid though.

You might enjoy this: How To Write Unmaintainable Code

quote:

To foil the maintenance programmer, you have to understand how he thinks. He has your giant program. He has no time to read it all, much less understand it. He wants to rapidly find the place to make his change, make it and get out and have no unexpected side effects from the change.
He views your code through a tube taken from the centre of a roll of toilet paper. He can only see a tiny piece of your program at a time. You want to make sure he can never get the big picture from doing that. You want to make it as hard as possible for him to find the code he is looking for. But even more important, you want to make it as awkward as possible for him to safely ignore anything.

quote:

10. Cd wrttn wtht vwls s mch trsr. When using abbreviations inside variable or method names, break the boredom with several variants for the same word, and even spell it out longhand once in while. This helps defeat those lazy bums who use text search to understand only some aspect of your program. Consider variant spellings as a variant on the ploy, e.g. mixing International colour, with American color and dude-speak kulerz. If you spell out names in full, there is only one possible way to spell each name. These are too easy for the maintenance programmer to remember. Because there are so many different ways to abbreviate a word, with abbreviations, you can have several different variables that all have the same apparent purpose. As an added bonus, the maintenance programmer might not even notice they are separate variables.

quote:

22. In naming functions, make heavy use of abstract words like it, everything, data, handle, stuff, do, routine, perform and the digits e.g. routineX48, PerformDataFunction, DoIt, HandleStuff and do_args_method.

quote:

28. If you have an array with 100 elements in it, hard code the literal 100 in as many places in the program as possible. Never use a static final named constant for the 100, or refer to it as myArray.length. To make changing this constant even more difficult, use the literal 50 instead of 100/2, or 99 instead of 100-1. You can futher disguise the 100 by checking for a == 101 instead of a > 100 or a > 99 instead of a >= 100.

Consider things like page sizes, where the lines consisting of x header, y body, and z footer lines, you can apply the obfuscations independently to each of these and to their partial or total sums.

These time-honoured techniques are especially effective in a program with two unrelated arrays that just accidentally happen to both have 100 elements. There are even more fiendish variants. To lull the maintenance programmer into a false sense of security, dutifully create the named constant, but very occasionally "accidentally" use the literal 100 value instead of the named constant. Most fiendish of all, in place of the literal 100 or the correct named constant, sporadically use some other unrelated named constant that just accidentally happens to have the value 100, for now. It almost goes without saying that you should avoid any consistent naming scheme that would associate an array name with its size constant.

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed

KernelSlanders posted:

Yet the linter wasn't smart enough to see that he was comparing two literals?

Why would the linter bother checking for something that the compiler will warn about?

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

The compiler likely doesn't know the value of "!data", given assembler/linker freedom, but it can probably assume it's not NULL on most platforms.

The MUMPSorceress
Jan 6, 2012


^SHTPSTS

Gary’s Answer
You're all assuming he ran the linter again or looked at its output after making his brilliant fix and pasting the original linter message in as justification.

b0lt
Apr 29, 2005

Subjunctive posted:

The compiler likely doesn't know the value of "!data", given assembler/linker freedom, but it can probably assume it's not NULL on most platforms.

It's a bit surprising that neither clang nor gcc emit -Wtautological-compare for this. I guess I should probably file a bug.

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

b0lt posted:

It's a bit surprising that neither clang nor gcc emit -Wtautological-compare for this. I guess I should probably file a bug.

It can't for anything but against explicit NULL, right? I thought that warning only tripped for > and < for some reason.

Meat Beat Agent
Aug 5, 2007

felonious assault with a sproinging boner
I thought that comparing a string literal against NULL would have emitted that warning too, but I tried it and was kinda surprised that it didn't.

Jabor
Jul 16, 2010

#1 Loser at SpaceChem
Comparing a string literal against another string literal is also tautological.

How does the compiler decide whether showing that warning is useful or not? I'd imagine that quite a lot of macro/template code has tautological comparisons once fully instantiated, with the expectation that those cases will be just be silently dropped where possible.

sarehu
Apr 20, 2007

(call/cc call/cc)
There are already those sort of warnings for that sort of thing for things like integer comparisons (comparing unsigned >= 0), and I don't like them, especially when I want to write robust code that doesn't depend on whether the type is signed or unsigned to do an assertion.

Strong Sauce
Jul 2, 2003

You know I am not really your father.





So I recently ran into a bug in an open source project I work on. A config setting message was printing out blank so I was looking through the code to debug it. For the most part I wasn't _super_ familiar with this portion of the code base so I've left most of it alone.

The gist of the code was this:
JavaScript code:
for line in lines
  regex = line.regex_it(/(.*)=(.*)/)
  if 'on' in regex && regex.length > 2
    for x in regex[1:]
      unless x in ['off', 'on']
        unless x in config.keys() && config[x].setting in ['med', 'high']
          config[x] = { setting: 'high' }
To explain, it takes an array of lines, tries to match "X=Y", check to see if Y is "on" and change the config to "high" if the config setting is currently at "low".

Nothing that slowed down the code, just the original author being very liberal with their use of the 'array contains' functions, extra loops, and unless statements. Also setting can only be low/med/high so not sure why they checked against med/high.

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe

Strong Sauce posted:

So I recently ran into a bug in an open source project I work on. A config setting message was printing out blank so I was looking through the code to debug it. For the most part I wasn't _super_ familiar with this portion of the code base so I've left most of it alone.

The gist of the code was this:
JavaScript code:
for line in lines
  regex = line.regex_it(/(.*)=(.*)/)
  if 'on' in regex && regex.length > 2
    for x in regex[1:]
      unless x in ['off', 'on']
        unless x in config.keys() && config[x].setting in ['med', 'high']
          config[x] = { setting: 'high' }
To explain, it takes an array of lines, tries to match "X=Y", check to see if Y is "on" and change the config to "high" if the config setting is currently at "low".

Nothing that slowed down the code, just the original author being very liberal with their use of the 'array contains' functions, extra loops, and unless statements. Also setting can only be low/med/high so not sure why they checked against med/high.

/(.*)=(.*)/ is the face you were supposed to make when you saw the code

canis minor
May 4, 2011

Strong Sauce posted:

Also setting can only be low/med/high so not sure why they checked against med/high.

If I'm not mistaken it changes low to high only - so if the config[x].setting isn't medium/high it changes it :downs:

It also changes it if the setting is disabled...

Jewel
May 2, 2009

Okay so is it just me or are sites like these (I forget their official name. mailing lists? newsgroups?) mostly unreadable (without heavy annoyance) to anyone else?

https://lkml.org/lkml/2015/11/19/454
http://comments.gmane.org/gmane.linux.drivers.driver-project.devel/75387

I have to scour the page for where the thread view might possibly be and even then it usually gives a weird navigation list that you have to try and work out who replied to what. And every single one of them uses their own horrible layout.

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

The lkml interface has always seemed pretty clear, if not really attractive. Indentation in the list on the left shows reply relationships.

They all have terrible search though.

xzzy
Mar 5, 2009

Gmane has been poo poo for browsing mailing list archives since day one. It looks exactly the same now as it did 15 years ago and it's never looked good.

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe

Jewel posted:

Okay so is it just me or are sites like these (I forget their official name. mailing lists? newsgroups?) mostly unreadable (without heavy annoyance) to anyone else?

https://lkml.org/lkml/2015/11/19/454
http://comments.gmane.org/gmane.linux.drivers.driver-project.devel/75387

I have to scour the page for where the thread view might possibly be and even then it usually gives a weird navigation list that you have to try and work out who replied to what. And every single one of them uses their own horrible layout.

it's not just you, those mailing list sites are all always super badly presented considering all they're really doing is showing threaded discussions.

ExcessBLarg!
Sep 1, 2001

Jewel posted:

Okay so is it just me or are sites like these (I forget their official name. mailing lists? newsgroups?) mostly unreadable (without heavy annoyance) to anyone else?
You're supposed to actually subscribe to the mailing list and read it in your favorite threaded MUA.

The various web archive interfaces are awful, but nobody seriously uses them.

xzzy
Mar 5, 2009

ExcessBLarg! posted:

The various web archive interfaces are awful, but nobody seriously uses them.

Problem being Google still spiders them and they pop up pretty high in search results and make you think you've found good discussion on a problem you're having.. and aww gently caress it's a gmane link.

ExcessBLarg!
Sep 1, 2001
Yeah, it would be helpful for Google to recognize it's a mailing list post and provide an alternate link to the Google Groups message. If you actually like Groups, that is.

Carbon dioxide
Oct 9, 2012

http://imgur.com/a/ARGjH

coke zero mit mayo
Nov 5, 2008
really mad at the placement of the braces there

Edit: Holy poo poo. The member declarations. Shoot me, now.

NihilCredo
Jun 6, 2011

iram omni possibili modo preme:
plus una illa te diffamabit, quam multæ virtutes commendabunt

I had a wild encounter in the F# subreddit and now I think I understand better the story about Babbage and the MPs.

a crazy man posted:

Hi all,
I'm trying to devise an efficient way to manipulating strings without the language's built-in functions (not even "string".Length nor "string".Substring() nor "string"[] and so on).
Let's say I want to substitute a letter of a string at the 3rd position.
code:
"string" -> "strong"
How can achieve it, without the aforementioned functions? My solution is generating lists of chars and by concatenating each of them, comparing them to the initial string. This way, starting from "A", "B", ..., "aa", "ab" I will eventually arrive at "string", which will return true to "string" = "string". At this point I will have a list of chars that correspond to the desired string, but... it is really expensive, computationally speaking.

Are there any other approaches? Can you think of or suggest me other solutions?

Thank you very much.

a sane man posted:

Because .NET strings implement seq<char> (AKA IEnumerable<char>), you could just iterate through the sequence, yield those chars you want to keep and yield your replacement when the forth index (3) is hit.
For example:
code:
"string"
|> Seq.mapi (fun index char -> if index = 3 then 'o' else char )
|> Seq.toArray
|> (fun charArray -> new string(charArray))
The built in string constructors can take a char array, hence the Seq.toArray and calling of the constructor. (Note that we cant just do "|> string" in that last step, as string is a function of type 'T -> string, which just calls the object's ToString() method)

a crazy man posted:

Thanks. However, I want to devise a solution that doesn't make use of anything rather than the simplest functional language constructs (lists, chars, comparison operators, ... and so on).

me posted:

I'm confused. You want to access the individual chars of your string, but doing that necessarily requires knowing how the string is made out of characters.
And the answer to that question is: the string is an array of characters. That's just what it is; any more "functional" (what do you mean by that?) construct you can come up with could only be a wrapper or interface around the array.

In fact, tehcrashxor's solution could be rewritten purely as an array transformation:
code:
"string".ToCharArray()
|> Array.mapi (fun index char -> if index = 3 then 'o' else char )
|> (fun charArray -> new string(charArray))
If your code has no understanding of "a string is made out of chars", then it cannot express the concept of "replace the third char with 'o'".

a crazy man posted:

quote:

any more "functional" (what do you mean by that?)
I beg your pardon, I'm rather new to functional programming and thought that only chars, strings, digits, boolean and lists were the core functional data-types. The way I devised is generating strings by concatenating chars. The problem is, in this way I must generate every single string up to that one in order to start manipulating it, which is exponentially costly.

I may rephrase my question: how can I sort out the issue above just by using these constructs?

I'm taking suggestions as to how I can possibly respond to that.

Bongo Bill
Jan 17, 2012

NihilCredo posted:

I had a wild encounter in the F# subreddit and now I think I understand better the story about Babbage and the MPs.

This story is unfamiliar to me.

ulmont
Sep 15, 2010

IF I EVER MISS VOTING IN AN ELECTION (EVEN AMERICAN IDOL) ,OR HAVE UNPAID PARKING TICKETS, PLEASE TAKE AWAY MY FRANCHISE

Bongo Bill posted:

This story is unfamiliar to me.

Charles Babbage posted:

"On two occasions I have been asked [by members of Parliament!], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question."

Volmarias
Dec 31, 2002

EMAIL... THE INTERNET... SEARCH ENGINES...

NihilCredo posted:

I'm taking suggestions as to how I can possibly respond to that.

"Good luck!" and then ignore the thread.

Deep Dish Fuckfest
Sep 6, 2006

Advanced
Computer Touching


Toilet Rascal

Volmarias posted:

"Good luck!" and then ignore the thread.

But then there is always this feeling in the back of one's mind, just grating under the surface trying to make sure things are made right...

Soricidus
Oct 21, 2010
freedom-hating statist shill

YeOldeButchere posted:

But then there is always this feeling in the back of one's mind, just grating under the surface trying to make sure things are made right...

We're rapidly approaching a thousand pages of coding horrors, in just this one thread out of many, and you still believe thing are ever going to be made right ...?

Carbon dioxide
Oct 9, 2012

Holy crap.

https://www.quora.com/What-is-a-coders-worst-nightmare/answer/Mick-Stute?srid=RBKZ&amp;share=1

This is worth reading.

Linear Zoetrope
Nov 28, 2011

A hero must cook

Ah yeah, the good ol' Ku Klux Komputer Klub always pullin' pranks.

:gonk:

Zopotantor
Feb 24, 2013

...und ist er drin dann lassen wir ihn niemals wieder raus...

Sounds suspiciously like Ken Thompson's scenario (Reflections on Trusting Trust). Does anybody know where or when this supposedly happened?

fritz
Jul 26, 2003

Zopotantor posted:

Sounds suspiciously like Ken Thompson's scenario (Reflections on Trusting Trust). Does anybody know where or when this supposedly happened?

Combined with the interfering computer subplot from Stephenson's "The Big U".

Xarn
Jun 26, 2015

Zopotantor posted:

Sounds suspiciously like Ken Thompson's scenario (Reflections on Trusting Trust). Does anybody know where or when this supposedly happened?

I am fairly sure I also saw this on TheDailyWTF, and it feels rather apocryphal.

Volte
Oct 4, 2004

woosh woosh

Zopotantor posted:

Sounds suspiciously like Ken Thompson's scenario (Reflections on Trusting Trust). Does anybody know where or when this supposedly happened?
Given root access to a machine it's a pretty well-known way to poison it. On the other hand, why did some random grad student have root access to the university machines in the first place? Exactly one person has sysadmin access to the CS department computers at my university: the department sysadmin.

Adbot
ADBOT LOVES YOU

fritz
Jul 26, 2003

Volte posted:

Given root access to a machine it's a pretty well-known way to poison it. On the other hand, why did some random grad student have root access to the university machines in the first place? Exactly one person has sysadmin access to the CS department computers at my university: the department sysadmin.

The 80s were a different time, and it's possible to imagine that the student had talked his way into getting root on just that one machine.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply