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
MrMoo
Sep 14, 2000

Eggplant posted:

Some gems from an ASP app that I inherited:
ASP always seems to promote the worst coding. I just wonder how these people think. Do they take days to do a couple of lines and forget half way through, or are just blind drunk?
code:
/* start poo poo */
$strNotFind=0;
$strData=$MyRS["size"];
while(strlen($strData)>0)
{
  $linLen=strlen($strData);
  $delimPos=(strpos($strData,"/") ? strpos($strData,"/")+1 : 0);
  if ($delimPos==$strNotFind && $linLen>0) {
    print "<option>".$strData."</option>";
    $delimPos=$linLen;
  } else {
    print "<option>".substr($strData,0,($delimPos-1))."</option>";
  } 
  $strData=substr($strData,strlen($strData)-($linLen-$delimPos));
}
/* end poo poo */

Adbot
ADBOT LOVES YOU

MrMoo
Sep 14, 2000

TRex EaterofCars posted:

It's an awesome hack... But come on, it's a hack. Using fallthrough like that is an anti-pattern unless you REALLY need the speed, like Tom Duff did.

The performance can actually be terrible as the increment is quite expensive, I found this out with a basic vector add & multiply. Array offsets work better ([n+1], [n+2], ...).

MrMoo
Sep 14, 2000

TRex EaterofCars posted:

you're saying that a register increment is expensive? inc reg is probably the cheapest op you can perform aside from the nop.

This:
code:
        int i = 0;
        count8 = len >> 3;              /* 8-way unrolls */
        if (count8)
        {
                while (count8--) {
                        d[i  ] ^= gfmul( b, s[i  ] );
                        d[i+1] ^= gfmul( b, s[i+1] );
                        d[i+2] ^= gfmul( b, s[i+2] );
                        d[i+3] ^= gfmul( b, s[i+3] );
                        d[i+4] ^= gfmul( b, s[i+4] );
                        d[i+5] ^= gfmul( b, s[i+5] );
                        d[i+6] ^= gfmul( b, s[i+6] );
                        d[i+7] ^= gfmul( b, s[i+7] );
                        i += 8;
                }

/* remaining */
                len %= 8;
        }

        while (len--) {
                d[i] ^= gfmul( b, s[i] );
                i++;
        }
Is faster than this, on a 3Ghz Xeon.
code:
    register n = (len + 7) / 8;
    switch (len % 8) {
    case 0: do { *d++ ^= gfmul( b, *s++ );
    case 7:      *d++ ^= gfmul( b, *s++ );
    case 6:      *d++ ^= gfmul( b, *s++ );
    case 5:      *d++ ^= gfmul( b, *s++ );
    case 4:      *d++ ^= gfmul( b, *s++ );
    case 3:      *d++ ^= gfmul( b, *s++ );
    case 2:      *d++ ^= gfmul( b, *s++ );
    case 1:      *d++ ^= gfmul( b, *s++ );
               } while (--n > 0);
    }
The array offsets are free on Intel processors.

MrMoo fucked around with this message at 08:31 on Mar 29, 2008

MrMoo
Sep 14, 2000

Triple Tech posted:

code:
print HANDLE "This one also demonstrates something else.";
print HANDLE "This programmer doesn't know how to use select.";
print HANDLE "Nor does he know what a heredoc is.";
print HANDLE "You get paragraphs of text that look like this.";
print HANDLE "For no reason, really.";

Same crap in PHP, I just roll my eyes and remember 8-bit BASIC. With PHP you have more options to make it read easier, so its even more retarded.

Similar vein is variable substitution like this, but for large HTML/XML blocks:
code:
echo "hello ".$user.", today is ".$date."\n";
The <<< function is obviously too much voodoo for some developers.

MrMoo
Sep 14, 2000

Victor posted:

Clearly, return is a function. :psyduck:

The SSL library by Reuters has oodles of wonders like this. Basically the API is 20 years old and needs to support every lovely poo poo poo poo compiler and linker out there. To an extreme. It's one function per file as old linkers don't smart link properly.

MrMoo
Sep 14, 2000

pokeyman posted:

(Did I miss anything?)

Return value seems to be undefined if string has length zero.

MrMoo
Sep 14, 2000

pokeyman posted:

It won't simply return the empty string?

If it were C that would be a problem, I guess from your comment strings are by default valid and empty. So presumably count would default to 0 too, so no need to set it, however I saw this too:

Delphi Basics posted:

