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
Qwertycoatl
Dec 31, 2008

It must be a parody.

Please, let it be a parody.

Adbot
ADBOT LOVES YOU

Qwertycoatl
Dec 31, 2008

How I landed a high-paying new job

quote:

If applicable, flirt heavily with whomever is receiving the application - getting someone on your good side can only help you.

Qwertycoatl
Dec 31, 2008

There was an extremely short polyglot quine in an IOCCC entry a while back:
Description
code:

Qwertycoatl
Dec 31, 2008

If that's C#, you could have
code:
private static String getValue(String userValue, String moduleDefault, String globalDefault) {
    return userValue ?? moduleDefault ?? globalDefault;
}

Qwertycoatl
Dec 31, 2008

Treating generated code as anything other than an object file is a horror itself. You're not supposed to read it, so it's fine for a generator to make life easy on itself with stuff like do { ....} while (false) and whatever.

Qwertycoatl
Dec 31, 2008

I prefer to declare variables at the point of first use, because then it's completely impossible to accidentally use the variable uninitialised.

Qwertycoatl
Dec 31, 2008

I think C# does a reasonable job of it. You can't do the nearly as much with C# generics as with C++ templates, but unlike Java it doesn't have type erasure, so generics make sense and don't need heaps of stupid casts everywhere.

It still managed to inherit the array covariance misfeature though.

Qwertycoatl
Dec 31, 2008

GrumpyDoctor posted:

I would love to see a C implementation where the undefined behavior was things like "changes your desktop wallpaper to a picture of dogs playing poker" instead of just crashing.

http://www.feross.org/gcc-ownage/

Qwertycoatl
Dec 31, 2008

I came across this today:
code:
sprintf(buf, "%s.ext", buf);
strcat is for losers! So is well-defined behaviour!

Qwertycoatl
Dec 31, 2008

That's a lot of words he used just to say that his new project management software doesn't scale.

Qwertycoatl
Dec 31, 2008

Admiral H. Curtiss posted:

The best part is how he actually uses stack.size() (I'm assuming "stack" is an ArrayList) in that insane method -- if he knows it exists, why not just return that?

It looks to me like the sort of code that people send as a joke to idiots who ask programming forums to do their homework for them.

Qwertycoatl
Dec 31, 2008

Deffon posted:

What am I missing here exactly? At first I though that p wasn't NULL-terminated, but then I saw that 2 bytes were copied from "/" to p.

"/" is a string with two bytes, a '/' and a null. Copying those two bytes null-terminates p. It doesn't matter that the first memcpy doesn't null-terminate, because it's immediately followed by one that does.

Qwertycoatl
Dec 31, 2008

Bunny Cuddlin posted:

a lot of for loops in the codebase where I work have (int ii = 0; ii < whatever; ii++) and I just realized why this is.

I'd have thought it was so someone could search for 'ii' and find the loop variable, rather than trying to search for 'i' and finding every drat thing.

Qwertycoatl
Dec 31, 2008

When I'm writing a delete statement, I start off by writing "WHERE butts='Yes' AND farts=4" then go back and fill in the DELETE FROM once I'm happy with how the rest of it looks.

Qwertycoatl
Dec 31, 2008

HappyHippo posted:

Huh?

C# code:
public class Test<T>
{
    T[] SomeArray;
    public Test(int Size)
    {
        SomeArray = new T[Size];       
    }
}
Compiles fine.

The problem C# has with array covariance is this:
C# code:
class Base
{
}
class Derived : Base
{
}

// This function should never throw an exception, right?
// Wrong. SetBase(new Derived[1]) compiles, and the array access throws
// ArrayTypeMismatchException
static void SetBase(Base[] arr)
{
   if (arr.Length > 0)
      arr[0] = new Base();
}

Qwertycoatl
Dec 31, 2008

HappyHippo posted:

Right. But does that affect this case (with the stack class the prof is trying to make)?

code:
...
Works fine. Am I missing something?

No, that's fine. C# isn't as crazy as Java, it's just a bit crazy.

Qwertycoatl
Dec 31, 2008

ManlyWeevil posted:

From a code review:

C++ code:
    bool alreadyGotOneItem = flase;
According to the review notes this compiled and ran successfully.

#define flase 1

I'm sure it's in some header somewhere

Qwertycoatl
Dec 31, 2008

1337JiveTurkey posted:

Semi-serious idea: Cut out the middleman and store the parse tree directly in an open format like XML, YAML or JSON. Then have editors use a grammar to display the file for editing and to save the edited file. Use stylesheets to format the displayed source code. If you don't give a gently caress about whitespace, then you might as well have a language that doesn't give a gently caress about whitespace.

The problem with normalised formatting schemes is that people come up with the idea, then as they refine it they make a series of decisions that seemed to make sense at the time, and end up proposing a system that uses XML.

Qwertycoatl
Dec 31, 2008

Another reason to commit often is that if you make some changes that don't work out, it's really easy to get back to where you were before you started, without losing any actual correct work.

Qwertycoatl
Dec 31, 2008

Someone's trying to outdo losethos with their own homegrown language/OS monstrosity:
http://www.urbit.org/2013/08/22/Chapter-0-intro.html

quote:

If I can summarize Hoon’s goal, it’s to be the C of functional programming

So, how great an idea is this? Let's take a look at the networking code:
https://github.com/cgyarvin/urbit/blob/6012eed7a31f7dc9db323dbc4b1cbf361923f620/lib/191/arvo/ames.hoon
code:
!:
:: ames (4a), networking
::
  |= pit=vase
  ^- vane
  => =~
  ::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  :: section 4aA, identity logic ::
  ::
  |%
  ::
  ++ grip :: extend will
    |= [wet=will law=will]
    ^- will
    ?~ wet law
    ?: =(wet law) law
    ?^ t.wet
      ?>((meld i.wet i.t.wet) [i.wet $(wet t.wet)])
    ?~ law
      ?>((pier i.wet) [i.wet ~])
    ?~ q.p.q.i.wet
      ?>((meld i.wet i.law) [i.wet law])
    =+ rul=(sein r.p.q.i.wet)
    |- ^- will
    ?: ?& =(rul r.p.q.i.law)
            =(p.p.q.i.law u.q.p.q.i.wet)
        ==
      ?>((meld i.wet i.law) [i.wet law])
    ?>(?=(^ t.law) $(law t.law))
  ::
  ++ meld :: verify connect
    |= [new=deed old=deed]
    ^- &
    ?> (melt new old)
    ?> =((shaf %meld (sham q.new)) (need (sure:pu:(hail r.q.old) *code p.new)))
    %&
  ::
And so on. That file is 1500 lines. There are many other files. I've never before seen so much effort put into completely incomprehensible insanity.

Qwertycoatl
Dec 31, 2008

He has unorthodox ideas about software versioning, too:

quote:

In Kelvin versioning, releases count down by integer degrees Kelvin. At absolute zero, the system can no longer be changed. At 1K, one more modification is possible. And so on. For instance, Nock is at 9K. It might change, though it probably won't. Nouns themselves are at 0K - it is impossible to imagine changing anything about those three sentences

Qwertycoatl
Dec 31, 2008

SintaxError posted:

OK, am I insane for thinking that C include files should include any dependencies in them?

For some reason it got into the head of a few programmers here that forcing users to do this:

#include "someheaders_dependency.h"
#include "someheader.h"

is more right than just putting the dependency in in the header, which leads to me chasing down dependencies over the past hour and winding up with a list of 30 or so headers included because I need info about a single struct type that's apparently at the bottom of the dependency tree.

They gave me a reason once but I forgot it. Probably because I thought it was total bs, but is there really any valid reason to do this?

It sounds like total bs to me. I hate it when people write headers that aren't self-contained.

Qwertycoatl
Dec 31, 2008

Compilers these days can detect when a header has include guards and skip it the second time without having to re-read it.

Qwertycoatl
Dec 31, 2008

At a previous job, this is what the system did to look up a user's email address stored in a database:

1) In another database, look up the application ID in a different database to find the location of the database with the user information in it.
2) Convert the request to XML, and http post it to something running ASP.NET on the same server
3) The asp.net page converts the XML request into a different format of XML, and looks up the application ID in a database to find out what port the application is listening on.
4) asp.net does an http post back to the original application with the XML request.
5) The application reads the database information and request out of the XML, and retrieves the email address from the database, and packages it up in XML top send back to asp.net
5) asp.net converts the response XML into different XML, and returns it to the application.

I'd been asked to look into why the system was too slow. I replaced all that with a function call.

Qwertycoatl
Dec 31, 2008

Doctor w-rw-rw- posted:

PHP horrors are almost run of the mill, but nevertheless...

http://3v4l.org/XXbtf

PHP code:
<?php
echo date('F',strtotime("February"));
code:
Output for 5.2.0 - 5.5.5
March
Output for 5.1.0 - 5.1.6
January
Output for 4.3.0 - 5.0.5
December

If people are curious what's going on here:
In 4.3.0-5.0.5, strtotime("February") returns -1, ie one second before epoch, so the last second in December 1969.
In 5.1.0-5.1.6, strtotime("February") returns nothing, which is interpreted as epoch, ie January 1970.
In 5.2.0-5.5.5, strtotime("February") returns the current date and time, with the month forced to February, ie 31st February, which in true PHP style is the 3rd March.

Qwertycoatl
Dec 31, 2008

Why does this guy have permission to push to 180 repositories he's not involved with, anyway?

Qwertycoatl
Dec 31, 2008

Is there another mutex class in the codebase that isn't threadsafe?

