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
return0
Apr 11, 2007
While I've got nothing as bad as that which has been posted, a colleague of mine was looking through some of my code and found something equivalent to this gem:

code:
private void SomeFunc(double _a, double _b)
{
    if(_a / _b > 1)
    {
        //...do stuff...
    }
    else
    {
        //...do other stuff
    }
}
I have absolutely no idea what the hell I was thinking. It did get written on a whiteboard under the heading "return0's FUCKUPS". Thankfully that's the only entry (so far). I've also spent five minutes trying to figure out why something I was scaling by zero wasn't visible. No scaling needed so scale by zero am I right?!

Adbot
ADBOT LOVES YOU

return0
Apr 11, 2007

such a nice boy posted:

What's wrong with that code? Is it just that
code:
if (_a > _b)
would have been better?

Yes, that's why it was insane. I wanted to branch based on which number was higher (i.e., if(_a > _b) ). My code requires more work, breaks for cases where an argument is negative, and obviously relies on _b not being zero. That's why it was such a wtf for me. I don't even remember writing it, but source control doesn't lie.

return0
Apr 11, 2007

ashgromnies posted:

(num & 1)==0 is correct.

What he posted in his example is incorrect.

code:
[b]First method:[/b]

Let n = 0111 (7 in decimal)

0110 &
0111
----
0110

Not equal to 0, therefore 7 is odd

Let n = 1010 (10 in decimal)

1001 &
1010
----
1000

Not equal to 0, therefore 10 is odd... WAITAMINUTE


[b]Second method:[/b]
Let n = 0111 (7 in decimal)

0111 &
0001
----
0001

Not equal to 0 therefore 7 is odd

Let n = 1010 (10 in decimal)

1010 &
0001
----
0000

Equal to 0 therefore 10 is even



if( ((num-1) & (num)) == 0 ) is not a test for evenness, it's checking for if num is a power of two.

It is however slightly incorrect in that zero is incorrectly considered to be a power of two, I think this can be used to fix that:

if(!(num & (num - 1)) && num )

return0
Apr 11, 2007

BigRedDot posted:

From the other end of the spectrum (bigger code block, but repeated few times) I recall some code from a physicist office mate once that had one 3000 line block of code repeated five times in a row—just with what amounted to a loop iteration variable changing everywhere in each block.


It was a savage optimisation.

return0
Apr 11, 2007
Hotels don't give a gently caress about reading input, pretending they do is a horror.

return0
Apr 11, 2007
Resisting speculative generality is great, but it's not an excuse for lazily writing bad code.

public void register(String name, int room)
public void register(Scanner scan)

Which is easier to write unit tests for?

return0
Apr 11, 2007

Scaevolus posted:

This is a horror.

Inline your booleans!

return0
Apr 11, 2007

b0lt posted:

Objective-C code:
#import <objc/runtime.h>
#import <Foundation/Foundation.h>
 
@interface aaagh : NSObject
- (void)
wtf;
@end
 
@implementation aaagh
- (void)
wtf {
    printf("wtf\n");
}
@end
 
class Test : private objc_object {
public:
    Test(void) {
        this->isa = [aaagh class];
    }
 
    operator id (void) const {
        return (id) this;
    }
};
 
int main(void) {
    Test foo;
    [foo wtf];
}
I am somewhat considering using this in production, help someone stop me the horror is coming from inside the house


Can you (or someone who knows about ObjectiveC/C++ interop) explain the horror here as it looks reasonable to me but I am clueless about Objective C so...

return0
Apr 11, 2007

Pixelboy posted:

I had a developer get pissy at me because I used the term "ex post facto" in a document.

Why the gently caress would you?

return0
Apr 11, 2007
Is it seriously called pdo? Is it pronounced like pedo?

return0
Apr 11, 2007

Hammerite posted:

It never occurred to me to read it that way. I always assumed it was pronounced "pee dee oh".

I thought that was what it probably was, but I am very juvenile.

return0
Apr 11, 2007
Vanilla java is a joke these days man, surely nobody is making new java software outside of phone apps and maintenance.

return0
Apr 11, 2007

Bognar posted:

Not if you're using it solely as an identifier. There are also some other strange things you could do with it in C# with extension methods. If you, for some reason, had functionality that could be used on any object (e.g. a GetHashCode() wrapper) but you only wanted it to appear on certain objects, you could have those objects inherit from an empty interface and define an extension method for that interface.

Doing this totally sucks and is a pet hate of mine. "Marker" interfaces indeed; terrible. If you want a GetHashCode or a ToString on some interface, put it on the interface?