Strings are indexed with 1 for the first character (arrays start with 0 for the first element).

MrMoo fucked around with this message at 11:50 on Apr 2, 2008

MrMoo
Sep 14, 2000

Lexical Unit posted:

So we use middleware to pass serialized objects around a network of machines. All code is c++. We have to interface with other people's code over this middleware.

Not really middleware then, just a communications system. Most normal message orientated middleware systems use a platform agnostic messaging format, like XDR name, value pairs, or modern behemoths like XML.

MrMoo
Sep 14, 2000

Lexical Unit posted:

Hence the horror.

I see a float too, float's even though IEEE specified are not standard across platforms. AIX/PowerPC has great issues with this.

Technically that middleware is tied to the sending system. TIBCO Rendezvous works across multiple platforms and has an agnostic message format, together with broken IEEE floating points. I'm amazed at the number of clients who expect it to translate even character encoding automagically between hosts.

MrMoo fucked around with this message at 16:24 on Apr 11, 2008

MrMoo
Sep 14, 2000

trashmatic posted:

Nope. It looks like assembly language for some DSP chip

The language looks like the DSP filter assembly language discussed here:

http://www.analog.com/library/analogDialogue/archives/31-2/dsp.html

MrMoo
Sep 14, 2000

Someone just pointed out a great structure in my code:
code:
 for (guint i = 0; i < count; i++)
 {

 } while ( STATE(data_bytes_offset)  < STATE(apdu_length) );
It compiles with no warnings at all, how does it work, is it exactly the same as this?
code:
for (guint i = 0; i < count && STATE(data_bytes_offset) < STATE(apdu_length);
i++)
{
}

MrMoo
Sep 14, 2000

nrichprime posted:

I've heard plenty of people describe conditions as being not false.

It's true:
code:
#define	TRUE	(!FALSE)
So with a signed int, true is -1, but aware that comparisons like 2 == TRUE fail because it's a value comparison not a logical comparison, the correct comparison being (2), the retarded version being 2 && TRUE.

MrMoo fucked around with this message at 14:59 on May 5, 2008

MrMoo
Sep 14, 2000

TRex EaterofCars posted:

There really should be an &= operator or something for referential equality.

Well don't these operators map into the extra math symbols, we have =, ≡, and ≣, so you could have === (≡) as data equality, and ==== (≣) for class equality.

I don't have a degree in maths, when would you use "identical to" === (≡) and "strictly equivalent to" ==== (≣)? I just found this for possible usage in OOP:

http://weblog.raganwald.com/2008/04/is-strictly-equivalent-to.html

MrMoo fucked around with this message at 06:33 on May 16, 2008

MrMoo
Sep 14, 2000

ashgromnies posted:

and most of it is equally unreadable... blargh.

It leans more towards retarded than unreadable, quite a few people skip using unless but it's a bit sill considering the post-conditional check.

MrMoo
Sep 14, 2000

mofmog posted:

I was bored. On a friday night. Oh god.

Oh dear, difficult to be so concise in C:

code:
#include <errno.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int
atostr (char* dest, const char* src)
{
	static const char* digit[] = { "zero", "one", "two", "three", "four", 
  "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", 
  "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen", "twenty", 
  "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety" };
	long val;
	char* endptr;

	val = strtol (src, &endptr, 10);

	if (	(errno == ERANGE && (val == LONG_MAX || val == LONG_MIN) )
	     ||	(errno != 0 && val == 0)	)
	{
		perror ("strtol");
		return EXIT_FAILURE;
	}

	if ( endptr == src ) {
		fprintf (stderr, "No digits were found\n");
		return EXIT_FAILURE;
	}

	if ( val > 999 ) {
		fprintf (stderr, "Number out of range\n");
		return EXIT_FAILURE;
	}

	*dest = 0;

	do {
		if ( val > 99 ) {
			strcat (dest, digit[ val / 100 ]);
			strcat (dest, " hundred");
			if ( val %= 100 ) {
				strcat (dest, " and ");
			} else {
				break;
			}
		}

		if ( val > 19 ) {
			strcat (dest, digit[ val / 10 + 18 ]);
			if ( val %= 10 ) {
				strcat (dest, "-");
			} else {
				break;
			}
		}

		strcat (dest, digit[ val ]);
		break;

	} while (val);

	*dest = toupper (*dest);

	return EXIT_SUCCESS;
}

