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
Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

But we're talking about languages, independent of any real-life machines. It's what the grammar can express that we're interested in, and not technicalities like sizeof(void*) or memory addressibility.

Adbot
ADBOT LOVES YOU

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

Munkeymon posted:

Wouldn't a pass-by-reference system be the best generic way to do it in Perl if you want people to be able to, say, sort an array of arrays by the lengths of the constituent arrays?

Honest question - I'm not a Perl expert, I just tinker with it occasionally.
Indeed, you need to pass by reference, but in your example (unless I'm misunderstanding your question) there's no need to allow the dereferenced array to be modifiable.


code:
$ cat foo.pl 
#!/bin/perl

my @array = ( [1, 32, 21], [4], [492, 39, 192, 10, 2], [2, 92], [0, 1, 32, 31] );

map { print "@$_\n"} sort { scalar(@$a) <=> scalar(@$b)} @array;


$ perl foo.pl 
4
2 92
1 32 21
0 1 32 31
492 39 192 10 2
Personally I think the better solution would just be to enforce some sort of const correctness on the sorted list, or at the very least issue a warning when it's being modified.

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

That pleb coder, he neglects the case where p_destination is both not equal to zero and not not equal to zero :pseudo:

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

BigRedDot posted:

So I don't work for Lockheed Martin, but I have to work with Lockheed Martin. Let me summarize their approach to testing/debugging:
Remind me to never get into a plane again :gonk:

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

Even though obfuscated code is arguably not an intentional coding horror, I was reminded of this hilarious rock-paper-scissors bot from my AI class a few years back:

code:
/*  Entrant:  Psychic Friends Network   Michael Schatz et al (USA)
              (Unofficial Super-Modified Class, i.e. it cheats)

 note: may cause a Segmentation Fault vs MegaHAL (error: "OUCH")

 > The Psychic Friends Network is a truly hilarious piece of obfuscated C,
 > written by Michael Schatz and company at RST Corporation.  Among other
 > things, it uses an auxiliary function to find good karma, consults
 > horoscopes, cooks spaghetti and (mystic) pizza to go with various kinds
 > of fruit, #defines democrats as communists, and undefines god.  We're
 > still trying to figure out exactly what it is doing with the stack
 > frame, but we do know that it never scores less than +998 in a match,
 > unless it is playing against a meta-meta-cheater.
 To give credit, where credit was due:  Frank Hill and T.J. Walls
 (also of Reliable Software Technologies) were the other minds behind
 Psychic Friends Network.  To see some of their other exploits check out:
 [url]http://www.rstcorp.com/news/gambling.html[/url]
*/
code:
#define RST_ULTIMATE_ANALYZER_FUNCTION rst_ultimate_analyzer_function
#define GOD %
#define democrats communists
/* The open brace was always overrated anyway. */
#define recycle return

/* more readable */
#define THEFUNCTIONSTARTS {
#define THEIFSTARTS {
#define THELOOPSTARTS {
#define spaghetti RST_ULTIMATE_ANALYZER_FUNCTION
#define fresh (
#define rotten (unsigned
#define bananas int)
#define grapes bananas
#define sake 3
#define be_good_for random()

char *find_goodkarma(int *arr) THEFUNCTIONSTARTS
    int turn = arr[0], * karma[50], eleven = 0;
    int magic_bacon;

    *karma = &turn;
    while (!eleven) THELOOPSTARTS

        /* We need to determine the karma rating of the magic bacon. */
        /* This depends highly on the number eleven. */
        for (magic_bacon = 0; magic_bacon < turn; magic_bacon++) THELOOPSTARTS
            eleven = 1;
            if ( (*(*karma + magic_bacon)) != arr[magic_bacon] ) THEIFSTARTS
                eleven = 0;
                break;
            }
        }

        /* why does everyone put their comments at the end of the line? */
        /* is it eleven yet? */             if (eleven) break;
        /* determine karma ratio */         (0[karma]) += (fresh bananas * karma / fresh grapes * karma );
    }

    /* return the . . . whatever the heck this is. */    recycle (char *)*karma;
}

