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
Jabor
Jul 16, 2010

#1 Loser at SpaceChem

Crazy RRRussian posted:

Acronyms in variable/function/class names piss me off too. I would rather have verbose names that are very descriptive than have to remember particular shortening of it. Although there is something to be said about long names that are still loving confusing and too long.

It really depends on the acronym, TBH. Certainly, I would hate to see a HyperTextMarkupLanguageParser class.

Adbot
ADBOT LOVES YOU

Jabor
Jul 16, 2010

#1 Loser at SpaceChem
Man, every time I look at that code, I see something new that's wrong with it :psypop:

Jabor
Jul 16, 2010

#1 Loser at SpaceChem

king_kilr posted:

If you think that's a coding horror, your codebase is probably ok. I can think of a totally valid reason for that. The Color class isn't under your control and features general color management things, for your app you want to have a consistant UI, and you're starting with their definitions of what constitutes DARK GREEN, but that might be changed in the future.

No, actually, it makes about as much sense as:

code:
public static final int SEVEN = 7;
If it were as you suggest, it should be named:

code:
public static final int COLOR_UI_PRIMARY = Color.DARKGREEN
(or similar)

Jabor
Jul 16, 2010

#1 Loser at SpaceChem

Janin posted:

it's a lot easier for some picky boss to say "can you make the buttons a bit darker" than to redefine the english language

Then it should be labelled something like BUTTON_COLOR instead.

...do you write code like this yourself and are trying to defend it, or something?

Jabor
Jul 16, 2010

#1 Loser at SpaceChem

Jonnty posted:

It's not particularly hard to imagine being instructed to "make it dark green", and using that so it can be easily changed in case that isn't the "right" dark green. It might have made more sense to put it under BUTTON_COLOUR or whatever, but for all we know it then actually is - as well as LABEL_COLOR and LINE_COLOR and BORDER_COLOR and ten other ones like it.

Then, as I suggested before, we have UI_PRIMARY_COLOR or similar.

All the benefits of COLOR_DARK_GREEN, but even more flexible for if you don't want it to be dark green any more!

Jabor
Jul 16, 2010

#1 Loser at SpaceChem
Regexes are actually a pretty good idea for this simple validation.

Honestly, return str ~= /^\d+$/ is a much more clear and legible way of expressing "this should consist solely of digits", and return str ~= !^(\d{2})/(\d{2})/\d{4}$! and int($1) < 32 and int($2) < 13 is a much better way of expressing that CheckDate thingy.

They're still simpler and clearer even after translating them to a language that isn't so straightforward with regards to regex matching. Of course, TryParse is really the better way of handling it. You can even use the parsed result as an out parameter, since you know the calling code is probably immediately going to parse it once you tell it it's good.

Jabor
Jul 16, 2010

#1 Loser at SpaceChem

Lumpy posted:

Huh?

Having a duplicated selector in a CSS rule isn't something one should aspire to, and if I saw one, I'd remove it. But since it cannot cause any unwanted behavior, isn't propagated anywhere else, can't break any other CSS files or rules, and I can't fathom it's existence causing anyone to cry at any point, I didn't think it was a HORROR. A minor annoyance that should be cleaned up, sure, but not a horror. How you infer that my code causes people to cry because of that....

Because the kind of person who double-pastes and doesn't notice or correct it is also the kind of person who is sloppy in other areas of their code.

Jabor
Jul 16, 2010

#1 Loser at SpaceChem

Jonnty posted:

Well, since they didn't post any other horrors, I guess that wasn't the case here?

Alternatively, they're in core business code that would be a fireable offence if you disclosed to the internet at large, and the poster didn't have the time to go through and anonymize it properly.

Jabor
Jul 16, 2010

#1 Loser at SpaceChem

Jonnty posted:

..so he got the weakest example he could find and blew it out of all proportion.

Maybe he couldn't tell which of the other WTF-y code was his and which was the other developers, so picked something he knew he didn't write?

Jabor
Jul 16, 2010

#1 Loser at SpaceChem

Zombywuf posted:

Tell me, how does this distinguish file does not exist, file is a directory, file is not readable and (my personal favorite) EAGAIN.