int
main (int argc, char* argv[])
{
	char buff[1024];

	if (argc != 2 || atostr( buff, argv[1] ) == EXIT_FAILURE) {
		fprintf (stderr, "Usage: %s [NUMBER]\n", argv[0]);
		exit(EXIT_FAILURE);
	}

	puts (buff);

	return EXIT_SUCCESS;
}

MrMoo
Sep 14, 2000

subreality posted:

php:
<?
  while ($image_width < $max_width) {
    $image_width = $image_width - 1;
  }
?>
Really '<' not '>'? How long does that run for?

MrMoo
Sep 14, 2000

Ryouga Inverse posted:

How are you going to deal with the corpus of already-existing code?

Re-write it when it fails or needs modification. Probably end up with something neat like MUMPS-Linq.

MrMoo
Sep 14, 2000

Parantumaton posted:

There's also two variants of IO API:s in Java, IO and NIO ("New IO"), latter is the faster one in certain situation (there's -if I remember correctly- 16 ways to read in a file in Java at the moment, uhh...).

Not enough! Say hello to NIO.2.

MrMoo
Sep 14, 2000

Janin posted:

Where I work, none of the builds use -Wall because "it prints too much noise".
Conversely I use the following because -Wall is too quiet,

-Wall -Wextra -Wfloat-equal -Wshadow -Wunsafe-loop-optimizations -Wpointer-arith -Wbad-function-cast -Wcast-qual -Wcast-align -Wwrite-strings -Waggregate-return -Wstrict-prototypes -Wold-style-definition -Wmissing-prototypes -Wmissing-declarations -Wmissing-noreturn -Wmissing-format-attribute -Wredundant-decls -Wnested-externs -Winline -pedantic

If you want really noisy output try the ICC compiler, warnings 981 "operands are evaluated in unspecified order" and 2259 "non-pointer conversion from "*" to "*" may lose significant bits" are crazy.

MrMoo
Sep 14, 2000

fritz posted:

insure++ warns (warned?) about not saving the return value from printf

That's where you end up with all the lazy developers doing inane hacks like void casting returns:
code:
(void)printf ("moo moo moo");
I've also seen many build scripts redirect warnings to /dev/null :haw:

MrMoo
Sep 14, 2000

RussianManiac posted:

What do you mean? Can you extrapolate?

while (0) is used to allow a semicolon after the macro call, it's pretty much the only place it should be used.

MrMoo
Sep 14, 2000

ICC loves to give warnings on C++2003 and C89 errors even though C99 is selected.
code:
556: cannot assign to an entity of type "void *"
589: transfer of control bypasses initialization

MrMoo
Sep 14, 2000

Unfortunately no code, but not lacking on humor.

quote:

searching concurrent linked list; I don't want to make copies of the list. Too expensive. Mom pays for my hardware.

http://stackoverflow.com/questions/4178132/searching-concurrent-linked-list

MrMoo
Sep 14, 2000

Janin posted:

I'm honestly shocked that Perl runs at all on a EBCDIC platform

Perl is there to help convert EBCDIC to more sane encodings. It's surprising how much Perl is used on big expensive machines.

MrMoo
Sep 14, 2000

Randomly sticking in volatile modifiers for a single threaded piece of code with no external IO, nice. I think Drepper would have a nice chuckle.

MrMoo
Sep 14, 2000

pseudorandom name posted:

Slapping a volatile on those variables forces them to be stored to memory, which truncates the 80 bit x87 FPU representation down to 64-bits,

Or rather any operation on the volatile double causes the x87 register to be copied to a x86 register causing the down conversion, without the volatile the intermediate values can be kept in the x87?

MrMoo
Sep 14, 2000

pseudorandom name posted:

Nope, volatile requires memory, not integer registers.

But it isn't forcing software x87 emulation, so its copy from x87 registers to main memory and back to x87 registers for each op?

MrMoo
Sep 14, 2000

Edison was a dick posted:

I don't understand your point. ANSI C is not C99 and while C99 is becoming the standard, ANSI C is portable to compilers that don't support C99, so if you program for portability it is beneficial to pick the standard with the most compiler support.

C99 is ANSI C, along with C90 and C89. What am I missing?

http://en.wikipedia.org/wiki/ANSI_C


Similar pedant post of the day on Stackoverflow, "UTF-8 isn't guaranteed by the C++ standard so you shouldn't use it":

http://stackoverflow.com/questions/4766301/windows-console-and-qt-unicode-text/4769080#4769080

