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
Scaevolus
Apr 16, 2007

j4cbo posted:

I wrote this. You'll need a decent grasp of x86 assembly to comprehend the horror...
To be fair, Assembly doesn't really lend itself to clear and readable code (without having a 1:1 opcode:comment ratio).

Adbot
ADBOT LOVES YOU

Scaevolus
Apr 16, 2007

http://luke.breuer.com/time/item/MeditechCodeProcessor/318.aspx

code:
Regex field = new Regex(@"
    (?<comment>
        (?:
            ^;\s*\n
        )?
        (?:
            ^;.*?
            (?:
                \ -\s*(?<sequence>\d+)
            )?
            \s*\n
        )?
        (?:
            ^;.*\s*\n
        ){0,5}
    )
    (?<setup>
        ^[^;]
        (?:
            .(?!@S)
        )*
        \s*\n
    ){0,3}
    (?<assignment>
        ^[^;].*\^@S
    )", RegexOptions.Multiline | RegexOptions.IgnorePatternWhitespace);

Scaevolus fucked around with this message at 22:46 on Mar 29, 2008

Scaevolus
Apr 16, 2007

nebby posted:

If we had editors that let you have rich symbology, colors, icons, tables, and flow diagrams instead just a static grid of ascii text of course this whole argument we just had would be moot since naming would take a backseat. Fortress doesn't count because you have to run the whole thing through LaTeX, and it's read only.
This is sarcasm, right? please?

Scaevolus
Apr 16, 2007

Project Euler Problem 22 posted:

Using names.txt (right click and 'Save Link/Target As...'), a 46K text file containing over five-thousand first names, begin by sorting it into alphabetical order

names.txt posted:

"MARY","PATRICIA","LINDA","BARBARA","MARIA","SUSAN","MARGARET","DOROTHY","LISA","NANCY",..."ALONSO"
The first part of someone's solution:
code:
#First load the file and sort it.
x = eval( '[' + open( '.../names.txt' ).readlines()[ 0 ] + ']' )
x.sort()
On principle, using eval is always wrong.

Scaevolus
Apr 16, 2007

Smackbilly posted:

That's terrible not only for the redundancy but also for the fact that it sefaults your program if either node or parent is NULL.
When you're writing tree structures, you can be pretty certain that that will never happen. Adding NULL checks to this would be stupid.

Scaevolus
Apr 16, 2007

Regarding the OpenSSL vulnerability,

http://metasploit.com/users/hdm/tools/debian-openssl/

It looks pretty bad--

quote:

Removing this code has the side effect of crippling the seeding process for the OpenSSL PRNG. Instead of mixing in random data for the initial seed, the only "random" value that was used was the current process ID. On the Linux platform, the default maximum process ID is 32,768, resulting in a very small number of seed values being used for all PRNG operations.

All SSL and SSH keys generated on a Debian-based systems (Ubuntu, Kubuntu, etc) between September 2006 and May 13th, 2008 may be affected.

...

Q: How long did it take to generate these keys?
A: About two hours for the 1024-bit DSA and 2048-bit RSA keys for x86. I used 31 Xeon cores clocked at 2.33Ghz.

So for a given architecture and release, there's only 215 different keys. He completely brute-forced the two most commonly used keyspaces in about 62 CPU hours.

Scaevolus
Apr 16, 2007

Melonhead posted:

What the hell is a Unicode keyboard? I am imagining a keyboard with over 100,000 buttons here.
I bet he means an APL keyboard.

Additional characters:

\ _ ¨ ¯ × ÷ ← ↑ → ↓ ∆ ∇ ∘ ∣ ∧ ∨
∩ ∪ ∼ ≠ ≤ ≥ ≬ ⊂ ⊃ ⌈ ⌊ ⊤ ⊥ ⋆ ⌶ ⌷
⌸ ⌹ ⌺ ⌻ ⌼ ⌽ ⌾ ⌿ ⍀ ⍁ ⍂ ⍃ ⍄ ⍅ ⍆ ⍇
⍈ ⍉ ⍊ ⍋ ⍌ ⍍ ⍎ ⍏ ⍐ ⍑ ⍒ ⍓ ⍔ ⍕ ⍖ ⍗
⍘ ⍙ ⍚ ⍛ ⍜ ⍝ ⍞ ⍟ ⍠ ⍡ ⍢ ⍣ ⍤ ⍥ ⍦ ⍧
⍨ ⍩ ⍪ ⍫ ⍬ ⍭ ⍮ ⍯ ⍰ ⍱ ⍲ ⍳ ⍴ ⍵ ⍶ ⍷
⍸ ⍹ ⍺ ⎕ ○

Let's stick to ASCII.

Scaevolus
Apr 16, 2007

No Safe Word posted:

Monkeypatching FTL.
How is this monkeypatching?

Scaevolus
Apr 16, 2007

Flobbster posted:

So the original question was, how efficient is this compared to a chain of if-statements? With -O3 enabled, the compiler does a phenomenal job of inlining this and it turns out it's exactly the same:
What about -O2?

Scaevolus
Apr 16, 2007

Flobbster posted:

-O2 comes out the same as -O3, compiled into to an inlined sequence of cmp/branch instructions. Under -O/-O1 though, the class, instantiated object, and method calls remain.

I ask because -O3 can cause some weird bugs, so I tend to use -O2.

Scaevolus
Apr 16, 2007

JoeNotCharles posted:

if you just automatically make an int, but you know it'll never get a value less than 0, you might want to change it to an unsigned int later to get more range.

never is a strong word

Scaevolus
Apr 16, 2007

Zombywuf posted:

Yes, yes, and holy gently caress python makes Ctrl-C an exception. Sheesh. But fair enough, go ahead and catch KeyboardInterrupt, pass the rest.
But it makes sense to handle trapped signals as exceptions-- would you rather there was a different language construct specifically for those sorts of interrupts?

Scaevolus fucked around with this message at 15:00 on Nov 5, 2008

Scaevolus
Apr 16, 2007

royallthefourth posted:

Dude, you just pre-incremented in order to increment the post! It seems like a post-increment would have been better suited!:cool:

edit: Wow, that really wasn't funny, in retrospect.

With complex object types, which post almost certainly is, as ++post implies all the tasks of logging in, finding a thread, writing a reply, etc., the pre-increment is more efficient that the post-increment, which tends to make useless copies of the object that most compilers are unable to optimize away.

Scaevolus
Apr 16, 2007

huge sesh posted:

I've always thought this one was real pretty
code:
not exp log srand xor s qq qx xor
s x x length uc ord and print chr
ord for qw q join use sub tied qx
xor eval xor print qq q q xor int
eval lc q m cos and print chr ord
for qw y abs ne open tied hex exp
ref y m xor scalar srand print qq
q q xor int eval lc qq y sqrt cos
and print chr ord for qw x printf
each return local x y or print qq
s s and eval q s undef or oct xor
time xor ref print chr int ord lc
foreach qw y hex alarm chdir kill
exec return y s gt sin sort split
that's one of the coolest JAPHs I've seen

Scaevolus
Apr 16, 2007

xkcd jokes get more hilarious with each repost!!

Scaevolus
Apr 16, 2007

Dijkstracula posted:

Well, given it's wrong, I should hope it's not used very often!

What's wrong with it?

Scaevolus
Apr 16, 2007

Avenging Dentist posted:

The sine function generally does not range from -0.0174532778 to 0.0174532778.

The only thing I can find wrong with it is that it uses degrees instead of gradians. :smug:

Scaevolus
Apr 16, 2007

Avenging Dentist posted:

Why would a system that uses 400 units for the angle of a circle be better?

Why would a 404 help your point?

Scaevolus
Apr 16, 2007

Avenging Dentist posted:

If you can't be bothered to figure out what the URL should be, perhaps you should go and hit the books mayhaps?

3 char extensions should be good enough for anyone!

Scaevolus
Apr 16, 2007

Avenging Dentist posted:

You know, if you got a 3-char extension maybe you wouldn't be a 2-bit poster anymore!

0_0

Scaevolus
Apr 16, 2007

quote:

There's a bit of controversy going on as to why the passwords were stored in plain text in the first place, with some arguing that it was because of the very large user base. Password hashing was apparently on the TODO list for the future, but that has become a priority now.
They must have been playing perl golf with their codebase or something, even just SHA1 with constant salt only takes a few more characters.

Scaevolus
Apr 16, 2007

4VAlien posted:

code:
Decimaal
Decimaal2
Decimaal sqlDSaanmaken
Decimaal2 Decimaal
Decimaal Decimaal

Here's the real horror.

Scaevolus
Apr 16, 2007

I thought it was a video encoder because of mbebuff_energy.

Scaevolus
Apr 16, 2007

10:33:11 < MononcQc> This has to come close to balls next to a cliff in terms of analogies: http://groups.google.com/group/comp.lang.scheme/msg/e7431893c4da4bbf?hl=en

Hi,
I understand continuations as taking a photo of what is happening, a special photo that you can use afterwards to go "to the past" where the photo was taking.
Continuations are very good on daily work, because you can take a photo (capture the *current* continuation) while you're having beers at the bar with your friends. If your daily work is boring you can always get your photo from your pocket and go instantly back to the bar with beers and friends. Great!!
Furthermore, when you take your photo (capture the *current* continuation) you pass a procedure to your camera (you *call* this procedure with the *current* continuation). The value returned by this procedure is then substituted in the very place you took your photo.
So continuations are a way to "return values from the future too" (you *call* a procedure with the *current* photo).
And this is fantastic!!
Imagine, for instance, that you're having beers with your friends at the bar. You then capture the current, comfortable, beer&friends continuation (take your photo) and say "let's capture a continuation here, and let's call a procedure that seeks what the winning lottery number is".
You then go to work, and you find in google what the winning lottery number is. You then pass this value (the value returned by the procedure) to the photo (the captured continuation). As a consequence you go immediately back to the bar... knowing what the winning lottery number is going to be!!
Now, isn't this fantasic? You just can win the lottery while being at the bar with beers and friends!! You won't have to go back to work again if you don't want to!!
In real life continuations don't exist (I wish they existed!), but while working with Scheme you can use continuations for doing some sort of things:
- Take a photo before seeking for something in a list. Pass a procedure to the photo that seeks for something in the list. (Looping).
- Iterate over all possible solutions to a problem. For each possible solution take a photo and pass it a procedure that sees if the solution is acceptable or not (backtracking).
- Perform a task. In the middle of the task take a photo and pass it a procedure that does another task (multitasking).
For examples of real-life usages of continuations you can take a look at [1], that contains "Design Patterns" explaining common situations for using continuations.
Cheers,
Antonio

Scaevolus
Apr 16, 2007

chocojosh posted:

So this is such a bad varation of the for-switch that once it matches either "mail", "facsimiletelephonenumber", or "telephonenumber" it's going to exit the loop.

Serious question, have you ever used C, C++, C#, or Java?

Scaevolus
Apr 16, 2007

Janin posted:

Why is it so much shorter than Mail::RFC822::Address?
Because normal people don't care about adhering to RFC822.

Scaevolus
Apr 16, 2007

Janin posted:

Well if you don't care about adhering to the standard, here's an even shorter regex:

.*@.*
Yes, there are sites that do that for basic form validation. The point isn't to make sure that the input is perfect, it's just to check that users enter something vaguely like an email in the field.

Scaevolus
Apr 16, 2007

ErIog posted:

I need a verdict. Is this a coding horror?

Yes, because you should be using lxml.

Scaevolus
Apr 16, 2007

Seth Turtle posted:

code:
    private static byte clampLo(byte lo, byte arg) {
       return (lo > arg) ? lo : arg;
    }
    private static byte clampHi(byte arg, byte hi) {
       return (hi < arg) ? hi : arg;
    }
Why isn't he just using the normal int type? This is the kind of optimization you would do on an 8-bit processor.

Scaevolus
Apr 16, 2007

PHP arrays: because every other data structure in the standard library is even worse.

Scaevolus
Apr 16, 2007

Captain Capacitor posted:

(Yes, I'm well aware of the etymological reasons behind this name)

It doesn't make it any less of a horror.

Scaevolus
Apr 16, 2007

The real horror of ftp is that the file list format isn't specified in the RFC, so clients have to implement multiple parsers to handle the different ways ftpds present information.

Scaevolus
Apr 16, 2007

Janin posted:

Some people don't put spaces around '=' for keyword arguments, but they're dumb.
From PEP8:
code:
      Don't use spaces around the '=' sign when used to indicate a
      keyword argument or a default parameter value.

      Yes:

          def complex(real, imag=0.0):
              return magic(r=real, i=imag)

      No:

          def complex(real, imag = 0.0):
              return magic(r = real, i = imag)

Scaevolus
Apr 16, 2007

C++ written by a former Fortran programmer:

code:
// this is in a function that loads settings from a file
if (!strcmp(str1, "locale_test"))
{
	double val = atof(str2);
	if (val == 0.5) locale_dot = true;
	else locale_dot = false;
}
else if (IFSresult) IFSresult = false;
else if (!strcmp(str1, "image_width")) params.image_width = atoi(str2);
else if (!strcmp(str1, "image_height")) params.image_height = atoi(str2);
else if (!strcmp(str1, "x_min")) params.doubles.amin = atof2(str2, locale_dot, &special->amin);
else if (!strcmp(str1, "x_max")) params.doubles.amax = atof2(str2, locale_dot, &special->amax);
else if (!strcmp(str1, "y_min")) params.doubles.bmin = atof2(str2, locale_dot, &special->bmin);
else if (!strcmp(str1, "y_max")) params.doubles.bmax = atof2(str2, locale_dot, &special->bmax);
else if (!strcmp(str1, "z_min")) params.doubles.cmin = atof2(str2, locale_dot, &special->cmin);
else if (!strcmp(str1, "z_max")) params.doubles.cmax = atof2(str2, locale_dot, &special->cmax);
[...200 similar lines...]
else if (!strcmp(str1, "file_envmap")) strcpy(params.file_envmap, str2);
else if (!strcmp(str1, "file_lightmap")) strcpy(params.file_lightmap, str2);
else if (!strcmp(str1, "file_animation_path")) strcpy(params.file_path, str2);
else if (!strcmp(str1, "file_keyframes")) strcpy(params.file_keyframes, str2);
else if (!strcmp(str1, "file_sound")) strcpy(params.file_sound, str2);
else if (!strcmp(str1, "palette")) GetPaletteFromString(params.palette, str2);
else
{
	printf("Warning! Unknown parameter: %s\n", str1);
	WriteLog("Warning! Unknown parameter:");
	WriteLog(str1);
}
There's a corresponding function to write out settings to a file, that looks pretty similar.

(You don't want to see the GTK interface code...)

Scaevolus
Apr 16, 2007

Janin posted:

You needn't even get that fancy; a simple parser class could clean up the duplicated code and symbol vomit:

code:
ParamParser p;

p.Integer("image_width", &(params.image_width));
p.Integer("image_height", &(params.image_height));
p.Double("x_min", &(params.doubles.amin), &(special->amin));
p.String("file_envmap", &(params.file_envmap));
// ...

while (/* get str1 and str2 here */)
{
  p.Parse(str1, str2);
}
This is my main issue. It's not that there's anything wrong with the code being explicit, it's just that there's so much redundancy in it.

Scaevolus
Apr 16, 2007

Jabor posted:

Probably, but it's even easier to do

code:
bool ThingHasBeenDone(a, b, c, d) {
    return (a && b) || c || d;
}

if (!ThingHasBeenDone(a, b, c, d))
This is a horror.

Scaevolus
Apr 16, 2007

code:
class RenderGlobal {
    ArrayList<Chunk> pendingChunks;
    ...
    public boolean renderNewChunks(Coord camera, boolean firstRun)
    {
        Collections.sort(this.pendingChunks, new DistanceComparator(camera));

        int lastChunkIndex = this.pendingChunks.size() - 1;
        int nChunks = this.pendingChunks.size();
        for (int i = 0; i < nChunks; i++) {
            Chunk chunk = this.pendingChunks.get(lastChunkIndex - i);
            if (!firstRun) {
                if (chunk.distance(camera) > 1024.0F) {
                    if (chunk.ready) {
                        if (i >= 3) 
                            return false; // termination point 1
                    }
                    else if (i >= 1) 
                        return false; // termination point 2
                }
            }
            else if (!chunk.ready)
                continue;
            
            chunk.render();
            this.pendingChunks.remove(chunk);
            chunk.notRendered = false;
        }

        return this.pendingChunks.size() == 0; // termination point 3
    }
    ...
}
Context:

1) this.pendingChunks averages 3000-5000 objects.
2) Collections.sort allocates a new array of the same size, copies all the elements out of the ArrayList, sorts them, then copies all the elements back.
3) The code always terminates at point 1 or 2, unless firstRun is true (i.e., it only processes the last ~3 objects in the list)

This method is called every frame, and accounts for 30% of CPU time on slower systems.

Scaevolus
Apr 16, 2007

HardDisk posted:

This came from Minecraft's source code, by any chance? :v:
Yes.

Scaevolus
Apr 16, 2007

crazylakerfan posted:

Dammit Notch, please let one of your employee rewrite your engine
This doesn't even begin fixing how the Minecraft engine renders >3x more triangles than necessary by not combining identical adjacent quads.

wlievens posted:

Do you mind sharing where you got this code from? Is Minecraft's code public? Or was this decompiled and cleaned up?
Decompiled, with variables renamed to reflect what I could figure out about their function.

Adbot
ADBOT LOVES YOU

Scaevolus
Apr 16, 2007

A pragmatic reason for code sucking doesn't mean it's not a coding horror.

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