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
ToxicFrog
Apr 26, 2008


ehnus posted:

Encountered today:

code:
public:
//private:
It's not as elaborately and stupid as most of these other coding horrors but it still makes me wonder what the intent was, why this was done, and can I change it back without breaking people who may be depending on these private members now being public.

If this were any other thread, I would say "check the version control logs".

Adbot
ADBOT LOVES YOU

ToxicFrog
Apr 26, 2008


qntm posted:

Today I discovered that FTP has no capability to "get" a complete directory and all of its subdirectories.

This isn't really a coding horror, it's more of an absence-of-coding horror.

This isn't a horror at all. As others have pointed out, the protocol has everything you need to easily implement recursive transfers, and any decent ftp client - nsftp, lftp, filezilla, wget, etc - supports them.

The real horror is that the plain 'ftp' command that most operating systems ship with hasn't been updated since the early 80s.

ToxicFrog
Apr 26, 2008


qntm posted:

Yeah, it's the ftp command that I'm complaining about, not the protocol itself. If it's so easy to implement clever recursive transfers on top of ftp, why hasn't it been done and incorporated into ftp?

It kind of has.

ToxicFrog
Apr 26, 2008


^ Typically you have some function for "convert this string to a number, and report failure in some way if the string cannot be parsed as a number". You might also have something like C's strtol() ("convert the leading portion of this string to a number, report both the resulting number (if any) and how much of the string is left afterwards").

In your case of "I have a string, there's a 100 in there somewhere, how do I get at" I see this as being either of the following:
- input was meant to be a number, is actually a string. Input is invalid and bitching about it is the correct approach.
- input is meant to be a string with a number in it somewhere. Use your favorite string processing tools (regexes, PEGs, parser combinators, etc) to extract the numeric portion from it and then feed that to the abovementioned function. (Or use your local strtol() equivalent, if you know the number is at the start.)

Note that even in the case of a best-effort numeric parser like strtol(), this is an explicit "I want the contents of this string interpreted as a number", not "hey let's silently and automatically convert this string here".

Coercion is the real horror.

ToxicFrog
Apr 26, 2008


McGlockenshire posted:

These are very good points.

But... if my language of choice raised an exception when I passed it contaminated data rather than make a best effort to clean it up, I don't think I'd prefer that language for much longer.

Why should the language do this automatically, though? Yeah, it should include tools for doing this, but I'd prefer not to have it try to guess what I meant, especially when this can hide type mismatches that are genuine bugs rather than just unclean input.

Not to mention that even coercion doesn't save you from having to write error handling, unless "gently caress you not a number" coerces to 0 in a numeric context.

I guess if I had to sum up my point here, it's that cleaning up bad input is a highly program-dependent process and thus should be handled by the programmer; trying to add language features to do this means the language will guess wrong sometimes, and furthermore, complicates parts of the program that have nothing to do with cleaning up input but which trigger these features anyways.

Otto Skorzeny posted:

4 == "4"

See, I consider that "badly done coercion". (4 + "4" == 8) is acceptable, but 4 and "4" are different types, they should never compare equal unless you're doing an explicit conversion or redefining equality.

Edit:

McGlockenshire posted:

Look, all I'm saying is that sometimes, being "sloppy" can be acceptable if the result of the sloppyness isn't harmful in the worst case. If all I need is an int, and I don't care what the user typed after it, I'm gonna cast it and spend my time fixing other problems instead. I'd rather not have my programming language make that decision for me.

But with implicit coercion it is making that decision for you, and the decision is always "be sloppy". Without coercion, it's in your hands what it does - treat type mismatches as errors, convert strictly, or convert laxly (or do something else entirely I haven't thought of). And the fact that you're talking about casting it (which implies an explicit conversion) seems to indicate that you're thinking along similar lines.

If your language lacks coercion, you can still get the desired sloppiness by using strtol() or tonumber() or whatever on your input before making use of it. But if it has coercion and you don't want it to be sloppy, you're hosed - or at least, you need a lot more extensive manual type checking and error handling.

