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

When I posted that code all I hoped for was a few "heh"s... not this. :smith:

Adbot
ADBOT LOVES YOU

Scaevolus
Apr 16, 2007

A bus factor of zero means no one knows how the codebase works.

edit: :downs:

Scaevolus fucked around with this message at 20:08 on Jan 10, 2011

Scaevolus
Apr 16, 2007

Wheany posted:

I thought the whole point of BS was quick screen scraping:

The point was easy screen scraping. BeautifulSoup is written in Python, don't expect it to be fast.

lxml has essentially the same interface (and XPath), so there's really no reason not to use it.

Scaevolus fucked around with this message at 19:21 on Jan 27, 2011

Scaevolus
Apr 16, 2007

If you're calling abs(INT_MIN), something has probably gone wrong already.

Scaevolus
Apr 16, 2007

It looks like the Blackberry JVM is really bad:

quote:

Optimizing division operations
Division operations can be slow on BlackBerry® devices because the processor does not have a hardware divide instruction.

When your code divides a positive number by two, use shift right by one (>> 1). Use the shift right (>>) only when you know that you are working with a positive value.

Code sample

int = width >> 1;
Apparently it doesn't even have a peephole optimizer. :psyduck:

Scaevolus
Apr 16, 2007

It's probably a straightforward interpreter, with zero optimization:

quote:

Optimizing subexpressions
If you use the same expression twice, use a local variable.

Code sample

int tmp = i+1; one( tmp ); two( tmp );

Scaevolus
Apr 16, 2007

BonzoESC posted:

That's how AES-CTR and AES-OFB work, except the table is so fantastically large it's impractical to store.
Yes, stream ciphers work by XOR-ing a suitably random stream of bits with a message stream.

Scaevolus
Apr 16, 2007

That's not how aes_encrypt works, though. It expects to get a (random) 128-bit string.

It should probably be noted in the documentation, but I don't see how this is a horror.

Scaevolus
Apr 16, 2007

What's the horror?

Scaevolus
Apr 16, 2007

Zombywuf posted:

Look at the graph for the part before the Perl one goes crazy. It's orders of magnitude slower for the non pathological case. It also doesn't do back references. I think the only way this could be faster in the general case is that you could potentially do some bit-twiddling to match a whole SIMD register's width of regexes at the same time, maybe.
People have already corrected you on your speed assumptions, but note that Google developed the re2 library because they needed to be able to run regexes against database columns with predictable performance.

Scaevolus
Apr 16, 2007

the best quine

"This is a Ruby program that outputs a Python program that outputs a Perl program that outputs a Lua program that outputs a OCaml program that outputs a Haskell program that outputs a C program that outputs a Java program that outputs a brainfuck program that outputs a Whitespace program that outputs a Unlambda program that outputs the program itself."