return0
Apr 11, 2007

crazypenguin posted:

And the java one will print 3, and I'm not sure why anyone would think otherwise?

I maybe have my retarded goggles on but why 3 - is Java method overloading weird?

return0
Apr 11, 2007

Kilson posted:

Because you're passing in a B (not up-cast), so it should print 2?

I think so too but dont really do much java

return0
Apr 11, 2007
The blog post from Bryan Cantrill at Joyent is absolutely ridiculous, and if he worked for me I can definitely say he would be *fired* right now for that poo poo (lack of sensitivity towards non-native English speakers on gendered pronouns, and for publicly castigating someone for executing an established procedure rather than reflecting on What Went Wrong).

return0 fucked around with this message at 19:14 on Dec 1, 2013

return0
Apr 11, 2007

pointsofdata posted:

What's ridiculous about the blog post? It seems quite reasonable to me.

It presumes that the maintainer who reverted the commit is familiar enough with English to comprehend the subtleties of gendered pronouns and the social implications of using them in the docs that they would (without instruction or communication) deviate from established commit acceptance protocol for documentation changes, which in a distributed FOSS community is disgustingly anglocentric. He then tries to publicly humiliate the guy in a cynical attempt to appear like he is a cool dude.

return0
Apr 11, 2007

pointsofdata posted:

What's ridiculous about the blog post? It seems quite reasonable to me.

e: didn't quite catch your edit. Everyone involved seems pretty fluent and "they" instead of "he" is very common. It's pretty clear that What Went Wrong was Isaacs being a stereotypical programmer I'm not quite sure why you'd revert the commit otherwise.

It was Ben Noordhuis who reverted the commit, who is Dutch and not a native English speaker. He explains why he reverted it here https://github.com/joyent/libuv/pull/1015#issuecomment-29568172

I guess it's up to you if you think that Bryan Cantrill blog is a proportionate response, I don't and I think it's ridiculous?

return0
Apr 11, 2007

mjau posted:

So he's not a native english speaker, yet he thought he was qualified to reject changes to the english documentation by someone who is?

He probably thought he was qualified because it was his role on the project to enforce community standards, which this commit was in violation of? After it has all blown up it is very easy to say "well of course it's a good change and he should have accepted it" and apportion blame, but what if it was a random code change he was unfamiliar with that was committed out of line with the standard procedure, should he be responsible for finding an expert and verifying it (or was it the responsibility of the committer to explain the change, which it seems Isaacs did not do adequately)? It's absurd to blame this guy for correctly applying the established process just because the outcome is unpopular, and especially so for some dickhead to do so this dramatically on a public company blog (so it will appear in google from now on).

Look Around You posted:

"Fine, I'll just take my ball and go home"

To take your ball home means nobody else gets your ball; people still have the project, they just don't get his contributions any more. I think that's pretty reasonable that he doesn't spend his free time contributing to a community that is happy to call him an rear end in a top hat for an obviously genuine mistake.

return0 fucked around with this message at 21:15 on Dec 1, 2013

return0
Apr 11, 2007

Blinkz0rz posted:

Definitely not.

His apology struck me as the same kind of apology that politicians make, e.g. an "I'm sorry I offended someone" apology rather than a real consideration of the issue at hand. I understand if, being a non-native English speaker, he might have rejected it out of hand, but I think that speaks more for him overreaching his expertise rather than anything else.

The fact remains that the commit should have been merged without any argument and he's kind of a douche for not accepting it.

The reason that you are incorrect is that in a functional community, the community itself acts as a check and balance against improper applications of standard protocol. The maintainer reacted entirely reasonably to an out-of-band forced through commit that did not have proper authorisation, but then the community indicated to the maintainer that the change, while small, is significant. At this point the maintainer could then accept the commit.

The problem is that the node community is apparently deeply dysfunctional and cynical, and people are so eager to self-aggrandise that they will post Internet tough-guy rhetoric about how they would totally fire this guy for his sexist attitude. No fucks seem to be given that the guy was just applying established norms, or that this reaction will leave a public trail of underserved invective about his character (despite him giving up his own time to be a core-maintainer), or that it makes the community itself look bad.

Like seriously why is the guy a douche?

Blinkz0rz posted:

Of course, gender neutrality has no place in OSS.

In other news, women should always wear ankle length skirts so as not to offend the men-folk.

Nobody at all is saying this, you know this is an asinine strawman so why bother? The problem here is a bunch of people cynically riling up others to attack a guy who reverted a docs change, as he was compelled to by convention, because he didn't understand the significance of the content. This is very anglocentric (and possibly racist?). I don't think anyone is saying that the content of the change is bad in and of itself, it is better docs content; the problem is all the other poo poo.