I deliberately use UTF-8 to gently caress over stupid MSVC users, I have no problem in MSVC 2010, OS X, Solaris or Red Hat. Just because Windows likes UCS2-LE internally doesn't mean you have to use it anywhere else.

MrMoo fucked around with this message at 15:08 on Jan 24, 2011

MrMoo
Sep 14, 2000

Well I wouldn't jump to thinking C89 either.

MrMoo
Sep 14, 2000

I like that, "Obviously".

MrMoo
Sep 14, 2000

Thankfully inline assembler is no longer supported with Win64.

MrMoo
Sep 14, 2000

nielsm posted:

MSVC for 64 bit doesn't allow inline assembly. You can still have assembly source files and call functions written entirely in assembly.

Yup. I have some assembler for ticket based spinlocks that requires 8-bit and 16-bit atomic ops, but Win API only provides one 32-bit aligned 16-bit atomic op and everything else is 32-bit or 64-bit. The limiting factor seems support of IA64 which does not permit such short aligned operations.

I tried using external MASM64 only to find that the supported syntax can be very different to MASM, i.e. MASM64 is like a version 1.0 and MASM32 is a version 8.0 with a lot more features. If you trawl the MSDN forums you can find tidbits from the developers.

I ended up bumping the locks up to 32-bit and 64-bit ops for Win64 as the intrinsic operations end up faster than function calls.

MrMoo
Sep 14, 2000

SavageMessiah posted:

http://www.infoq.com/presentations/Development-at-Google

Not really that great of a talk but goddamn that poo poo is insane. All of google's code is in one repo! I wish I had the time to improve our little 20 dev HG based system.

Isn't Apache similar? I seem to recall massive numbers browsing one project.

HTTPD is at 1134699, http://svn.apache.org/repos/asf/httpd/

MrMoo
Sep 14, 2000

shrughes posted:

That's still terrible, the code is hard to read with the type name so far from the variable.

lol, it's when you have to add restrict it gets even more entertaining.

code:
int *
do_the_evocollection
(
	                     int                     count_of_things,
	                   float          * restrict epsilon_ranges,
	              const char   *const * restrict format_ids,
struct SOME_LONGEISH_STRUCT_NAME          * restrict why_not_some_structs_as_well
)
{
	...
}

MrMoo
Sep 14, 2000

Not lined up hints at different tab size, if it was stackoverflow, inane disinterest in effort is quite popular.

MrMoo
Sep 14, 2000

TasteMyHouse posted:

I was mostly upset about (condition)?true:false;

You end up with a lot of code like that when writing 64-bit code and getting it to work on 32-bit platforms. A 64-bit non-zero integer evaluates as false on IA32 due to automagic promotion to a 32-bit integer.

MrMoo
Sep 14, 2000

Internet Janitor posted:

-Use a programming language meant for data processing. R, for example, can easily deal with millions of rows of data in a fraction the time and space Excel would require.

There are a few solutions that provide an Excel like interface around large scale data processing. FORA springs to mind:

http://broadstreetanalytics.com/spreadsheet.html

Thomson Reuters have one too but I don't know much about it's integration potential currently. I'm starting a new job on Monday which I think is about doing this, so :v:

MrMoo
Sep 14, 2000

I've just been picking up a couple of new APIs at work (Thomson Reuters) and it's utterly depressing. C++ code written by poor C developers that skip all the basics, code copy and pasted from many other projects and not even bothering to change introduction text or pre-processor guards. Today I'm looking at C code that is conversely written by poor C++ Windows developers showing no basic understanding of C coding and loving up everything.

Who the gently caress puts static prototypes in public headers? Unfortunately this isn't them:

http://stackoverflow.com/questions/7912863/is-there-a-way-to-have-static-prototypes-and-public-ones-in-the-same-header-file

Apparently the C++ API is cleaned up a bit, they were previously adding "using namespace" inside public headers. The private headers in each example still does it though, and the C APIs certainly don't care about polluting namespace everywhere.

What gets me is a "lean high performance" API has examples comprising 20 headers and 20 C++ files for sending demo values and performing absolutely zero processing on the content.

Comedy note that a new "ultra performance" API uses select on Windows and this is an API designed and built on Windows and then ported to Solaris and Linux taking really crufty Windows API clones for i18n, configuration files and other services.

MrMoo
Sep 14, 2000

Using Java to integrate between PHP and COBOL, fricking awesome.

Adbot
ADBOT LOVES YOU

MrMoo
Sep 14, 2000

I thought they would have gone with Vala if anything. Good to know alternative languages are always being investigated though.

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