code:
# ruby
l=92.chr;eval s="s=s.dump[r=1..-2].gsub(/("+l*4+"){4,}(?!\")/){|t|'\"+l*%d+\"'%(t
.size/2)};5.times{s=s.dump[r]};puts\"# python\\nprint(\\\"# perl\\\\nprint(\\\\\\
\"# lua"+l*4+"nprint("+l*7+"\"(* ocaml *)"+l*8+"nprint_endline"+l*15+"\"-- haskel
l"+l*16+"nimport Data.List;import Data.Bits;import Data.Char;main=putStrLn("+l*31
+"\"/* C */"+l*32+"n#include<stdio.h>"+l*32+"nint main(void){char*s[501]={"+l*31+
"\"++intercalate"+l*31+"\","+l*31+"\"(c(tail(init(show("+l*31+"\"/* Java */"+l*32
+"npublic class QuineRelay{public static void main(String[]a){String[]s={"+l*31+"
\"++intercalate"+l*31+"\","+l*31+"\"(c("+l*31+"\"brainfuck"+l*64+"n++++++++[>++++
<-]+++++++++>>++++++++++"+l*31+"\"++(concat(snd(mapAccumL h 2("+l*31+"\"110"+l*31
+"\"++g(length s)++"+l*31+"\"22111211100111112021111102011112120012"+l*31+"\"++co
ncatMap("+l*32+"c->let d=ord c in if d<11then"+l*31+"\"21002"+l*31+"\"else"+l*31+
"\"111"+l*31+"\"++g d++"+l*31+"\"22102"+l*31+"\")s++"+l*31+"\"2100211101012021122
2211211101000120211021120221102111000110120211202"+l*31+"\"))))))++"+l*31+"\","+l
*63+"\""+l*64+"n"+l*63+"\"};int i=0;for(;i<94;i++)System.out.print(s[i]);}}"+l*31
+"\")))))++"+l*31+"\",0};int i=0;for(;s[i];i++)printf("+l*63+"\"%s"+l*63+"\",s[i]
);puts("+l*63+"\""+l*63+"\");return 0;}"+l*31+"\");c s=map("+l*32+"s->"+l*31+"\""
+l*63+"\""+l*31+"\"++s++"+l*31+"\""+l*63+"\""+l*31+"\")(unfoldr t s);t[]=Nothing;
t s=Just(splitAt(if length s>w&&s!!w=='"+l*31+"\"'then 501else w)s);w=500;f 0=Not
hing;f x=Just((if x`mod`2>0then '0'else '1'),x`div`2);g x= reverse (unfoldr f x);
h p c=let d=ord c-48in(d,replicate(abs(p-d))(if d<p then '<'else '>')++"+l*31+"\"
."+l*31+"\");s="+l*31+"\"# ruby"+l*32+"n"+l*31+"\"++"+l*31+"\"l=92.chr;eval s=\"+
(z=l*31)+\"\\\"\"+s+z+\"\\\""+l*31+"\"++"+l*31+"\""+l*32+"n"+l*31+"\""+l*15+"\""+
l*7+"\")"+l*4+"n\\\\\\\")\\\")\"########### (c) Yusuke Endoh, 2009 ###########\n"
(he also wrote the qlobe)

Scaevolus fucked around with this message at 03:22 on Apr 15, 2011

Scaevolus
Apr 16, 2007

hq9+ quine
code:
q

Scaevolus
Apr 16, 2007

Volte posted:

Is there some kind of quine theory that reduces creating quines to some sort of mechanical procedure, or did that guy just spend way too much time on it
All the quines after the ruby one are basically just one long print("#next_language language_print("escaped string")), so it's trivial as long as you can get the base quine to set up the escaping properly.

e: okay, the haskell one does a bit of non-trivial escaping into brainfuck (and probably whitespace as well)

Scaevolus fucked around with this message at 00:35 on Apr 17, 2011

Scaevolus
Apr 16, 2007

mjau posted:

code:
#include <stdio.h>

int main ()
{
    int i;
    for (i = 1; i <= 100; ++i)
        printf("% 3d\n\0fizz\n\0buzz\n\0fizzbuzz\n"+(!(i%3)+2*!(i%5))*6, i);
    return 0;
}
:v:
We should follow that guy's advice and avoid unnecessary indentations as well.

code:
#include <stdio.h>
#include <stdlib.h>

int main(int n) {
    printf("%d\n\0  Fizz\n\0Buzz\n\0FizzBuzz\n"+(!(n%3)+2*!(n%5))*6, n);
    (main+((int(*)(int))exit-main)*(n/100))((n+1)%101);
}

Scaevolus
Apr 16, 2007

code:
#include <stdio.h>

int main(int n) {
    printf("%d\n\0  Fizz\n\0Buzz\n\0FizzBuzz\n"+(!(n%3)+2*!(n%5))*6,n)&&n%100&&main(n+1);
}

Scaevolus
Apr 16, 2007

Not to mention that reflection is very slow, so it's not the kind of thing you'd want to be doing in your networking code.

Scaevolus
Apr 16, 2007

Fehler posted:

code:
typedef double real;
const real two = (real)2;
const real pi = 3.141592653589793;
This project is gonna be fun!
Looks like a FORTRAN programmer has been forced to write C, and is resisting.

Scaevolus
Apr 16, 2007

"<< 1" instead of "* 2" is generally a horror.

Scaevolus
Apr 16, 2007

shodanjr_gr posted:

I sympathize with you for everything you said apart from the coding-style issue. Coding style consistency is critical inside a big project for readability and maintenance purposes...Unless he is forcing some rear end-backwards coding style, I don't see a problem with your manager fixing up your code. It's actually something that you are supposed to take care of yourself...
Consistent coding style for "readability and maintenance purposes" is comical considering the developers have to work with zend-guard obfuscated code.

Scaevolus
Apr 16, 2007

Plorkyeran posted:

The volatile there is extra-weird.
I think the volatile is meant as an extra-strong hint for buggy compilers that don't properly handle the union's double/char array aliasing.

He's probably been bitten by bad compilers for embedded systems before, making him learn a more defensive style of programming.

Scaevolus fucked around with this message at 00:55 on Aug 11, 2011

Scaevolus
Apr 16, 2007

ORMs are dumb, how are you supposed to savagely optimize your database usage? :downs:

Scaevolus
Apr 16, 2007

I hate my classmates.


INFINITY = 40000 #circumference of the earth

Scaevolus
Apr 16, 2007

Sometimes people really want to write Java.
code:
        choice = (str)(raw_input("Select a menu item: "))     
...  
        name = (str)(raw_input("Enter a file name : "))
...
        min_connections = (int)(raw_input('Minimum number of connections in a hub city :'))
...
        population = (long)(raw_input("Population : "))

Scaevolus
Apr 16, 2007

baquerd posted:

And what about that says Java to you?
It was written using PyDev and the programmer is most familiar with Java.

Scaevolus
Apr 16, 2007

Regarding Python's def fun(a, b,) thing, function arguments are not the same thing as tuples.

From the official grammar.
code:
funcdef: 'def' NAME parameters ':' suite
parameters: '(' [varargslist] ')'
varargslist: ((fpdef ['=' test] ',')*
              ('*' NAME [',' '**' NAME] | '**' NAME) |
              fpdef ['=' test] (',' fpdef ['=' test])* [','])
fpdef: NAME | '(' fplist ')'
def fun(*a,) is a syntax error since the only parameter that could come after it is **b, which isn't that necessary. def fun(**b,) is also a syntax error, since nothing could come after it.

Scaevolus
Apr 16, 2007

EpicCodeMonkey posted:

I never understood why the language (or other C-derived languages, for that matter) don't make fall-through legal in switch statements, but require that the last statement in each case be "break", "return", or "continue" - the latter specifying a fallthrough. If anything else is encountered it would be a syntax error. The only downside would be that:

code:
switch
{
     case 1:
     case 2:
          DoSomething();
}
Would be illegal both due to the missing break at the end, and the two case statements together with no code in between, but you could special-case that. This way there's no way a programmer can accidentally fallthrough, but it's still possible if that is desired.
I like Go's solution:

Expression switches

In an expression switch, the switch expression is evaluated and the case expressions, which need not be constants, are evaluated left-to-right and top-to-bottom; the first one that equals the switch expression triggers execution of the statements of the associated case; the other cases are skipped. If no case matches and there is a "default" case, its statements are executed. There can be at most one default case and it may appear anywhere in the "switch" statement. A missing switch expression is equivalent to the expression true.

In a case or default clause, the last statement only may be a "fallthrough" statement (§Fallthrough statement) to indicate that control should flow from the end of this clause to the first statement of the next clause. Otherwise control flows to the end of the "switch" statement.

The expression may be preceded by a simple statement, which executes before the expression is evaluated.

code:
switch tag {
default: s3()
case 0, 1, 2, 3: s1()
case 4, 5, 6, 7: s2()
}

switch x := f(); {  // missing switch expression means "true"
case x < 0: return -x
default: return x
}

switch {
case x < y: f1()
case x < z: f2()
case x == 4: f3()
}

Scaevolus
Apr 16, 2007

Optimus Prime Ribs posted:

I have to wonder: is Ramsus just a gigantic meat-head or is PHP an elaborate troll?
Yes.

Rasmus Lerdof posted:

I'm not a real programmer. I throw together things until it works then I move on. The real programmers will say "Yeah it works but you're leaking memory everywhere. Perhaps we should fix that." I’ll just restart Apache every 10 requests.

Rasmus Lerdof posted:

I don't know how to stop it, there was never any intent to write a programming language [...] I have absolutely no idea how to write a programming language, I just kept adding the next logical step on the way.

Scaevolus
Apr 16, 2007

Pangolin Poetry posted:

a recent horror that I constructed was to have a program calculate integers, then output them to a file as strings, which were then read into a different program as strings, which were then re-converted to integers, then cast as floats inside an array. then, i graphed them.

It sounds like you've implemented a poor man's version of UNIX pipes.

Scaevolus
Apr 16, 2007

Zombywuf posted:

CPU prediction logic has got more complex since then, which is what that problem seems to be about.

No, the problem is about cache aliasing.

Scaevolus
Apr 16, 2007

yaoi prophet posted:

What exactly happened with Itanium?

Over-optimistic sales forecasts. :v:

Scaevolus
Apr 16, 2007

Language developers not caring about algorithmic attacks is kind of a horror:

http://www.ocert.org/advisories/ocert-2011-003.html

https://www.youtube.com/watch?v=R2Cq3CLI6H8

Basically you can DOS most web frameworks easily by sending POST data with keys that are chosen to collide and cause worst-case hashmap performance.

Scaevolus
Apr 16, 2007

Crosscontaminant posted:

You should probably specify you're catching an XmlException - naked catch blocks are discouraged in Python (which I'm familiar with) and I can't imagine the same not being true for Visual Basic.
Did you read the thread title?

Scaevolus
Apr 16, 2007

BP posted:

Interestingly, we do have a TLS implementation available. However none of our customers actually use it due to "performance concerns", and internal management is equally wary. This is despite realistic performance tests with our application that show around a ~0.2% performance degradation from turning on TLS.

How much of a performance hit is the homebrew "encryption"?

Scaevolus
Apr 16, 2007

Zombywuf posted:

This is why Ritchie granted us the power to name functions.
We don't need static typing, we have Hungarian notation.

Scaevolus
Apr 16, 2007

Otto Skorzeny posted:

I thought the rules were 'just' that this wasn't allowed, eg. a read of type A from union {A, B} foo is only allowed if the last write to foo was of type A?
When how something would be implemented isn't obviously portable, the C/C++ standards tend to err on the side of "undefined"/"implementation dependent" rather than "illegal".

iirc, C99 doesn't even guarantee that integers are represented by two's complement.

Scaevolus fucked around with this message at 21:07 on Feb 19, 2012

Scaevolus
Apr 16, 2007

Munkeymon posted:

Well, yes and no. Literally
Awesome, if I ever have to use PHP again I'm going to write all my keywords in caps and say that I thought it was BASIC.

Scaevolus
Apr 16, 2007

The Gripper posted:

code:
void Butts(int? i = null) {
    if (i.Equals(null)) i = 42
    Console.WriteLine(i);
}
Good luck calling a method on a null object.

code:
void Butts(int? i = null) {
    i = i ?? 42;
    Console.WriteLine(i);
}

Scaevolus
Apr 16, 2007

Nippashish posted:

PHP's rand() function seems to have some pretty obvious patterns.

Woah, it's weird to see people link old stuff you've written.

pokeyman posted:

Yeah Windows rand() is loving worthless. Found that out when trying to reimplement the deals in FreeCell. It's got some ridiculously low period.
I did the same. :v: If you still have any desire for AUTHENTIC FREECELL DEALS, I could dig up my code.

Scaevolus
Apr 16, 2007

nielsm posted:

Not only that, you only need to recalculate lighting when something changes, and you can probably take a shortcut and only recalculate e.g. 15 blocks in each direction from the changed block.

That's basically what Minecraft does.

Adbot
ADBOT LOVES YOU

Scaevolus
Apr 16, 2007

There's a "new" OpenSSL vulnerability in the parser for ASN.1, a good example of the hilarious overcomplication that design-by-committee causes.

Some people are smart:

djmdjm posted:

FYI OpenSSH's sshd is not vulnerable, despite using OpenSSL. Back in 2002 and after a different ASN.1 bug, Markus Friedl observed that RSA verification used the OpenSSL's full ASN.1 parser to parse PKCS#1 RSA signatures despite them having an almost entirely fixed format under the parameters used in the SSH protocol.
He wrote a minimal RSA signature verification implementation that we've used ever since. This is the eighth bug that it has saved us from in the last ten years.

Some are cheeky as well:

mdowd posted:

I published that bug in our book (TAOSSA) in 2006. I just neglected to mention it was 0day.

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