The point is, you don't really need to distinguish them. In most cases, your resolution will be "specify a valid file, dummy".

The real problem is that you need to address all of them somewhere, so you can either explicitly check for them before opening the file (and then duplicate it in the exception logic in case it changes between the check and the actual access), or you can just try it and if it doesn't work, figure out how to deal with it then.

Actually, the parenthetical statement is another important part. You have to write that exception logic anyway. Why not just skip the initial checks and deal with anything that goes wrong, when it actually goes wrong?

Jabor
Jul 16, 2010

#1 Loser at SpaceChem

Zombywuf posted:

I'm going to take it from that that you don't know what EAGAIN means.

I'm going to take it from that that you don't know what "most" means.

Jabor
Jul 16, 2010

#1 Loser at SpaceChem

OddObserver posted:

I am pretty sure it's normally a good design practice for the sensible behavior to be default.

Perl is designed so that common tasks can be achieved really easily, even if it results in unintuitive behaviour when taken out of context.

So in this case, instead of being erroring out when you compare a string to a number, it converts the string to a number and then compares them. If you want a string-based comparison, convert the number to a string and then compare.

Perl also assumes that the programmer knows what they're doing - if you convert a string that is only partially numeric to a number, it converts the numeric part and ignores the rest. If you want to do something different if the string is not just a number, explicitly test for that.

Jabor
Jul 16, 2010

#1 Loser at SpaceChem

Internet Janitor posted:

Scaevolus: Maybe I'm the coding horror here, but that could be a lot worse. Assuming all the settings are already stored in a single object, that seems like a halfway reasonable way to serialize and deserialize them without worring about breaking everything when you add a field. The main problem would appear to be a failure to organize the data with any kind of heirarchy.

Well, first of all, there's this line:

code:
else if (IFSresult) IFSresult = false;
Which as far as I can tell is a pretty horrible hack to let it not break on the one setting that has an additional line of data. And that's in addition to the reinventing-the-wheelness.

Jabor
Jul 16, 2010

#1 Loser at SpaceChem

Incoherence posted:

Because it's usually something like
code:
if (!(a && b) || c || d) {
  // do nothing
} else {
  // do something
}
(imagine a, b, c, and d are relatively long as well) and just leaving it that way is easier to parse than wrapping the whole thing in a !() and trying to figure out what it means in six months.

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))

Jabor
Jul 16, 2010

#1 Loser at SpaceChem

tef posted:

The weird bit

I don't hear other people who write websites or code wishing for php's == vs === in other languages. And yet somehow 'it's useful'.

It is a false utility - you exchange a legion of bugs for a handful of keypresses.

I think it's like Java developers claiming that anonymous inner classes are "useful".

Jabor
Jul 16, 2010

#1 Loser at SpaceChem

ShoulderDaemon posted:

For most hash constructions, you can amortize the costs of a changing suffix more readily than a changing prefix, meaning that you can take a dictionary of unsalted hashes for common passwords and cheaply transform it to a dictionary of suffix-salted hashes for common passwords, allowing more effective attacks against databases of accounts.

It looks to me like the username is taking the place of a nonconstant prefix.

Jabor
Jul 16, 2010

