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
Mr.Radar
Nov 5, 2005

You guys aren't going to believe this, but that guy is our games teacher.

chocojosh posted:

We couldn't have just used the ? operator?

The person who wrote that probably cut their teeth with VB6 and wasn't aware of the ?: operator. VB6 didn't have a dedicated short-circuiting inline conditional operator, but it included a (non-short-circuiting IIRC) IIF function that worked like the one you posted.

Mr.Radar fucked around with this message at 16:35 on May 7, 2008

Adbot
ADBOT LOVES YOU

Mr.Radar
Nov 5, 2005

You guys aren't going to believe this, but that guy is our games teacher.

ehnus posted:

Encountered today:

code:
public:
//private:
It's not as elaborately and stupid as most of these other coding horrors but it still makes me wonder what the intent was, why this was done, and if I can change it back without breaking people who may be depending on these private members now being public.
code:
#define private public
Yes, this is actually out there...

Mr.Radar
Nov 5, 2005

You guys aren't going to believe this, but that guy is our games teacher.

Lysandus posted:

This isn't so much a horror, as it just bugs me.

code:
HttpHeaders.HEADER_ACCEPT_ENCODING
Isn't
code:
HttpHeaders.ACCEPT_ENCODING

enough? :confused:

If that code is from a library for a high-level language (e.g. Python) which is wrapping a C library it's probably named like that because that's what the C constant was named.

Mr.Radar
Nov 5, 2005

You guys aren't going to believe this, but that guy is our games teacher.

Wheany posted:

But at some point, PHP didn't have an ecosystem or a user base.

At that time, wasn't the choice for web scripting pretty much between PHP, Perl 5.0, TCL, and C (yes, people wrote CGI programs in C) where PHP handled CGI and (to some extent) templating for you while the others made you do it all yourself? In that context, PHP was the sane choice.

Mr.Radar fucked around with this message at 03:16 on Dec 12, 2010

Mr.Radar
Nov 5, 2005

You guys aren't going to believe this, but that guy is our games teacher.

Orzo posted:

Why? If you really don't know anything about programming, there are certain things you need to understand before method signatures, access modifiers, and argument lists. Have you ever tried to teach any programming to a complete newbie? The entrypoint signature can be overwhelming. Even many introductory books say 'we'll come back to this later, but for now you always need to have this block of code for your program to run.'

But at the same time there are languages like Scheme and Python where you don't need to worry about those things at all. The real horror is teaching Java as a first language.

Mr.Radar
Nov 5, 2005

You guys aren't going to believe this, but that guy is our games teacher.
It also uses memset to force the system to actually allocate the memory pages rather than just promising to (as most modern systems do when you call malloc).

Mr.Radar
Nov 5, 2005

You guys aren't going to believe this, but that guy is our games teacher.

TasteMyHouse posted:

Apparently that code triggers a warning, "double is not assignable to int" http://try-dart-lang.appspot.com/s/_44V

but uh... so does this
http://try-dart-lang.appspot.com/s/D-cV

That's because / is the floating-point division operator. The integer division operator is ~/.

Mr.Radar
Nov 5, 2005

You guys aren't going to believe this, but that guy is our games teacher.

Zhentar posted:

The T_#_SECONDS appear stupid, but they only make up 101 lines out of 1208, and are presumably only there for symmetry with non-seconds definitions. T_7_DAYS on the other hand, is obviously more understandable than 25200, less error prone than 60*60*24*7, and faster than doing the math at runtime with a library, as justified in the README.

It is perhaps premature optimization (or maybe it was well justified from profiling!), but it's definitely not ':psyduck: what were they thinking?!'.

They could done macros that calculated the seconds from given time periods, e.g.
code:
#define TIME_S(s) (s)
#define TIME_MS(m, s) TIME_S(60*(m)+(s))
#define TIME_HMS(h, m, s) TIME_MS(60*(h)+(m), (s))
#define TIME_DHMS(d, h, m, s) TIME_HMS(24*(d)+(h), (m), (s))
//Convenience macros
#define TIME_D(d) TIME_DHMS((d), 0, 0, 0)
#define TIME_H(h) TIME_HMS((h), 0, 0)
//etc..
Any compiler worth anything would be able to constant-fold those expressions down to literal numbers so there's no drawback in terms of performance and a large gain in flexibility.

Mr.Radar
Nov 5, 2005

You guys aren't going to believe this, but that guy is our games teacher.

Look Around You posted:

I would like to know how they are going to a) use macros in a language which has none and b) rely on compilation optimization in a language which is not compiled.

(yes I know that the ruby interpreter could do this [and in fact probably does] but I don't know if that's good to rely on if you need the response time that they are apparently aiming for with this library)

Oops. I got confused by Dicky B's post into thinking the original code was C.

Edit: of course, the answer is to preprocess their Ruby source code with the C preprocessor :pseudo:

Mr.Radar fucked around with this message at 20:40 on Feb 1, 2012

Mr.Radar
Nov 5, 2005

You guys aren't going to believe this, but that guy is our games teacher.

rjmccall posted:

Which would, of course, not work, because it's not like the C preprocessor does constant folding either (except to resolve #if conditions).

Hence the :pseudo: (well, and the fact that Ruby syntax is different enough from C syntax to make it unlikely that most ruby code could be preprocessed correctly if at all).

Mr.Radar
Nov 5, 2005

You guys aren't going to believe this, but that guy is our games teacher.
So in Visual Studio 2013 Microsoft is finally adding the most useful features of C99/C11 that everyone else has supported since forever. I would be over the moon on this if I weren't stuck using Visual Studio 2005 for C development at my job. "Well that's pretty old, wouldn't they be moving to 2013 pretty soon then?" Yes, if they hadn't just started transitioning to 2010 shortly after I was hired in 2011 which is still ongoing (I'm told we can expect the first customer shipments of builds with 2010 late next year or early 2015). At this pace I'm expecting I'll finally be able to start coding against a language standard younger than I am at work in about 15 or so years :suicide:.

Mr.Radar
Nov 5, 2005

You guys aren't going to believe this, but that guy is our games teacher.

astr0man posted:

I'm in a shop that still uses VS2005 as well. We might transition to 2010 next year, but even if we do we'll still have to stick with C89 anyways, which really isn't that terrible of a requirement. :shrug:

Yeah, I was exaggerating a bit about bad it is, but it's still frustrating when Microsoft's pigheadedness about native development over the past decade (particularly C development) is the only reason I haven't been able to use C99 features to add extra safety to my code (it forces me to give my variables more scope than I would like to and prevents me from using const in some places), plus the horror that I still won't be able to until we drop 2005 and 2010 which will take way too long. Of course we also still use CVS and it doesn't seem that bad either (given the business practices we've developed around it) so I may not have the clearest perspective :v:.

Adbot
ADBOT LOVES YOU

Mr.Radar
Nov 5, 2005

You guys aren't going to believe this, but that guy is our games teacher.

Plorkyeran posted:

The entire point of the ten-day deadline was to get it into production before the alternative far worse scripting language being worked on.

Could you elaborate? I've never heard that there was something even worse than JavaScript that was being pushed and Wikipedia and Google aren't turning anything up.

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