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
Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe

JawnV6 posted:

If you look around and there's not anyone to learn from: leave.

You should be actively seeking out mentors in your company and industry. I have a longer post more suited to the oldie thread about the types of mentors you can't do too well without, but I can't really tell if you're responding to the specific instance or positing that you can't imagine someone unequivocally better existing at all.

Keep in mind that it doesn't have to be a learning within your field at all. One of the things that makes Red Hat such a great place to work at is because we're fairly well diversified. On my floor, I can talk to people who are experts in GPU technology and write GPU drivers and OpenGL implementations. Or I can talk to the guys who make your mouse and keyboard work and why all input hardware is terrible.

Or why your windows never seem to resize correctly.

Or how text rendering is a mess.

Or walk a floor up and learn about how video/audio compression and how codecs work.

Hm, maybe I should learn about compilers today. Hm, or not, maybe networking. Holy crap, I never knew rebooting a computer was this complicated.

I don't have any blog posts to link to, but I also talk with the sales/business people a lot. In fact, that's probably who I'm learning most from right now. They make great lunch partners, and I love hearing about all the social problems they have to solve as well, in their own little domain.

Adbot
ADBOT LOVES YOU

Bizarro Buddha
Feb 11, 2007

Flownerous posted:

int or float? I use that form if it's a float and I want to catch NaN too. Maybe I'm the horror?

How is !(NaN > 0) any more defined than (NaN > 0)?

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

Bizarro Buddha posted:

How is !(NaN > 0) any more defined than (NaN > 0)?

All comparisons with NaN are false, so they're both equally defined, yes. But the value of the expression is obviously different.

!(a > 0) is true for positive and negative zero, negative numbers, and NaNs. a <= 0 is true for positive and negative zeroes, and negative numbers but not NaNs.

(Assuming non-signaling NaN, of course.)

substitute
Aug 30, 2003

you for my mum
It's the same function, with the Dev's name for the second one.

php:
<?
I have a web team meeting tomorrow.

And, I may go to prison for murder. So long goons.

[php]
/**
 * Static content controller.
 *
 * This file will render views from views/pages/
 *
 * CakePHP(tm) : Rapid Development Framework ([url]http://cakephp.org[/url])
 * Copyright (c) Cake Software Foundation, Inc. ([url]http://cakefoundation.org[/url])
 *
 * Licensed under The MIT License
 * For full copyright and license information, please see the LICENSE.txt
 * Redistributions of files must retain the above copyright notice.
 *
 * @copyright     Copyright (c) Cake Software Foundation, Inc. ([url]http://cakefoundation.org[/url])
 * @link          [url]http://cakephp.org[/url] CakePHP(tm) Project
 * @package       app.Controller
 * @since         CakePHP(tm) v 0.2.9
 * @license       [url]http://www.opensource.org/licenses/mit-license.php[/url] MIT License
 */

App::uses('AppController', 'Controller');

/**
 * Static content controller
 *
 * Override this controller by placing a copy in controllers directory of an application
 *
 * @package       app.Controller
 * @link [url]http://book.cakephp.org/2.0/en/controllers/pages-controller.html[/url]
 */
class PagesController extends AppController {

/**
 * This controller does not use a model
 *
 * @var array
 */
    public $uses = array();

/**
 * Displays a view
 *
 * @param mixed What page to display
 * @return void
 * @throws NotFoundException When the view file could not be found
 *    or MissingViewException in debug mode.
 */
    public function display() {
        $path = func_get_args();

        $count = count($path);
        if (!$count) {
            return $this->redirect('/');
        }
        $page = $subpage = $title_for_layout = null;

        if (!empty($path[0])) {
            $page = $path[0];
        }
        if (!empty($path[1])) {
            $subpage = $path[1];
        }
        if (!empty($path[$count - 1])) {
            $title_for_layout = Inflector::humanize($path[$count - 1]);
        }
        $this->set(compact('page', 'subpage', 'title_for_layout'));

        try {
            $this->render(implode('/', $path),'cake-default');
        } catch (MissingViewException $e) {
            if (Configure::read('debug')) {
                throw $e;
            }
            throw new NotFoundException();
        }
    }
    
/**
 * Displays a view
 *
 * @param mixed What page to display
 * @return void
 * @throws NotFoundException When the view file could not be found
 *    or MissingViewException in debug mode.
 */
    public function developersName() {
        $path = func_get_args();
        $count = count($path);
        if (!$count) {
            return $this->redirect('/');
        }
        $page = $subpage = $title_for_layout = null;

        if (!empty($path[0])) {
            $page = $path[0];
        }
        if (!empty($path[1])) {
            $subpage = $path[1];
        }
        if (!empty($path[$count - 1])) {
            $title_for_layout = "DeveloperName: ".Inflector::humanize($path[$count - 1]);
        
        }
        $this->set(compact('page', 'subpage', 'title_for_layout'));

        try {
            //$this->layout = 'default_developersName';
            $this->render(implode('/', $path),'default');
        } catch (MissingViewException $e) {
            if (Configure::read('debug')) {
                throw $e;
            }
            throw new NotFoundException();
        }
    }
        
}