Like if this guy forced through a code commit and it fixed a bug but it was reverted as it jumped the queue, nobody would give a gently caress right? But because it's a docs issue (so everyone can understand it) and because it's a contentious issue, the guy becomes the villain. But it's the same in both cases; applying standards to your version control history.

return0 fucked around with this message at 01:09 on Dec 2, 2013

return0
Apr 11, 2007

Blinkz0rz posted:

Saying something is Anglocentric (and possibly racist?) is missing the point (because, you know, gender issues are an international concern) and is really doing a disservice to the actual issue at hand.

The issue at hand is that Bryan Cantrill is cynically exploiting a community who care about gender equality by riling them up to abuse someone who made a genuine mistake (if you could call consistent application of the community policy a mistake!) for personal benefit.

return0
Apr 11, 2007

Blinkz0rz posted:

This:


isn't an apology or at least a "I'm not racist, my best friends are black" style apology? I must have missed something.

Either way, Ben Noordhuis should have recognized previous comments in the PR thread and/or understood the implications of maintaining gendered documentation. In no way did the PR harm anyone or do anything wrong, but rejecting it is a pretty serious indictment of either Ben's linguistic deficiency (in which case he's not qualified to evaluate PRs for English documentation) or a serious case of misogyny that needs to be corrected.

It's not an apology because he doesn't owe an apology. The situation is that he rejected a commit that was, by the communities standards, pushed incorrectly. The commit, however, was good (in that it improved something), but it was reverted because it did not follow process (all commits should improve something but they can't all just be pushed immediately right?); note that the process does not require Ben to validate this rejection with a set of experts. Why does he owe an apology for this, and why are you so unwilling to accept that a non-native english speaker who was unaware of the reason for this (extra-process) commit might have reverted it in good faith?

I guess I just don't understand the logic, when even by his own admission he volunteers in a mentorship program for young engineers to get involved in technology and volunteers as a core-maintainer on a popular project, why it is acceptable for rivals in that community to cynically exploit his actions and use them as a weapon in an ongoing power struggle between organisations in the node ecosystem. It trivialises the actual issue at hand, and taints the name of someone who is ostensibly innocent.

It's such obvious and transparent politicking from Cantrill I'm surprised you're falling for it tbh

return0
Apr 11, 2007

Blinkz0rz posted:

Who gives a flying gently caress about politicking in an open source project? The fact remains that Noordhuis was flippant about a PR that converted gendered pronouns to non-gendered pronouns and then, when he was called out on it, said "if it gets us scores of female contributors, who am I to object?"

If you're surprised that as a maintainer of a very large and very visible project he's being called out for his part in this then you need to back away from the computer and join the real world.

I'm done arguing about this. If you don't understand A) why gendered pronouns are bad and B) why Noordhuis is wrong --full stop-- then you have bigger issues than trying to spot the next coding horror.

Edit:


Probably true, but node is a pretty visible project and as a maintainer, he needs to understand that public actions have consequences, regardless of whether he intended them to. He probably didn't mean to offend anyone, but the flippant manner in which he dismissed the original PR and his non-apology apology indict him pretty seriously.

I don't think gendered pronouns are bad, they convey information that non gendered pronouns do not (specifically gender). I do think they are generally inappropriate for technical documentation and I agree with your broader point here. My problem is not with the commit, it's with people acting like Noordhuis was being a dick by reverting a rejected but pushed commit.

I'm not surprised he's being called out, I just think he doesn't deserve it.

I think you are well-meaning, but sheltered such that you don't understand how difficult it is to understand the subtleties in your non-native language, and lack the empathy to imagine what it would be like. I agree that it's pointless to continue arguing it, you've obviously made up your mind.

return0
Apr 11, 2007

shrughes posted:

Okay, so, back to the topic of coding horrors...

I can't even make this stuff up. Ever want to make sed or grep worse? Check this out: https://github.com/harthur/replace

Are you deliberately trolling given the previous topic? http://jaxenter.com/my-code-is-so-bad-it-makes-people-s-eyes-bleed-46072.html / http://harthur.wordpress.com/2013/01/24/771/

return0
Apr 11, 2007

shrughes posted:

No, it was a complete coincidence that I quoted verbatim two of the tweets.

Cool just checking

return0
Apr 11, 2007

Jewel posted:

I was confused about why "warning = limit * persentage" wouldn't work. I haven't worked with C++ in a little while so I thought "hm, does 'limit * persentage' create a new unsigned char of the multiplication, then cast that to long? I thought that makes sense so I did a quick test to see what the output would be. I got:

C++ code:
#include <iostream>

void multiply(unsigned char a, unsigned char b)
{
    unsigned long result;
    result = a * b;

    std::cout << +a << " * " << +b << " = " << result << std::endl;
}

int main()
{
    multiply(5, 5);
    multiply(255, 255);

    return 0;
}
With the output of:

code:
5 * 5 = 25
255 * 255 = 65025
Why is this? It seems to work? So my two questions: Why did their code snippet not work, and why does this work with regards to casting and overflow?

Maybe it's C++ and operator * is overloaded and crashes?

return0
Apr 11, 2007

GrumpyDoctor posted:

You can't overload operators unless one of the operands is a user-defined type.

And it looks like the horror is meeeeeee! Only ever done/seen it for custom math types but didnt know it was illegal for built-in.

return0
Apr 11, 2007

ErIog posted:

rolling your own bullshit untested nonsense

The purpose of asking someone to reverse an array is to see if they can solve a trivial problem using an algorithm, because they might have to write code that isn't implemented in a library.

return0
Apr 11, 2007

coffeetable posted:

No, that'd be the purpose of asking someone to reverse an array without using library functions.

Okay, so imagine that as a result of asking that question you discover they can't reverse an array without a library function - is this useful information to you, as the interviewer, which you didn't have before? If so it's a worthwhile question, right?

return0
Apr 11, 2007
Ah okay, I understand what you are saying now, I thought you were insane and suggesting the question itself had no value rather than just ambiguous to the interviewee.

return0
Apr 11, 2007

shrughes posted:

That is indeed an appropriate contribution for this thread, since it has undefined behavior on one of its inputs.

Out of curiosity what's the UB?

return0
Apr 11, 2007

shrughes posted:

You can see other circumstances where undefined behavior results in a surprise optimization, like seen http://lwn.net/Articles/342330/ <- there.

This is pretty cool tbh

return0
Apr 11, 2007

Howmuch posted:

I'm working on a big project at work and noticed a variation of this being used in the code in multiple places.

code:
lblTimeStamp.Text = timeService.GetCurrentTime().ToString();
Here's the magical timeService.

code:
interface ITimeNow
    {
        DateTime GetCurrentTime();
    }

    public class CurrentTimeService : ITimeNow
    {
        public DateTime GetCurrentTime()
        {
            return DateTime.Now;
        }
    }
:downs:

How is this a horror at all?

return0
Apr 11, 2007

Sagacity posted:

It's a horror because what previously could've been a simple call to DateTime.Now (or .UtcNow am I right?) now becomes an service/interface "look I have StructureMap" monstrosity.

A better option would be what Ithaqua mentioned (pass in a Func) but you could also, you know, have methods that accept a DateTime as input instead of having to inject some kind of nonsensical DateTimeProvider.

Hmm guess we'll just have to agree to disagree then :)

return0
Apr 11, 2007
I don't get why people hate the constructor. It's like, jeez just pass the stuff the class needs to the constructor already.

return0
Apr 11, 2007
It would be cool if a record scratch noise played in a meeting when people suggest using some GPL bullshit

return0
Apr 11, 2007

Jabor posted:

Is this why people implement their own memory allocator because they think the platform one isn't fast enough?

That said, there isn't a reason not to have per-cpu urandom state if someone wants to put in the work to implement it.

Usually people implement their own memory allocator for special cases where it is faster than an allocator that is fast for the general case, and where performance is important?

return0
Apr 11, 2007

Otto Skorzeny posted:

I'm sorry your google-fu is weak - try the string "define t&a" and it will come up under the 4th result on the first page, or "t&a acronym" and it will come up under the second result on the first page :)

e: oddly enough, DDG gives a surgical procedure as the first result. I had no idea tonsillectomies & adenoidectomies were usually performed together :monocle:

Google for "define t&a" just brings up stuff about tits for me, and I search for technical things a lot, I think you are not correct.

return0
Apr 11, 2007
It's a pretty well known/obvious way to check a bit is set, not sure what the horror is tbh?

Adbot
ADBOT LOVES YOU

return0
Apr 11, 2007

Zombywuf posted:

The correct way to test a bit in C++ is obviously:
C++ code:
#include <type_traits>
#include <cassert>

template<class Integer>
bool is_bit_set(int offset, Integer value) {
  static_assert(std::is_integral<Integer>::value, "Can only test integral types");
  assert(offset >= 0);
  assert(offset < sizeof(Integer) * 8);

  return value & (1 << offset);
}

why not just use value??

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