int RST_ULTIMATE_ANALYZER_FUNCTION() THEFUNCTIONSTARTS
    int turn [1];
    int *good_hand, *bad_hand, *pizza;
    int cancer, scorpio, libra;
    /* x is actually my all time favorite variable */     int x;
    int i, democrats;
    int (*callback) () = spaghetti;

    (*&cancer) = (scorpio = (libra = (int)NULL));
        *turn = opp_history[0];

        if (*turn < trials - 2) return libra ? callback() : be_good_for GOD sake;

    /* Consult appropriate astrological signs in order to determine exactly */
    /* which hand to throw. */
    good_hand = (int *)find_goodkarma(my_history);
    bad_hand = (int *)find_goodkarma(opp_history);

    if( cancer == 1 ) return *(int *)"ROCK";
    if( scorpio == 1 ) return *(int *)"SCISSORS";
    if( !(( scorpio != 0 ) || (cancer != 1)) || !((cancer != 0) ||
           (scorpio!=1)) ) return *(int *)"PAPER";
    if( ((  scorpio == 0 ) && (cancer == 1)) || ((cancer == 0) &&
           (scorpio==1)) ) return *(int *)"FONZ";

    /* Process Good Karma Values */
    for (i = 1; i<=*turn; i++) THELOOPSTARTS
        if (good_hand[i] == bad_hand[i]) libra++;
        else if ( ((good_hand[i] - bad_hand[i] +3) GOD sake) == 1) cancer++;
        else scorpio++;

        good_hand[i] = (bad_hand[i] + 1) GOD sake;
    }

    if (bad_hand > good_hand) THEIFSTARTS
        i = cancer;
        cancer = scorpio;
        scorpio = i;
        democrats = 2;
    }
    else democrats = 1;

    pizza = turn;
    for ( x = 0; !( (pizza[0] == libra) &&
        (pizza[1] == scorpio) &&
        (pizza[2] == cancer) ); x++ ) pizza++;

    pizza[0] = 0;
    pizza[1] = 0;
    pizza[2] = 0;
    pizza[3-democrats] = cancer + scorpio + libra;
    democrats = 0;

    recycle (pizza[democrats] + rotten bananas good_hand) GOD sake;
}

# undef GOD
/* Is that possible? */
#undef democrats
#undef recycle
#undef THEFUNCTIONSTARTS
#undef THEIFSTARTS
#undef THELOOPSTARTS
#undef spaghetti
#undef fresh
#undef rotten
#undef bananas
#undef grapes

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

To say nothing of that ridiculous switch statement could be removed (edit: or at least simplified) if the author had known about fls()

Dijkstracula fucked around with this message at 21:03 on Jul 7, 2009

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

Otto Skorzeny posted:

Did he specify he was on a BSD? ffs(3) and its extensions are in POSIX.1-2001, but fls(3) and friends are BSD-specific from what I can tell.

e: more than BSD-specific, fls(3) first appeared in FreeBSD 5.3 circa November 2004
Ah, interesting, good to know that it's not portable, since I use those functions every now and then (but is pretty trivial to implement oneself). I just checked the man page on OSX and assumed it would be present everywhere.

edit: :smug::respek::v:

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

the dd and sed one is the only amusing "win" on that page; all the others are just spamming anonymous functions.

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

That piece of code is incredible. At first glance it only looks moderately silly, but the more I stare at it, the more hidden horrors reveal themselves, like the blossoming of an enormous carrion flower. :gonk:

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

so this xkcd is an internet comic strip, you say

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

Lexical Unit posted:

Haha, same file:
code:
#define SIN(x) (sin((x)*M_PI/180))
Note that SIN() is only ever called once in the file, and it's never #undefed.
Well, given it's wrong, I should hope it's not used very often!

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

Otto Skorzeny posted:

Yeah, on a second look I read the parens wrong
Christ, so did I. :suicide: Shouldn't try to post smarmy comments before my third cup of coffee of the day.

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

Avenging Dentist posted:

For people who think that ants are a silly or irrelevant species, they're not. There are literally 142857 times as many ants in the world than there are humans.
I've seen about 20 sci-fi movies from the 1950s that lend significant weight to this statement :tinfoil:

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

floWenoL posted:

(I still can't decide whether you're trolling or not.)
There's no way he couldn't be.

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

I admit I can't even imagine why an implementation of TSP (or, even any of its variants - bitonic TSP, euclidean TSP, etc) would take anywhere near 3000 lines :gonk:

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

quote:

I've been lucky to be ahead of the curve since I got into this whole social media thing early. Yay me!
I already hate this thread. There's no way it can go downhi--oh jesus :suicide:



quadreb posted:

"Moved on"? Regular expressions are an integral part of modern business programming.
s/business//

Also, regular expressions in Java are so terribly loving broken, I don't know if there's any correlation between them and "business programming".

edit: Also also, regexes aren't hard to understand, and if you think they are then you are dumb

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

BigRedDot posted:

I work on sonar systems for submarines, I can say confidently that regular expressions are not at all an integral part of the programming we do.
The military as a business? :911: :v:

edit: But seriously, folks. It might not be used in every single program that you write, but people can't deny that its only use is to tabulate reports or whatever. String matching is important and common. :)


edit 2: TSDK, would you also say that people should only be allowed near a context-free language if they can distinguish it from a context-sensitive language, and prove it using the equivilent context-free pumping lemma?

Dijkstracula fucked around with this message at 18:36 on Aug 1, 2009

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

TSDK posted:

