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
NFX
Jun 2, 2008

Fun Shoe

SurgicalOntologist posted:

Last week I called out the prof (my PhD advisor, incidentally) for providing unvectorized example code, I'm pretty sure now he's just trolling me. I wrote that I refuse to do part 2c on principle.

Your prof just knows that just like with Suspicious Dish's link to HashPass.php a few posts above, repetition is the key to success in programming.

Adbot
ADBOT LOVES YOU

FlapYoJacks
Feb 12, 2009
https://github.com/boundarydevices/imx_usb_loader/blob/master/imx_usb.c

Look at that horrible pile of poo poo. Why do people release poo poo like this to the public? I have ran into this more than once from companies.

Multiple .C files? gently caress that!
Variables that mean something? gently caress that!
Object oriented? It's C! What's an object?

:suicide:

Kilson
Jan 16, 2003

I EAT LITTLE CHILDREN FOR BREAKFAST !!11!!1!!!!111!
That really doesn't seem all that terrible.

Or maybe I'm just jaded by having to look at Asterisk's source code all the time. :cry:

substitute
Aug 30, 2003

you for my mum
I hate graphic designers.
code:
<h6>
	<a href="/company/locations">
		<span class="nowrap">See Contact</span>
		<span class="nowrap">Information for</span>
		<span class="nowrap">other Locations</span>
	</a>
</h6>

FlapYoJacks
Feb 12, 2009

Kilson posted:

That really doesn't seem all that terrible.

Or maybe I'm just jaded by having to look at Asterisk's source code all the time. :cry:

I don't know, I tend to use header files, objects, clearly defined macros, tons of comments, and clean indentation.

I also like the format:

code:

/*
 *@Brief: Quick blurb about what function does.
 *@Params: What parameters are needed for function to function.
 *@Retval: What will the function return on success and error and why.
*/
int Function_Butt(char *farts)
{
    /* Do Stuff.*/
    Stuff;
    /* If Stuff failed. */
    if (Stuff != 0)
    {
	/* Print standard error. */
	printf("Stuff failed. Error code %i\n", errno);
        /* Return error. */
        return -1;
    }
    /*If Stuff was successful, return success*/
    return 0;
}

But that's just me.

FlapYoJacks fucked around with this message at 19:42 on Feb 20, 2014

Don Mega
Nov 26, 2005

Kilson posted:

That really doesn't seem all that terrible.

Or maybe I'm just jaded by having to look at Asterisk's source code all the time. :cry:
A 200 line function is usually a good indication you should break up the logic.

fritz
Jul 26, 2003

ratbert90 posted:

https://github.com/boundarydevices/imx_usb_loader/blob/master/imx_usb.c

Look at that horrible pile of poo poo. Why do people release poo poo like this to the public? I have ran into this more than once from companies.

Multiple .C files? gently caress that!
Variables that mean something? gently caress that!
Object oriented? It's C! What's an object?

:suicide:

I just skimmed, but that doesn't look like a coding horror, more like a coding nuisance.

FlapYoJacks
Feb 12, 2009

fritz posted:

I just skimmed, but that doesn't look like a coding horror, more like a coding nuisance.

Huh, I guess I just don't like giant .c files with little to no comments and variable names that don't mean anything. I guess I am spoiled. :smith:

Hughlander
May 11, 2005

code:
#define get_min(a, b) (((a) < (b)) ? (a) : (b))
:allears: love code that can easily abused with multiple evaluation side-effects.

shrughes
Oct 11, 2008

(call/cc call/cc)
But it's so much faster than a function!

e: Also :lol: at the extraneous use of "get_" as prefix.

vOv
Feb 8, 2014

Is there any way to write a generic min() function in C that isn't terrible?

ExcessBLarg!
Sep 1, 2001

vOv posted:

Is there any way to write a generic min() function in C that isn't terrible?
If your compiler supports the typeof operator and Statement Expressions then you can do something like this:
code:
#define min(a,b) ({typeof(a) _a = (a); typeof(b) _b = (b); _a < _b ? _a : _b;})
But some might consider that to be terrible as well.

Rottbott
Jul 27, 2006
DMC

vOv posted:

Is there any way to write a generic min() function in C that isn't terrible?
No, it would end up like qsort - obnoxious to use and slow.

FlapYoJacks
Feb 12, 2009

Hughlander posted:

code:
#define get_min(a, b) (((a) < (b)) ? (a) : (b))
:allears: love code that can easily abused with multiple evaluation side-effects.

You should see Freescales kernel code implimentation.

Functions that lead to macros that are built on the fly from other macros. :suicide:

shrughes
Oct 11, 2008

(call/cc call/cc)
I was going to suggest writing a <? b but apparently that's only a C++ extension in gcc.

mjau
Aug 8, 2008

ExcessBLarg! posted:

If your compiler supports the typeof operator and Statement Expressions then you can do something like this:
code:
#define min(a,b) ({typeof(a) _a = (a); typeof(b) _b = (b); _a < _b ? _a : _b;})
But some might consider that to be terrible as well.

code:
int _a = 3;
int _b = min(4, _a);  // = 4

shrughes
Oct 11, 2008

(call/cc call/cc)
I'm no preprocessor guru, but

code:
#include <stdio.h>

#define concat_help(x, y) x##y
#define concat(x, y) concat_help(x, y)

#define expand_min(c, d, a, b) ({               \
      typeof(a) c = (a);                        \
      typeof(b) d = (b);                        \
      c < d ? c : d;})

#define min(a,b)                                \
  expand_min(concat(_gensym_, __COUNTER__),     \
             concat(_gensym_, __COUNTER__),     \
             a, b)

int main(void) {
  int _a = 3;
  int _b = min(4, _a);  // = 3
  printf("_a = %d, _b = %d\n", _a, _b);
  return 0;
}
Edit: I mean, yeah, s/\b_a\b/_gensym_0/g, sure.

shrughes fucked around with this message at 22:48 on Feb 20, 2014

ExcessBLarg!
Sep 1, 2001

mjau posted:

code:
int _a = 3;
int _b = min(4, _a);  // = 4
Preprocessor deficiencies is a bottomless pit of despair.

Dren
Jan 5, 2001

Pillbug

Suspicious Dish posted:

Was trying to book a flight today:

JavaScript code:
function TestNameValue(namevalue) {
    var status = true;
    var atest = /^[A-Za-z\s\-]+$/;

    if (namevalue.length == 0 || (/^\s*$/).test(namevalue))
        return status;

    // test for special characters
    var ss = namevalue.replace(/^\s*/, "").replace(/\s*$/, "");
    if (!ss.match(atest)) {
        status = false;
    }
    // check for multiple words
    //if (ss.split(" ").length - 1 > 1) {
    //    status = false;
    //}
    return status;
}

function ValidateContactName()
{
    var status = true;
    var ds = document.SkySales;
    var tbFirstName = ds['ControlGroupContactView$ContactInputContactView$TextBoxFirstName'];
    var tbLastName = ds['ControlGroupContactView$ContactInputContactView$TextBoxLastName'];

    if (tbFirstName != null && tbLastName != null) {
        if (!TestNameValue(tbFirstName.value) || !TestNameValue(tbLastName.value)) {
            status = false;
            alert("Contact name is invalid.");
        }
    }
    return status;
}
My legal name is "Jasper St. Pierre"

gently caress you AirTran.