Qwertycoatl
Dec 31, 2008

nielsm posted:

In languages that lack an explicit expression-if construction, having "and" and "or" return its arguments is a massive help. For instance in Lua, foo and bar or baz, equivalent to C ternary foo?bar:baz. The same also works in Python, and I prefer it to the bar if foo else baz construct, only because it keeps the condition first instead of stuffing it in between the two values.

I don't like it, because it looks like it's equivalent to foo?bar:baz but isn't.

Qwertycoatl
Dec 31, 2008

Look Around You posted:

Lmfao at the guy in the comments suggesting md5-hashing strings to make sure they're equal. And then someone replying to him cautioning about hash collisions (instead of pointing out how absurd it is to use a hash function to test for routine string equality).

That guy's comment is amazing.

quote:

Sometimes when you compare two strings that look "the same", you will find that they aren't. If you don't want to bother finding out why, then this is a simple solution:

$string = implode(str_split($string));

Converting the strings to md5 is also a nice method to see if they're equal.

md5($str1)."\n";
md5($str2)."\n\n";

Skimming the documentation, it looks like that "$string = implode(str_split($string));" just gets back to the original string. Is it just the commenter being dumb or does that code do something for some :psyduck: reason?

Qwertycoatl fucked around with this message at 10:47 on Jul 26, 2014

Qwertycoatl
Dec 31, 2008

omeg posted:

https://github.com/coapp-packages/bzip2/blob/master/decompress.c

That macro at the top with a case label in it... Was there no other way to do this? :psyboom:

It's pretty wtf and could do with a giant comment explaining what's going on, but it's a pretty neat way of doing coroutines.

Qwertycoatl
Dec 31, 2008

The Laplace Demon posted:

Can the number of topics only be even? The floor makes it equivalent to:
Java code:
int numTopics = Kmin + Kmax;
numTopics -= numTopics % 2;
He wrote , which most people would simplify to , so your mathematician probably isn't very good at math either...

The "min + (max - min)/2" looks like he heard about how to take an average without integer overflow messing things up, but didn't really believe it so cast everything to doubles just in case.

Qwertycoatl
Dec 31, 2008

Honest Thief posted:

The problem is they have a method signature setting, I guess, the flag to false to force the new logic, and yet kept the method signature as it is and the whole code. Because, I dunno. The only other place its used the flag is always true, so I dunno, either it's leftover code from whenever or..

It's not forcing the flag to false, it's setting a default value, so if a caller doesn't specify the flag it'll be false, but if they want it to be true they can set it.

Qwertycoatl
Dec 31, 2008

ErIog posted:

Is there anyone running a message board by abusing Git commit/merge/clone/message behavior yet? That would qualify for this thread.

Not exactly, but

Qwertycoatl
Dec 31, 2008

code:
unsigned int is_even(unsigned int x)
{
    for (unsigned int i = 0; i < x; i++) {
        x *= x;
    }
    return !x;
}

Qwertycoatl
Dec 31, 2008

return0 posted:

whoa, why does this work

It relies on integer overflow. If you repeatedly square an even number, it will become 0 mod 2^32. If you repeatedly square an odd number, it will become 1 mod 2^32. When one of those things happens, the for loop will terminate and the answer will come out.

Qwertycoatl
Dec 31, 2008


The best bit is that when you're in the nested function, you can use a goto to jump to a label in the outer function :catstare:

Qwertycoatl
Dec 31, 2008

Volmarias posted:

I saw this style a few days ago as well. I'd always heard legends, but never imagined I'd see it myself.

The best one I've seen in real life looked like this:
code:
alphabet = []
for (i in [1..26])  {
     switch (i) {
       case 1:
              alphabet.append("A")
       case 2:
              alphabet.append("B")
       .....
       case 26:
              alphabet.append("Z")
    }
}

Qwertycoatl
Dec 31, 2008

I normally like early return, especially for "bail early in error situations", but there's one situation where I end up regretting it. When debugging, I often find it useful to temporarily add in some logging to a function, like "called foo with parameter 3", "foo returned 7". With multiple return, it's a (minor) annoyance to add this in because the outbound logging has to go into multiple places (or I have to rename foo to foo_inner and make a wrapper).

Qwertycoatl
Dec 31, 2008

Hammerite posted:

Less flippantly, it seems like the proper answer to this situation would be to have an option on the archive-unpacking tool that says "if the contents aren't in a top-level directory, then create one for me, named after the archive, and put the files in there instead" (or that could be the default behaviour and there could be an option to suppress it).

I use dtrx to extract everything. It does exactly that, and also saves me from having to remember how the command line options for tar work.

Adbot
ADBOT LOVES YOU

Qwertycoatl
Dec 31, 2008

Cuntpunch posted:

code:
namespace Senior.Developers

This is my favourite part of this code. It's like the codinghorror "for sale: baby shoes, never worn"

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