?>

substitute fucked around with this message at 02:31 on Mar 28, 2014

shrughes
Oct 11, 2008

(call/cc call/cc)

Gazpacho posted:

memset(out, NULL, bufSize);

The worst thing is passing NULL to memset.

qntm
Jun 17, 2009

leper khan posted:

if (!(foo > 0)) {
..
}

There's a number of IBM things which support all eight relational operators: EQ, NE, LT, LE, GT, GE, NL and NG. The latter two meaning "not less than" and "not greater than".

..btt
Mar 26, 2008
What happened to NGE and NLE? Seems like an embarrassing oversight!

Marta Velasquez
Mar 9, 2013

Good thing I was feeling suicidal this morning...
Fallen Rib

shrughes posted:

The worst thing is passing NULL to memset.

The code is initializing an array of pointers to NULL. It's odd, but I'm not totally against it.

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

contrapants posted:

The code is initializing an array of pointers to NULL. It's odd, but I'm not totally against it.

memset operates on bytes, not words, so passing something with pointer-meaning is pretty broken. In many C (rather than C++) environments it wouldn't compile, because NULL is (void *)0 rather than C++'s simple 0.

Marta Velasquez
Mar 9, 2013

Good thing I was feeling suicidal this morning...
Fallen Rib

Subjunctive posted:

memset operates on bytes, not words, so passing something with pointer-meaning is pretty broken. In many C (rather than C++) environments it wouldn't compile, because NULL is (void *)0 rather than C++'s simple 0.

You're right about that. I was thinking more along the lines of "at least I can tell what he's trying to do here" rather than what's actually correct.

Maybe the code at my job has made me too lenient to bad code.

code:
#define JBUTT_SUB(X) \
class X##_cls : public jbutt { \
public: \
private: \
    void jfart(void); \
    void jfoo(void); \
    void jbar(void); \
friend class jkrn; \
};

JBUTT_SUB(ja);
JBUTT_SUB(jb);
JBUTT_SUB(jc);
JBUTT_SUB(jd);
JBUTT_SUB(je);
Yes, he's using the preprocessor to create multiple classes. Every variable starts with a J, because Jesus should be in everything. The variable names I've used above to sanitize are far more descriptive than what is in the commentless code.

Nothing compiles unless if it is specifically passed to the preprocessor as a separate stage in the Makefile. I have no idea why yet.

edit: Missed a variable name

Marta Velasquez fucked around with this message at 15:18 on Mar 27, 2014

NtotheTC
Dec 31, 2007


Suspicious Dish posted:

Interesting links

thanks for these. one underlying theme im spotting is that hardware developers seem to hate software. and not in an ironic "haha software sucks, coding horrors amirite?" way- but a proper "everything should be hardware" way. is that actually a thing?

SavageMessiah
Jan 28, 2009

Emotionally drained and spookified

Toilet Rascal

contrapants posted:

Every variable starts with a J, because Jesus should be in everything.

Is that... is that really the reason? :psyduck:

Marta Velasquez
Mar 9, 2013

Good thing I was feeling suicidal this morning...
Fallen Rib

SavageMessiah posted:

Is that... is that really the reason? :psyduck:

I swear that it is.

Another product requires a copy of the Windows registry be exported to it as a tree of plain text files. This product runs Android. I wish I could just dump the entire repo into this thread.