#1 Loser at SpaceChem
Is the first thing that gets done to the result of that query a split on `~'?

Jabor
Jul 16, 2010

#1 Loser at SpaceChem

yaoi prophet posted:


:kiddo:

Whoah, this language does DWIM on English as well?

Jabor
Jul 16, 2010

#1 Loser at SpaceChem

Incoherence posted:

As usual, this is sort of a good idea in theory (it keeps you from forgetting to clean up after yourself before returning in languages/situations where that matters, at the possible cost of making your logic harder to follow), but eventually everyone just sort of forgets the tradeoff part of it and it gets upgraded into a Law of Programming.

Honestly something like the following isn't too bad if you can't have automatic cleanup for some reason:

code:
function foo() {
   var return_value = sane_default;
   //LOGIC!...
   //...
       return_value = something;
       goto end_foo;
   //...
   //OTHER LOGIC!
  end_foo:
   //Cleanup!
   return return_value;
}
It only gets into real horror territory when the "OMG NO GOTOS EVAR" thing gets added in and then you have to add in some really convoluted logic to break out of a nested loop and not execute the rest of the code until the cleanup bit.

Jabor
Jul 16, 2010

#1 Loser at SpaceChem

Zombywuf posted:

HTML has lists, sets and dictionaries. It also has a bunch of other stuff like semantically marked up hyperlinks, what more could you need?

Any setup where the structure of data is inherently tied up and munged in with its presentation is pretty sucky. It basically means you have to choose between presenting well-structure data for the benefit of automated systems, or well-presented data for the benefit of humans looking at it, and it's a right pain in the rear end to get both.

Jabor
Jul 16, 2010

#1 Loser at SpaceChem

Wheany posted:

already-hashed user.getPassword().

Unfortunately, I'm afraid that either:

1. They're not hashing passwords, or
2. That method is poorly-named.

And as much as I'm hoping it's 2, I'd have to put my money on it being 1.

Jabor
Jul 16, 2010

#1 Loser at SpaceChem

Wheany posted:

Well what does encryptAndSave(user, newPassword); do?

Encrypt the username?

Reversible encryption.

Jabor
Jul 16, 2010

#1 Loser at SpaceChem
Considering that sleepsort is just insertion sort with a whole lot of system call overhead chucked in...

Jabor
Jul 16, 2010

#1 Loser at SpaceChem

Milotic posted:

but the first call to GetAction is with a value of 1, and not 0 as you would initially intuit.

It's the whole lambda scoping thing. Lambdas close over variables, not values.

Jabor
Jul 16, 2010

#1 Loser at SpaceChem

nielsm posted:

Evil, but I see how it kinda makes sense.

It allows you to have persistent, modifiable state in a lambda, which you you either can't or it's-a-real-pain-to-do otherwise. The obvious "toy example" is a lambda which tracks how many times it's been called, but there are some actual useful uses for it. For example, we could implement a PRNG as so (largely psuedocode):

code:
newGenerator(int seed)
  return function() {
    seed = (seed * P) % n;
    return seed;
  }
Whether it's a good idea to have it as the default (closing over values by default and requiring a keyword such as outer to access a persistently-scoped variable might perhaps be more intuitive), it's pretty common to anonymous functions across all languages and should really only catch you out once.

Jabor
Jul 16, 2010

#1 Loser at SpaceChem

Scaevolus posted:

Consistent coding style for "readability and maintenance purposes" is comical considering the developers have to work with zend-guard obfuscated code.

Who wants to bet that they've actually lost the original unobfuscated source?

Jabor
Jul 16, 2010

#1 Loser at SpaceChem


Comic Sans 4 lyfe :smugdog:

Jabor
Jul 16, 2010

#1 Loser at SpaceChem

MEAT TREAT posted:

Seriously what the gently caress is an aliasing violation? I tried looking it up, but the examples I saw didn't make any sense. Is that something that you C guys have to deal with constantly?

Basically "aliasing" is when you have one location that's referred to by multiple names.

If you assume that anything at all can be aliased to anything else in the current scope, then that really limits what optimizations you can do - you have to actually write everything to memory before you read through a pointer, for example. So for performance, the compiler is allowed to assume that in most cases there is no aliasing.

If there actually is aliasing when the compiler assumes there isn't, then you can run into some problems with your reads getting stale values and the like.

Jabor
Jul 16, 2010

#1 Loser at SpaceChem

qntm posted:

php:
<?
class Object { }
$a = new Object();
$b = new Object();

print($a === $b ? "true" : "false"); // "false"
$b =& $a;
print($a === $b ? "true" : "false"); // "true"
?>

Wait, what's the horror?

Two entirely separate objects are nonequal, that's fine. Do a reference assignment so that both are referencing the same object, and then they're equal (as they should be)?

PHP has enough horrors as it is, you don't really need to make up more.

Jabor
Jul 16, 2010

#1 Loser at SpaceChem

1337JiveTurkey posted:

Implicit casts are functions from one type to another. If I write foo = 2 + "2" or foo = "2" + 2 then depending on the language, foo might equal 4 or "22" (or both depending on the order of the operands). Either I'm terrible at math or that is the worst violation of the Liskov Substitution Principle I have ever seen.

If it's consistent within a language, then there's no problem?

Unless you were wanting to talk about the principle of Least Surprise instead of LSP, I guess.

Alternatively you could use a language that doesn't use the exact same operator for two completely different operations.

Jabor
Jul 16, 2010

#1 Loser at SpaceChem

Janin posted:

Not many languages pass that test; for example, concatenation and addition are just as different, yet "a" + "b" isn't a type error.

Depends on the language - Perl wouldn't be doing a string concatenation there, for example.

When it comes to strongly-typed languages "based on the type of the left-hand operand" is a perfectly fine solution - but for a loosely typed language, overloading a single operator for two conceptually different things is a bad idea.

Jabor
Jul 16, 2010

#1 Loser at SpaceChem

nielsm posted:

If two objects with the same interface have different actual operations performed by otherwise identical calls, then they are of different types.

Does that make the empty string (that is, the string that returns true when you call isEmpty()) of a different type to any other string?

They do have quite distinct behaviour in that regard.

Jabor
Jul 16, 2010

#1 Loser at SpaceChem
That sure is some pretty, pretty, HTML.

Jabor
Jul 16, 2010

#1 Loser at SpaceChem
See this is why typed enumerations are a good thing.

Jabor
Jul 16, 2010

#1 Loser at SpaceChem

BonzoESC posted:

Except for the forums mangling your indentation, that looks pretty much par for the course for jQuery.

code:
var downType=$('#rdoPercentage').val() == "pct" ? "pct": "fixed";
Wouldn't this always be "pct", or am I just not getting jquery?

Jabor
Jul 16, 2010

#1 Loser at SpaceChem

Haystack posted:

Javascript's ternary syntax is var return_value = test ? expression1 : expression2. So JediGandalf's code would return "pct" if downType=$('#rdoPercentage').val() returned "pct", or "fixed" if otherwise.

Right. But my point is that there's only one HTML element with an id of #rdoPercentage, and that always has the value "pct".

Which is why I was asking about jQuery, not javascript.

Jabor
Jul 16, 2010

#1 Loser at SpaceChem
"Design patterns" are basically means of working around deficiencies in a language, and most uses of goto are no exception.

- Early-days uses of goto were workarounds for a lack of proper structured-programming constructs. This deficiency has been corrected in many modern languages.

- Using goto to help implement single-point-of-return is generally a workaround for a language not having having a mechanism for scope-based resource lifetimes - some languages (e.g. C++, anything with proper try-finally blocks) have this, but others don't, so using goto in this manner could be alright if your language doesn't have a better way of doing it.

- Using goto to break out of nested loops is a workaround for not otherwise being able to interact with control flow elements that aren't "the element I am directly inside of" or "the entire function I am part of".

Goto is bad, but sometimes it's better than all the alternatives, and when that's the case it usually suggests a deficiency in the language.

Jabor
Jul 16, 2010

#1 Loser at SpaceChem

Aleksei Vasiliev posted:

URL a = new URL("http://stackoverflow.com");
URL b = new URL("http://stackexchange.com");
System.out.println(a.equals(b));
true


whose brilliant idea was this

You know what's awesome about this?

If the machine you're running on has no DNS, your calls to equals will hang the thread for a second or two while the name lookups time out.

Jabor
Jul 16, 2010

#1 Loser at SpaceChem
I would guess it's the fact that the + operator is overloaded for both addition and string concatenation, which makes the operator not associative in certain combinations of types.

(Foo + (string + integer)) [the first snippet] does one thing, while ((Foo + string) + integer) [the second one] does it differently.

Adbot
ADBOT LOVES YOU

Jabor
Jul 16, 2010

#1 Loser at SpaceChem

Wheany posted:

Yes, the init function has one eval in the middle of the for some reason.

It appears to be an (ugly and terrible) workaround for how this gets evaluated in Javascript, by "baking in" the value of this._elementId when the event is created rather than having it be resolved when the event runs.

Of course there are so many better ways of doing it but it is necessary to do something there to get around Javascript's this-fuckery.

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