(The irony is that I changed it because my original name, "Jean-Philippe St. Pierre" confused every form. AirTran's regexp accepts '-', but not '.')

What did you end up doing? Did you greasemonkey the page and turn off the validator?

Suspicious Dish
Sep 24, 2011

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

Dren posted:

What did you end up doing? Did you greasemonkey the page and turn off the validator?

Booked a flight on JetBlue instead.

ExcessBLarg!
Sep 1, 2001
autoquit - Automatically quit node.js servers when inactive.

OK, that's cool. But why would I ever want to do that?

Ruben Vermeersch posted:

You should really kill your backend at all times. This forces you to keep state out of it. Keep sessions in Mongo, Redis or memcache. Keep all important state out of the app tier.

That’s the first step towards scaling horizontally.
:stare:

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
Makes sense to me.

MrMoo
Sep 14, 2000

ratbert90 posted:

https://github.com/boundarydevices/imx_usb_loader/blob/master/imx_usb.c

Look at that horrible pile of poo poo. Why do people release poo poo like this to the public? I have ran into this more than once from companies.

Multiple .C files? gently caress that!
Variables that mean something? gently caress that!
Object oriented? It's C! What's an object?

:suicide:

Its quite nice really, but the aforementioned stupid get_min name and the C89 obsession weak stack handling in clearly C99 code. For some reason the author isn't aware of typedef tags.

MrMoo fucked around with this message at 00:28 on Feb 21, 2014

Plorkyeran
Mar 22, 2007

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

Suspicious Dish posted:

Makes sense to me.
Not keeping state in your app server is certainly a good idea, but it's not really something I've ever found myself having to go out of my way to do. Does node make it easy to accidentally have persistent state?

ExcessBLarg!
Sep 1, 2001

Plorkyeran posted:

Does node make it easy to accidentally have persistent state?
Not really.

Another thing that node doesn't make easy is gracefully handling folks who connect to your service just as it's autoquitting. Serving null responses and 504s is kind of rude.

Vanadium
Jan 8, 2005

Is typeof actually a thing in C11 or whatever. Can you hack it together with _Generic somehow.

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
_Generic is basically just a limited, non-extendable version of function overloading.

Suspicious Dish
Sep 24, 2011

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

ExcessBLarg! posted:

Not really.

Another thing that node doesn't make easy is gracefully handling folks who connect to your service just as it's autoquitting. Serving null responses and 504s is kind of rude.

I'd imagine that you'd have a load balancer or something in front to distribute HTTP requests to all your internal servers, and know when they're going down ahead of time.

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
In the scenario described there's only a single node instance that's started by systemd when a connection comes in on port 80. It sounds like there's a race condition if a request comes in between when node starts shutting down and when it finishes shutting down, but if you regularly go ten minutes with zero requests to your one instance, that's probably not a big deal anyway.

It sounds like mostly just a thing to make your initial deployment setup more similar to a real deployment setup behind a load balancer, and I guess I can get down with that even if the details are kinda goofy.

Plorkyeran fucked around with this message at 01:33 on Feb 21, 2014

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
If it's properly socket-activated, then when it starts to shut down, it would immediately unbind the port. In this case, systemd is now listening on the port, and when the server starts back up, it still has all listening connection in the queue and can call accept on them immediately.

So, I don't see the race.

ExcessBLarg!
Sep 1, 2001

Suspicious Dish posted:

So, I don't see the race.
The node module isn't unbinding from the socket and then waiting to ensure all accepted connections are closed. With the way node's event queue works (which I'm not an expert on, but I've seen problems like this in node.js code in the past) it's not clear to me that there isn't a potential a connection to be accepted, then the timeout handler to invoke shutdown, before the countConnection callback is processed. Granted the window is really small, and the likelihood of a connection is miniscule if there hasn't been one for ten minutes.

It's more that he proclaims "you should really kill your backend at all times" and provides utterly dubious reasoning, that serves no real purpose on a production machine.

Jewel
May 2, 2009

Wait were we talking about preprocessor macros? I love those things! Evidently, so does boost!

C++ code:
 /* BOOST_PP_SEQ_FOLD_LEFT */
#
# if 0
#    define BOOST_PP_SEQ_FOLD_LEFT(op, state, seq) ...
# endif
#
# define BOOST_PP_SEQ_FOLD_LEFT BOOST_PP_CAT(BOOST_PP_SEQ_FOLD_LEFT_, BOOST_PP_AUTO_REC(BOOST_PP_SEQ_FOLD_LEFT_P, 256))
# define BOOST_PP_SEQ_FOLD_LEFT_P(n) BOOST_PP_CAT(BOOST_PP_SEQ_FOLD_LEFT_CHECK_, BOOST_PP_SEQ_FOLD_LEFT_I_ ## n(BOOST_PP_SEQ_FOLD_LEFT_O, BOOST_PP_NIL, (nil), 1))
# define BOOST_PP_SEQ_FOLD_LEFT_O(s, st, _) st
#
# define BOOST_PP_SEQ_FOLD_LEFT_257(op, st, ss) BOOST_PP_ERROR(0x0005)
# define BOOST_PP_SEQ_FOLD_LEFT_I_257(op, st, ss, sz) BOOST_PP_ERROR(0x0005)
#
# define BOOST_PP_SEQ_FOLD_LEFT_CHECK_BOOST_PP_NIL 1
#
# define BOOST_PP_SEQ_FOLD_LEFT_CHECK_BOOST_PP_SEQ_FOLD_LEFT_I_1(op, st, ss, sz) 0
# define BOOST_PP_SEQ_FOLD_LEFT_CHECK_BOOST_PP_SEQ_FOLD_LEFT_I_2(op, st, ss, sz) 0
# define BOOST_PP_SEQ_FOLD_LEFT_CHECK_BOOST_PP_SEQ_FOLD_LEFT_I_3(op, st, ss, sz) 0
# define BOOST_PP_SEQ_FOLD_LEFT_CHECK_BOOST_PP_SEQ_FOLD_LEFT_I_4(op, st, ss, sz) 0
# define BOOST_PP_SEQ_FOLD_LEFT_CHECK_BOOST_PP_SEQ_FOLD_LEFT_I_5(op, st, ss, sz) 0
# define BOOST_PP_SEQ_FOLD_LEFT_CHECK_BOOST_PP_SEQ_FOLD_LEFT_I_6(op, st, ss, sz) 0
# define BOOST_PP_SEQ_FOLD_LEFT_CHECK_BOOST_PP_SEQ_FOLD_LEFT_I_7(op, st, ss, sz) 0
# define BOOST_PP_SEQ_FOLD_LEFT_CHECK_BOOST_PP_SEQ_FOLD_LEFT_I_8(op, st, ss, sz) 0
# define BOOST_PP_SEQ_FOLD_LEFT_CHECK_BOOST_PP_SEQ_FOLD_LEFT_I_9(op, st, ss, sz) 0
# define BOOST_PP_SEQ_FOLD_LEFT_CHECK_BOOST_PP_SEQ_FOLD_LEFT_I_10(op, st, ss, sz) 0
# define BOOST_PP_SEQ_FOLD_LEFT_CHECK_BOOST_PP_SEQ_FOLD_LEFT_I_11(op, st, ss, sz) 0
# define BOOST_PP_SEQ_FOLD_LEFT_CHECK_BOOST_PP_SEQ_FOLD_LEFT_I_12(op, st, ss, sz) 0
# define BOOST_PP_SEQ_FOLD_LEFT_CHECK_BOOST_PP_SEQ_FOLD_LEFT_I_13(op, st, ss, sz) 0
# define BOOST_PP_SEQ_FOLD_LEFT_CHECK_BOOST_PP_SEQ_FOLD_LEFT_I_14(op, st, ss, sz) 0
# define BOOST_PP_SEQ_FOLD_LEFT_CHECK_BOOST_PP_SEQ_FOLD_LEFT_I_15(op, st, ss, sz) 0
# define BOOST_PP_SEQ_FOLD_LEFT_CHECK_BOOST_PP_SEQ_FOLD_LEFT_I_16(op, st, ss, sz) 0
# define BOOST_PP_SEQ_FOLD_LEFT_CHECK_BOOST_PP_SEQ_FOLD_LEFT_I_17(op, st, ss, sz) 0
# define BOOST_PP_SEQ_FOLD_LEFT_CHECK_BOOST_PP_SEQ_FOLD_LEFT_I_18(op, st, ss, sz) 0
# define BOOST_PP_SEQ_FOLD_LEFT_CHECK_BOOST_PP_SEQ_FOLD_LEFT_I_19(op, st, ss, sz) 0
# define BOOST_PP_SEQ_FOLD_LEFT_CHECK_BOOST_PP_SEQ_FOLD_LEFT_I_20(op, st, ss, sz) 0
# define BOOST_PP_SEQ_FOLD_LEFT_CHECK_BOOST_PP_SEQ_FOLD_LEFT_I_21(op, st, ss, sz) 0
# define BOOST_PP_SEQ_FOLD_LEFT_CHECK_BOOST_PP_SEQ_FOLD_LEFT_I_22(op, st, ss, sz) 0
# define BOOST_PP_SEQ_FOLD_LEFT_CHECK_BOOST_PP_SEQ_FOLD_LEFT_I_23(op, st, ss, sz) 0
# define BOOST_PP_SEQ_FOLD_LEFT_CHECK_BOOST_PP_SEQ_FOLD_LEFT_I_24(op, st, ss, sz) 0
# define BOOST_PP_SEQ_FOLD_LEFT_CHECK_BOOST_PP_SEQ_FOLD_LEFT_I_25(op, st, ss, sz) 0

...

# define BOOST_PP_SEQ_FOLD_LEFT_CHECK_BOOST_PP_SEQ_FOLD_LEFT_I_251(op, st, ss, sz) 0
# define BOOST_PP_SEQ_FOLD_LEFT_CHECK_BOOST_PP_SEQ_FOLD_LEFT_I_252(op, st, ss, sz) 0
# define BOOST_PP_SEQ_FOLD_LEFT_CHECK_BOOST_PP_SEQ_FOLD_LEFT_I_253(op, st, ss, sz) 0
# define BOOST_PP_SEQ_FOLD_LEFT_CHECK_BOOST_PP_SEQ_FOLD_LEFT_I_254(op, st, ss, sz) 0
# define BOOST_PP_SEQ_FOLD_LEFT_CHECK_BOOST_PP_SEQ_FOLD_LEFT_I_255(op, st, ss, sz) 0
# define BOOST_PP_SEQ_FOLD_LEFT_CHECK_BOOST_PP_SEQ_FOLD_LEFT_I_256(op, st, ss, sz) 0
And then repeat for 3 more other similar blocks. Everything to do with boost scares me.

http://www.boost.org/doc/libs/1_49_0/boost/preprocessor/seq/fold_left.hpp

Edit: I forgot that the "other similar blocks" involve even worse :getin:

C++ code:
#    define BOOST_PP_SEQ_FOLD_LEFT_I_168(op, st, ss, sz) BOOST_PP_IF(BOOST_PP_DEC(sz), BOOST_PP_SEQ_FOLD_LEFT_I_169, BOOST_PP_SEQ_FOLD_LEFT_F)(op, op(169, st, BOOST_PP_SEQ_HEAD(ss)), BOOST_PP_SEQ_TAIL(ss), BOOST_PP_DEC(sz))
#    define BOOST_PP_SEQ_FOLD_LEFT_I_169(op, st, ss, sz) BOOST_PP_IF(BOOST_PP_DEC(sz), BOOST_PP_SEQ_FOLD_LEFT_I_170, BOOST_PP_SEQ_FOLD_LEFT_F)(op, op(170, st, BOOST_PP_SEQ_HEAD(ss)), BOOST_PP_SEQ_TAIL(ss), BOOST_PP_DEC(sz))
#    define BOOST_PP_SEQ_FOLD_LEFT_I_170(op, st, ss, sz) BOOST_PP_IF(BOOST_PP_DEC(sz), BOOST_PP_SEQ_FOLD_LEFT_I_171, BOOST_PP_SEQ_FOLD_LEFT_F)(op, op(171, st, BOOST_PP_SEQ_HEAD(ss)), BOOST_PP_SEQ_TAIL(ss), BOOST_PP_DEC(sz))
#    define BOOST_PP_SEQ_FOLD_LEFT_I_171(op, st, ss, sz) BOOST_PP_IF(BOOST_PP_DEC(sz), BOOST_PP_SEQ_FOLD_LEFT_I_172, BOOST_PP_SEQ_FOLD_LEFT_F)(op, op(172, st, BOOST_PP_SEQ_HEAD(ss)), BOOST_PP_SEQ_TAIL(ss), BOOST_PP_DEC(sz))
#    define BOOST_PP_SEQ_FOLD_LEFT_I_172(op, st, ss, sz) BOOST_PP_IF(BOOST_PP_DEC(sz), BOOST_PP_SEQ_FOLD_LEFT_I_173, BOOST_PP_SEQ_FOLD_LEFT_F)(op, op(173, st, BOOST_PP_SEQ_HEAD(ss)), BOOST_PP_SEQ_TAIL(ss), BOOST_PP_DEC(sz))
#    define BOOST_PP_SEQ_FOLD_LEFT_I_173(op, st, ss, sz) BOOST_PP_IF(BOOST_PP_DEC(sz), BOOST_PP_SEQ_FOLD_LEFT_I_174, BOOST_PP_SEQ_FOLD_LEFT_F)(op, op(174, st, BOOST_PP_SEQ_HEAD(ss)), BOOST_PP_SEQ_TAIL(ss), BOOST_PP_DEC(sz))

Jewel fucked around with this message at 03:33 on Feb 21, 2014

shrughes
Oct 11, 2008

(call/cc call/cc)
~summons That Turkey Story~

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
yeah I posted that a while ago and it started the worst argument

Dren
Jan 5, 2001

Pillbug
oh poo poo not this again

Jewel
May 2, 2009

I forgot we talked about this DON'T START ANYTHING we've done it before see this post if you want to see the discussion on it. Move along :allears:

vOv
Feb 8, 2014

What's the point of the

code:
# if 0
#    define BOOST_PP_SEQ_FOLD_LEFT(op, state, seq) ...
# endif
?

Marta Velasquez
Mar 9, 2013

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

vOv posted:

What's the point of the

code:
# if 0
#    define BOOST_PP_SEQ_FOLD_LEFT(op, state, seq) ...
# endif
?

It's a preprocessor way of commenting things out.

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
I assume it's there because the actual definition of BOOST_PP_SEQ_FOLD_LEFT on the next line doesn't make it at all obvious what the arguments to it are.

Adbot
ADBOT LOVES YOU

Blotto Skorzany
Nov 7, 2008

He's a PSoC, loose and runnin'
came the whisper from each lip
And he's here to do some business with
the bad ADC on his chip
bad ADC on his chiiiiip
Are my eyes all hosed up, or did the [code] tags get modified to use a variable width font :psyduck:

e: nope, opera just had the stylesheet hosed up :/

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