I've learned to pick my battles during code reviews. The memset to NULL compiles, so I wouldn't have fought it. There are worse errors to fight about.

raminasi
Jan 25, 2005

a last drink with no ice
I've got somebody's hand-rolled graph algorithm code that I don't trust and now I have to decide between digging through it to debug it or just rewriting everything using a proper library and hoping they weren't doing anything intentionally weird. Unit tests or documentation? What are those?

feedmegin
Jul 30, 2008

Gazpacho posted:

C++ code:
string fileContents;
readFileIntoString(filePath, fileContents);

unsigned long outBytes = 0;
const size_t bufSize = 16384;
unsigned char * in = (unsigned char *) malloc(fileContents.length());
unsigned char * out = (unsigned char *) malloc(bufSize);

memcpy(in, fileContents.c_str(), fileContents.length());
memset(out, NULL, bufSize);
someTransformation(in, fileContents.length(), out, bufSize, outBytes);
free(in);
in = NULL;
string s = string((char *) out);
free(out);
out = NULL;
The project is C++ but there was a dev on the team who always thought it should have been C instead. One way he expressed that was by writing code like this.

For that to compile presumably there's a using namespace std; in there somewhere. Which is also horrible :colbert:

feedmegin
Jul 30, 2008

leper khan posted:

if (!(foo > 0)) {
..
}

Not sure I understand this one? (-1 is true in Calikes, remember, so this is 'do this if the value is 0 or negative', which seems fair enough)

Steve French
Sep 8, 2003

Two related links for consideration:

https://github.com/kohsuke/github-api/blob/master/src/test/java/org/kohsuke/AppTest.java#L76

https://github.com/kohsuke/test/issues?state=closed

ToxicFrog
Apr 26, 2008


feedmegin posted:

Not sure I understand this one? (-1 is true in Calikes, remember, so this is 'do this if the value is 0 or negative', which seems fair enough)

It would be a lot more readable as if (foo <= 0), though.

Gazpacho
Jun 18, 2004

by Fluffdaddy
Slippery Tilde

feedmegin posted:

For that to compile presumably there's a using namespace std; in there somewhere. Which is also horrible :colbert:
No, string.h is included and there are using declarations for individual types. I put "using namespace std;" in cpp files all the time, though. I'm not going to litter my code with "std::" if there's not a demonstrated conflict.

NtotheTC posted:

thanks for these. one underlying theme im spotting is that hardware developers seem to hate software. and not in an ironic "haha software sucks, coding horrors amirite?" way- but a proper "everything should be hardware" way. is that actually a thing?
I'm not seeing that in the articles at all. I do see people saying that software solutions should be informed by the observed hardware behavior.

What SD described is a benefit of working in any company that produces a general-purpose OS stack.

Dren
Jan 5, 2001

Pillbug

does that mean his github credentials are in the baseline...?

nm I read it wrong. I wonder if it was even meant as a test or if it's backdoor to list everyone who has built jenkins.

Dren fucked around with this message at 21:43 on Mar 27, 2014

Internet Janitor
May 17, 2008

"That isn't the appropriate trash receptacle."
Y'know, I think this line works remarkably well without further context:

code:
double balance = Math.round(balance * 100 + 0.49999);

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.
One horror per side of the equals sign is an excellent ratio!

LOOK I AM A TURTLE
May 22, 2003

"I'm actually a tortoise."
Grimey Drawer
I don't know, guys. Doubling my balance sounds like a great idea!

Sulla Faex
May 14, 2010

No man ever did me so much good, or enemy so much harm, but I repaid him with ENDLESS SHITPOSTING
Six months into the PHP project for a client, we're a few days away from finishing, and one of the guys is like "empty? What does that do.. Can't I just do if($var = null || $var = "") ?"

Dessert Rose
May 17, 2004

awoken in control of a lucid deep dream...
It's an oldie, but it never really gets old, does it?

code:
public const int TIMEOUT_30 = 30; // Die after 30 seconds if waiting for something that SHOULD happen.
public const int TIMEOUT_1 = 1;   // Only wait for 1 second when waiting for something that SHOULD NOT happen.
The comments are probably good enough. Let's not bother naming the constants something useful like TIMEOUT_EXPECTED_FAILURE or something.

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
Well, at least it isn't:

code:
public const int TIMEOUT_30 = 60; // Die after 30 seconds if waiting for something that SHOULD happen. 03/04/99: adjusted timeout to 60s --stevel

Howmuch
Apr 29, 2008
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:

LOOK I AM A TURTLE
May 22, 2003

"I'm actually a tortoise."
Grimey Drawer

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:

This is probably being done to facilitate unit testing. I think it's usually overkill, personally, but there are cases where it makes sense. Suppose for example that you have a method with a test like if (DateTime.Today.DayOfWeek == DayOfWeek.Monday) { ... }. How would you write a unit test for that if you can't override the value of DateTime.Today? Run it only on Mondays? There are a number of ways to deal with this issue, one of which is to hide DateTime.Now behind an interface and inject a mocked implementation in unit tests.

Now, if they're doing this but there are no actual unit tests to take advantage of it, then that's certainly the worst of both worlds.

Howmuch
Apr 29, 2008
Nope.

Hopefully it was made with unit testing in mind but in comparison with the rest of code from this person I seriously have my doubts.

Like the ~1800 line class on the DAL layer whose only purpose is to enable CRUD for one table in the database.

LOOK I AM A TURTLE
May 22, 2003

"I'm actually a tortoise."
Grimey Drawer

Howmuch posted:

Nope.

Hopefully it was made with unit testing in mind but in comparison with the rest of code from this person I seriously have my doubts.

Like the ~1800 line class on the DAL layer whose only purpose is to enable CRUD for one table in the database.

Probably a cargo cult thing, then. Or an "I'll definitely write tests for this. Later." thing.

big trivia FAIL
May 9, 2003

"Jorge wants to be hardcore,
but his mom won't let him"

Digging through some legacy databases:

code:
... PROCEDURE sp_GetAssignTries (@OrderId VARCHAR(25))

AS

RETURN 5;

GO
I think my favorite part is that it takes input.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

LOOK I AM A TURTLE posted:

Probably a cargo cult thing, then. Or an "I'll definitely write tests for this. Later." thing.

That seems likely. I've written almost identical code before, but that's because I was writing unit tests.

Of course, at this point I prefer to skip the boilerplate for such a simple case and just inject a Func<DateTime> into the class, with the default being () => DateTime.Now.

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?

shrughes
Oct 11, 2008

(call/cc call/cc)
It seems reasonable that people would want a MockTimeService for testing.

Howmuch
Apr 29, 2008

return0 posted:

How is this a horror at all?

I'm most likely the horror. :)

It's absolutely not horror when you have testing in place or planned("we do not have time for unit testing").

I think I managed to post the worst(best actually) snippet after spending an hour going through that mess.
I should have posted one of the 200+ line long functions that had max two character long variable names(a, aa, x, xx, y, yy and so on) and multiple nested loops.

Westie
May 30, 2013



Baboon Simulator

shrughes posted:

It seems reasonable that people would want a MockTimeService for testing.

Indeed.

What if you're implementing functionality regarding national holidays and you want to block something from occurring on that date?

PleasingFungus
Oct 10, 2012
idiot asshole bitch who should fuck off

ToxicFrog posted:

It would be a lot more readable as if (foo <= 0), though.

Except, as people discussed, that returns a different value if foo is NaN.

leper khan
Dec 28, 2010
Honest to god thinks Half Life 2 is a bad game. But at least he likes Monster Hunter.

PleasingFungus posted:

Except, as people discussed, that returns a different value if foo is NaN.

Yes, in this case changing it to that would have it produce the correct value if foo is NaN.

Sagacity
May 2, 2003
Hopefully my epitaph will be funnier than my custom title.

return0 posted:

How is this a horror at all?
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.

Adbot
ADBOT LOVES YOU

Jabor
Jul 16, 2010

#1 Loser at SpaceChem
Dependency injection is actually pretty cool, but it's actually much cooler to use a proper DI framework instead of hand-rolling that sort of thing. There's no reason to have a CurrentTimeService, it should just be a Provider<DateTime> with an annotation that says it provides the value of "now".

Having the current time being passed in as a method parameter is also workable, but it's really just pushing your own dependencies up to whoever's calling you, and often just results in even more boilerplate (or untestable code) being written elsewhere to accommodate it. It's really a case-by-case thing as to which is preferable.

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