ToxicFrog fucked around with this message at 08:16 on Sep 27, 2010

ToxicFrog
Apr 26, 2008


Otto Skorzeny posted:

There's a semantic spat to be had here about whether scalar variables in Perl have types and whether perl's concept of SV's and PV's constitute datatypes, but I'll instead say that you probably also have a bone to pick with ANSI C's handling of equality between ints and floats:

I'm not as mussed about it in statically typed languages, because then the type checker can ensure that (a) the coercion will never fail at runtime and (b) no information is lost - in the case of C, for example, short int == long int will upcast the lhs to a long int, int == float will upcast it to a float, and int == char * is an error (or at least a warning). In a dynamically typed language no such guarantees can be made, so the possibility exists for something that works most of the time, but fails on certain input as the coercion fails at runtime - or something that works all of the time even when it should fail and report invalid input.

RankWeis posted:

Yeah, unfortunately, I was posting from my iPad so google and a terminal were too complicated to actually test anything out. But I recall that languages that do this type of comparison usually have a 'strict' comparison to go along with it, and I thought python was one of them

Most dynamically typed languages are nonetheless strongly typed and, consequently, tend not to pull this. It mostly seems to be a feature of weakly typed languages like Perl or TCL.

It may come as no surprise that my preference is for strongly+statically typed languages. :)

ToxicFrog
Apr 26, 2008


So wait, is it calling Number() on something that's already numeric? Or are they not only using systems hungarian, but lying about the type?

ToxicFrog
Apr 26, 2008


Lysandus posted:

RIMs bastard java they put on Blackberrys.

:argh:

That whole thing is a coding horror.

My favorite part was probably finding out that in a multithreaded app, blocking the UI thread would block the entire application, including the background thread that pings the robot every 50ms to keep it from going into full reverse and destroying something.

Although, to be fair, the robot was around 4-5 horrors on its own. That entire project was a clusterfuck.

ToxicFrog
Apr 26, 2008


^^ I haven't run it, but from a cursory reading it looks like it should work; here's an annotated version.

code:
// trim leading and trailing whitespace from a string
Stuff.rtrim = function(s) {
  s = s.replace(/^\s+/, ''); // trim leading whitespace
  for (var i = s.length - 1; i >= 0; i--) { // scan backwards through the string
    if (/\S/.test(s.charAt(i))) { // as soon as you hit a non-whitespace character...
      s = s.substring(0, i + 1); // slice off the rest of the string and break
      break;
    }
  }
  return s;
}
Granted, I'm not sure why you would do it this way when you can replace it with:
code:
function(s) { return s.replace(/^\s+/, '').replace(/\s+$/, '') }

ToxicFrog
Apr 26, 2008


Argue posted:

:gonk:

Is this something that worked at some point in the past? Say, back in the day there was only one worker thread, and the socket pool was actually a queue, and then one day they decided to add more worker threads without paying attention to how sockets were matched up with requests?

Or has it been broken since day one?

ToxicFrog
Apr 26, 2008


^ Weird, it supports ! and everything in unicode I've thrown at it.

ToxicFrog
Apr 26, 2008


E: hey new page let's get that quote tag in there

yaoi prophet posted:

Tumblr lets users reblog/like posts they see on their dashboard. When you look at an individual post, it also shows you the last 50 or so 'notes' (reblogs, likes, and replies) on that post, not only by that user, but by all people who reblogged that post. Pretty interesting, right? Sounds like the sort of data you might want to visualize if you're into that sort of thing.

Well, you can't. There's no way, API or scraping, to get all the notes; you have to manually do XmlHttpRequests. And even then you can't get all of them because it likes repeating notes and at some point it gives you the same set of 50 over and over again. Fortunately, you can detect this because it gives you the same XHR url, but still. Ugh.

^^ At least you can use XHR rather than having to scrape the page and then extract the info you need from from only-mostly-valid HTML 4.something.

I would kill for a stand-alone library that takes arbitrarily hosed up HTML as input and gives you its best guess at the DOM, rather than the current choice between "only support XHTML/XML" and "shoot yourself".