Okay, so the regex was a bit of a light troll on my part (especially the pumping lemma proof), but DFAs aren't exactly difficult. I would expect any decent programmer to be able to grasp the fundamentals without too much trouble.
The thing is, though, that I agree with you that people ought to know about language theory since a) it's important, and b) it's interesting, but for 99% of working programmers (maybe this is what people mean by "business programmers"), understanding the rough idea ("This returns true/false if the input matches against this expression") and the syntax is enough.

Also, as Flobbster said, regular expressions in practice aren't DFAs anyway. Perl's maximal matching via backtracking behaves more like an NFA, and the moment you start dealing with ERA stuff like backreferences, you've thrown yourself out of the regular world altogether. Given that, does it really make sense for every person to read the first fifty pages of Sipser or Aho/Hopcroft anyway?

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

enki42 posted:

Stuff like language theory is probably important for an architect, but if a dev is told they are going to be using a regular expression, it's nowhere near a necessity.
I agree, but I would temper this statement a bit to say that it's important that the person have some sense of what a regular expression can "do" (that is, to have an understanding of the limits of the tool that they use). I'm not saying that they need to know how to knock off proofs using the Pumping Lemma by heart at all, but someone should have an intuition that tells them that you can't determine whether a string is a palendrome using a regular expression.

(I say this only because I know a guy who spent hours trying to write a regex to match something along the lines of "anbn", which is pretty much the canonical non-regular language.)

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

wolf_man posted:

for loops are better optimized and efficient then do whiles.
Granted, I don't know the first thing about PHP's internals, but I would be highly surprised if a do-while construct could be "optimized" (I'm thinking of things like loop invarients) any better than a plain for-loop. it's a conditional and jump, what's to optimize :confused:

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

necrobobsledder posted:

Maybe it was to compete for Fortran users or something?
Fortran's array indexing, barring specifying index ranges, isn't that different than C's. You certainly can't do i[a] in Fortran, so I don't know what you mean. :confused:

code:
  1         PROGRAM CODINGHORRORSTHREAD
  2 
  3         INTEGER A(100)
  4         A(1) = 12345
  5         1(A) = 42
  6         PRINT *, A(1)
  7         END

~$ gfortran -std=legacy foo.f
foo.f:5.9:

        1(A) = 42                                                       
        1
Error: Invalid character in name at (1) 

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

Avenging Dentist posted:

Guys, the a[i] / i[a] equivalence is just because the standard defines a[i] as being equivalent to *(a+i).
The thing is, though, this makes sense until you think about it for a bit and realize that it's not *(a+i), it's *(a + (i * sizeof(thetype))), so it's not commutative in that way unless the size of the type happens to be the size of the architecture's word.

Was this not the case back in the good old days? Were all data types 16 bits on the PDP-11 or something?

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

Avenging Dentist posted:

You may want to read up on your pointer arithmetic.

edit: ah, talked to #cobol - the compiler implicitly adds the stride based on sizeof(thetype). I got it now. :)


sizeof(float) = 4
(a + 0) = 0x7fff5fbff850
(a + 1) = 0x7fff5fbff854
(a + 2) = 0x7fff5fbff858
(a + 3) = 0x7fff5fbff85c
(a + 4) = 0x7fff5fbff860
sizeof(void) = 1
(b + 0) = 0x7fff5fbff850
(b + 1) = 0x7fff5fbff851
(b + 2) = 0x7fff5fbff852
(b + 3) = 0x7fff5fbff853
(b + 4) = 0x7fff5fbff854

Dijkstracula fucked around with this message at 08:15 on Sep 19, 2009

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

I believe we should be exploiting jump tables in a switch statement for maximum fastness :pseudo:

code:
switch (checkForInvalid().ToString().Length()) {
   case 5:
      isValid = true;
      break;
   case 4:
      isValid = false;
      break;
   default:
      throw new NonTrueOrFalseBooleanValueException();
}

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

Seriously, I'm pretty sure the Dragon text devoted an entire chapter to fending off mythical beasts or something :confused:

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

Or grep for it after running gcc -E and see if it's getting inserted into an unexpected place.

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

PT6A posted:

There are three parts to the assignment/series of assignments: simulate a hard disk (read_block, write_block, etc...) with and without cache (LRU cache replacement), then implement a basic (highly restricted) FAT filesystem, and then allow that basic filesystem to be accessed across a network. Other than correctness, there are no requirements (i.e. it can be as inefficient as you like). Given those constraints, I don't think it's unreasonable to expect 3rd-years to complete the assignments in C, given approximately a month to finish each stage.

Certainly, they shouldn't be disregarding the instructions entirely and using Python without explicit permission.
Boy you sure seem to care a lot about something that in no way affects you. If the assignment can be done in Java (which is as big a "systems language" as Python), there's really no reason to disallow Python.

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

MEAT TREAT posted:

Perhaps, but how is that a coding horror in any way?
whitespace syntax :xd:

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

HFX posted:

Usually, the best code comes from guys who regularly use functional or declarative languages.
This is entirely because functional and declarative languages are used entirely by hobbyists and Reddit circlejerkers who aren't writing production code.

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

Wow thank you so much for showing me this magic of "recursion"! This is indeed a beautiful thing that is unique to functional languages let me go grab GHC and convert all my code to monads :rolleyes: Like, really? That's your counterexample? You don't show off higher-order functions or lambdas and say "can your C do that? Look at what I can do with map and foldr!"

But, my entire complaint about functional programming acolytes (where my Reddit circlejerk comment came from) was actually this:

jandrese posted:

And of course because it's a functional language, it will only be natural to you if you're a mathematician and you would rather be writing proofs instead of code.
It's exactly this kind of smug wankery that drives me up the loving wall. The only thing I hate more than people who use their operating system to define themselves are people who use their programming language to define themselves.

Just for the record, I still do a lot of programming in functional languages, and it is indeed cool. (and, indeed, I'm TAing a freshman CS class this term that uses Scheme, and the average quality of code that I see in that class is far higher than what I saw in the other freshman Java class.) But you're loving kidding yourself if you try and correlate a language's "quality" with a self-serving "you must be this smart to enter" metric. And further, you can't compare the "average quality" of code of a language that isn't used in a production setting, with one that is. If Java wasn't used by every half-assed developer and his dog to slap together some lovely business app, then you too could probably look at the average piece of Java code and say, "yes, this is beautifully written."

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

It's a pretty common thing. I did a very similar assignment at the University of Alberta (the LRU cache simulation, but no file system simulation stuff)

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

It's interesting to see so many McGill CS types in here - COMP 202 was the class that inspired me to drop my music degree and go into CS :cool:


jandrese posted:

Way to miss the point. The example there was to show off the weirdness that is running pattern matches on your function calls, the recursion bit was just there because that's how Erlang works!
For somebody who claims Erlang has revolutionized his life and how he codes, you sure had a difficult time coming up with the syntax for writing a factorial function, about the simplest Erlang program there is, from memory. Maybe you were too busy writing proofs and being a mathematician to steal a solution off Google? (As you can probably tell, the "mathematican" comment of yours was the comment that ruffled my fur more than the condescending example "code")

This, actually, proves my point - so many people on the net proselytize the flavour-of-the-week functional language and yet so few have clearly actually used it for anything beyond copying the code examples out of Joe Armstrong's book.

Anyway.

To give a less snotty answer, no, I didn't miss the point. Yes, the pattern matching stuff in Erlang is very cool, but every single other person in this thread saw it with Prolog in their third year of uni, so we don't feel the need to extol the virtues of a programming paradigm that isn't news to us. It's the whole "to a carpenter with a new hammer, everything looks like a nail" maxim.

(additionally, most scheme implementations actually have compound datatypes, though IIRC it's not part of the language spec - in PLT Scheme, for instance, it's defined through the (make-struct ...) construct.)


edit:

Mustach posted:

a tokenizer and parser generator (leex and yecc).
:lol::lol:

Dijkstracula fucked around with this message at 20:55 on Nov 29, 2009

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

jandrese posted:

What are you talking about? Have you confused me with someone else?
pretty sure I haven't :confused:

quote:

In Pseudocode because I can't remember the wacky syntax:

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

Mustach posted:

Is this a "lol they suck?"
No, no,. the names of the lexer and parser amused me, is all :)

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

yaoi prophet posted:



I can't wait to use the 'seeking feed fwd', the 'anonymous role mixin', and the 'hyper dwim all'!
I actually had a copy of this printed on my university's large-scale printer and am partially ironically hanging on my wall :colbert:

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

dis astranagant posted:

No one sane uses an integer for radians.
sure, if you care enough about accuracy to get within 25 degrees of the correct answer, then go right ahead and use those extravagant floating point operations :rolleye:

#define 2PI 6

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!


quote:

If you're using Linux, it's something a lot like that. If you're using Windows, go f*ck yourself.
what a superburn, such sublime ownage coming out of Atwood in that post :rolleye:

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

Panic! at the Fist Jab posted:

you're a retard, he was quoting jwz, who *does* unequivocally own
:suicide: So noted, though indeed, jwz's anti-M$$$ cheapshots do tend to grate on me, too.

It's not like it takes any special skill to come up with something like that.

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

Yakattak posted:

That's fairly reasonable as long as it's in a loop, as you rarely ever need to know what that variable is, usually because it's scope is only within the loop. I don't use i however, I use count, because I seem to always miss i when reading code.
What do you do when you have to use a nested loop?

(please don't say "count2" :v: )

Adbot
ADBOT LOVES YOU

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

holy crap, this guy is evidentially a legend http://thestupidestmanonearth.com/

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