evensevenone posted:

Is there anyone in the world who upon seeing the words "ANSI C" would think "C99"?

Personally, I'd reply with "do you mean ANSI C89 or ANSI C99" unless it was obvious from context.

ToxicFrog
Apr 26, 2008


Zombywuf posted:

libxml2, also you know, webkit and even mshtml.

dark_panda posted:

libtidy might help, too.

Well, I've just been schooled. :downs: Tidy looks ideal, it's nice and lightweight (I don't need a full XML parser, let alone a rendering engine) and has bindings to both Scala and Lua. This'll definitely come in handy. Thanks.

(HTMLAgilityPack looks nice too, but the .NET dependency is a problem.)

ToxicFrog
Apr 26, 2008


Scaevolus posted:

It looks like the Blackberry JVM is really bad

Speaking as someone who's had the misfortune to do Blackberry development - yes, the Blackberry JVM and runtime libraries all belong in this thread. gently caress RIM, and gently caress the Blackberry.

Ryouga Inverse posted:

No. If blocks can have different behaviors based on their type then it's not really a horror to implement those behaviors in code. Where the code is stored isn't really of concern - if a game designer wanted to create a new block type with its own custom behaviors they'd have to write code no matter what. Implementing something that lets you write the code in a language other than Java is a ton of work for no gain.

Untrue. If that were the case, languages like Lua wouldn't be showing up all over the place. Pulling this sort of game logic (as opposed to engine logic) into external scripts has a number of benefits, including making it a shitload easier to mod, and making development easier because you no longer have to recompile the entire game every time to change something - just "/reload" from in game and your changes are ready to be tested.

This also means you can make your game crazy moddable without exposing the guts of the engine to everyone, although in Minecraft's case specifically the obfuscation used is so pitiful that it hardly matters.

It's not "a ton of work" either; if you're using something like Lua, there are seamless or nearly-so Java APIs to it. It's trivial if the engine is designed with this in mind from day one, and even retrofitting it in isn't very hard.

ToxicFrog
Apr 26, 2008


^^ I don't disagree, but where zootm's argument goes off the rails in the assumption that any use of external scripting or configuration falls into this category. The experience of Adobe, Blizzard, Gas Powered Games, Firaxis, and Relic directly contradicts this, and shows that such an architecture has very real benefits.

ToxicFrog
Apr 26, 2008


Who the gently caress uses floats to store monetary amounts :psyduck:

ToxicFrog
Apr 26, 2008


^^ Why is that? Shouldn't only one F be created, and thus, only one destroyed?

ToxicFrog
Apr 26, 2008


BonzoESC posted:

List appends aren't in place in python, are they?

Depends on how you append.

code:
# + does not modify the original list
>>> a = [1,2,3]
>>> a + [4]
[1, 2, 3, 4]
>>> a
[1, 2, 3]

# .append does
>>> a.append(4)
>>> a
[1, 2, 3, 4]
>>> a
[1, 2, 3, 4]

# += does in addition to performing assignment
>>> b = a
>>> b += [5]
>>> b
[1, 2, 3, 4, 5]
>>> a
[1, 2, 3, 4, 5]
AzraelNewtype is correct with respect to what's actually happening; a[0] += [5] first updates a[0] in place (which succeeds, because while a is immutable, a[0] is not); then it tries to (redundantly) assign the updated list to a[0], and fails. Since the first step succeeds, you get both an updated list and an error.

The horror here, if there is one, is that + doesn't update the list in place but += does (as well as performing assignment).

ToxicFrog fucked around with this message at 23:15 on Mar 28, 2011

ToxicFrog
Apr 26, 2008


^^ Pretty much this.

UraniumAnchor posted:

Why *would* + update it in place? + shouldn't modify either of its operands.

I agree. I was ambiguous there; I meant that given that + doesn't modify either operand (nor should it), it's surprising that += does (in addition to assigning).

ToxicFrog
Apr 26, 2008


Lexical Unit posted:

:gonk:

This wouldn't be a problem if you used SI to begin with like all right-thinking people do. :colbert:

Seriously though, I'm so sorry.

ToxicFrog
Apr 26, 2008


Zombywuf posted:

Yeah, it's not like I spend half my time trying to get program A to talk to program B using protocol C, which they both claim to support, but actually implement differently (and incorrectly) in both cases.

Fixed that for you. :suicide:

ToxicFrog
Apr 26, 2008


Am I missing something, or could that whole thing be replaced with:

code:
public static String readUrl(String urlString) {
  return urlString;
}
Since all it does is copy urlString line-by-line and then return the copy, and since Java strings are immutable making a copy is pointless?

ToxicFrog
Apr 26, 2008


GreatKesh posted:

It's not actual code but rather a language and the fact I have to use it to pass this class

For my programming class we have to spend most of a year doing gml (Game Maker Language) because 90% of the dickwits in my class have never done any programming before and get bored with other languages such as delphi "coz you can't make games with them"

Someone should educate them.

(Comedy option: start them on Inform 7 so that they can complain it's not real programming because it doesn't use {} to delimit code blocks.)

(Cruelty option: start them on C++ with OpenGL so that they no longer want to make games, learn how to program, or live.)

ToxicFrog
Apr 26, 2008


Internet Janitor posted:

ToxicFrog: I was very disappointed that none of those links involved Delphi. Apparently you can write games with it: http://delphigamedev.com/ :v:

I figured you probably could, but I don't know Delphi or any of its libraries, so I stuck to what I know.

ToxicFrog
Apr 26, 2008


^^ Or should, anyways. Here we start students off on C because there's no money in the budget for the co-op and non-co-op students to take different courses in first year, and there's apparently no demand in the industry for anything but C and Java. :smithicide:

I see a lot of students in second year who can program in C badly but who can't really program - they get so bogged down in the overhead of learning C that they don't really learn any of the underlying concepts. There were similar issues when they started with Java.

A lot of the profs would rather move first year to Python, but it's never going to happen as long as the people running the co-op program have their heads up their arses.

ToxicFrog fucked around with this message at 16:25 on May 20, 2011

ToxicFrog
Apr 26, 2008


Zombywuf posted:

The overhead of learning C, or the overhead of complex memory management that was taught to them before they were finished learning for loops?

GrumpyDoctor beat me to it. C has a lot of up-front complexity compared to Scheme, Lua, or even Python, and is a lot harder to experiment with - even before you start talking about memory management. This is fine if you already have the fundamentals down, but if you're going into a first-year programming course, you probably don't.

The result of this is that the language gets in the way of the learning; you end up with a lot of people who know how to cobble together a program in C by regurgitating individual fragments of code, but don't actually understand what they're doing because they had to spend the entire semester learning C rather than learning how to program.

ToxicFrog
Apr 26, 2008


I'm fond of "exception thrown without stack frame" myself. :wtc:

ToxicFrog
Apr 26, 2008


This is compounded by the fact that most academics that aren't in CS or something closely related have little experience and no formal training in programming. So they learn just enough fortran/C/python to make something that works (or adapt existing code into something that works), get the results, and move on.

In the parallel programming class that I TA, we often see researchers from other disciplines (physics and biology in particular) who are hoping to learn enough to parallelize their takes-days-to-run software and get some significant improvements. In most cases, they lack the fundamentals that are necessary to understand the course material; the rest often decide to just stick with what they have rather than completely redesigning the program (which is often what would be necessary).

ToxicFrog
Apr 26, 2008


Room Temperature posted:

Your way:

Better way:

Vim's auto-indenting:

This poo poo right here is why I use spaces everywhere, despite agreeing in principle with "indent with tabs, align with spaces"; I have never used an editor that doesn't gently caress up in this manner as soon as you start actually aligning things.

ToxicFrog
Apr 26, 2008


Che Delilas posted:

Never knew this (not that I ever used the language), but that quote is a pretty reasonable conclusion if you don't know, is it not? Especially if you don't speak Portuguese.

I guess, except that in all of the documentation, websites that discuss it, etc it's written "Lua" and not "LUA".

ToxicFrog
Apr 26, 2008


baquerd posted:

I bet it's redrawing the entire image every frame but the GIF animation definition allows for frame difference updates so the actual file size is small enough to be an avatar but there are a ton more frames than most GIFs.

That still doesn't explain why it would murder performance in IE9 when it works just fine in every other browser on earth, though.

ToxicFrog
Apr 26, 2008


yaoi prophet posted:

Have you ever wanted to fit your executable inside the ELF header?

ELF origami.

I love it.

ToxicFrog
Apr 26, 2008


Jabor posted:

It's like they deliberately took the worst parts of Javascript as well - automatic semicolon insertion? Seriously?

Is there a significant difference between "automatic semicolon insertion" and "optional semicolons"? I can't see one, but the former seems to be reviled whereas most people seem to either not care about the latter or consider it a good thing.

ToxicFrog
Apr 26, 2008


Oh. So "automatic semicolon insertion" is "a semicolon is inserted at each newline if one is not already present".

:gonk:

ToxicFrog
Apr 26, 2008


Meanwhile, RIM (at least, according to a friend who works there) doesn't have test code at all, at least for BBOS. :gonk:

Instead, they have ~2000 QA workers tasked with testing each new build by manually going down a checklist and interacting with the blackberry.

They estimate this gives them about 30% code coverage.

Granted, "my friend who works at RIM" isn't exactly a citable source, but given what an incredible shitheap Blackberry Java is, I can believe it.

ToxicFrog
Apr 26, 2008


SavageMessiah posted:

It seems like the more someone is concerned about random people stealing their code, the shittier it is.

Now that I think about it, that kind of makes sense.

If you're good, you can write simple stuff like that easily, and you know that other good programmers can as well, which means there's no reason to keep it secret.

If you aren't, it's a terrible ordeal to get it written and even once you're done it only just barely works. But since they think they're good, that means it must have been a really loving hard problem they just solved! Which means a solution for it must be valuable in some way, and they should protect it.

ToxicFrog
Apr 26, 2008


SlightlyMadman posted:

To make this better, be sure you call that function in other parts of the code to determine the units age for completely unrelated reasons, and then later end up changing the warranty eligibility to be based on something completely different, but retain the original function name.

$5 says that's already happened and he just hasn't realized it yet. :ohdear:

ToxicFrog
Apr 26, 2008


TasteMyHouse posted:

e2: ah, GNU strchr always returns a char *, not a const char *. is this standard? Now I don't know who to trust

POSIX and the C99 standard both specify that strchr has signature char * strchr(const char *, int). So GNU strchr is conformant in this case.

ToxicFrog
Apr 26, 2008


Plorkyeran posted:

Grading is awesome because you get to punish people for writing terrible code rather than having to just sigh and put up with it.

Grading is terrible, because you realize that of the 20 people registered for the course, only 16 bothered to commit a solution at all.

And of those 16, only one implemented the spec correctly. Over half, on the other hand, submitted something that does not actually run (except in the most charitable sense that "the OS successfully loads the executable").

And all of these are third-year students who have somehow passed several programming courses.

:suicide:

(My favorite failure mode was the two programs that are somehow written in such a way that only absolute paths work on the command line. How is that even possible? It's harder to do it that way than to accept both absolute and relative paths!

I say "was" because today it was superseded by the program that doesn't check how many nodes are available, and instead starts by assuming it can only create 1 process and then doing some math that results in it trying to create -1 processes and crashing.)

Adbot
ADBOT LOVES YOU

ToxicFrog
Apr 26, 2008


baquerd posted:

This is only a problem when you have academic/political pressure to pass a certain percentage.

We don't. And I didn't say it was a problem.

It's just drat depressing. :sigh: Are they that clueless? If so, how did they pass the previous courses? Do they just not care? If so, why did they sign up for this course?

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