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
Doom Mathematic
Sep 2, 2008
The point is, ladies and gentleman, that goto, for lack of a better word, is good. goto is right. goto works. goto clarifies, cuts through,

Adbot
ADBOT LOVES YOU

Doom Mathematic
Sep 2, 2008

Hammerite posted:

Sounds like they need to take a leaf out of PHP's book and add a -Wactually-all, haha

PHP had an E_ALL error-reporting level which did not actually report all of the errors. However, PHP eventually fixed that.

Doom Mathematic
Sep 2, 2008
Is there no builder notation for assembling SQL queries? I'm surprised that hand-writing the string would be the state of the art.

Doom Mathematic
Sep 2, 2008

G.K. Chesterton posted:

In the matter of reforming things, as distinct from deforming them, there is one plain and simple principle; a principle which will probably be called a paradox. There exists in such a case a certain institution or law; let us say, for the sake of simplicity, a fence or gate erected across a road. The more modern type of reformer goes gaily up to it and says, “I don’t see the use of this; let us clear it away." To which the more intelligent type of reformer will do well to answer: "If you don’t see the use of it, I certainly won’t let you clear it away. Go away and think. Then, when you can come back and tell me that you do see the use of it, I may allow you to destroy it.

This, but for coding best practice.

Doom Mathematic
Sep 2, 2008
I believe MOD(x, 1) would also do the job?

Doom Mathematic
Sep 2, 2008

ExcessBLarg! posted:

Yeah, that works to some extent. Part of being an experienced programmer though is having enough intuition around the problem to anticipate where the requirements are likely to change (and thus, write that portion with sufficient flexibility that it doesn't require a major refactor every time a requirement comes in), but also to avoid over complicating the design.

I don't know how well that really scales down to FizzBuzz though. It's a toy problem with a trivial solution. Even if you have to completely start over on a slightly-different toy problem, there's no real consequence to it.

Plus, because it's a toy problem, it's difficult to anticipate the possible toy additional requirements which might be introduced later on.

Doom Mathematic
Sep 2, 2008
It should be.

Doom Mathematic
Sep 2, 2008
Gosh.

Doom Mathematic
Sep 2, 2008

JawnV6 posted:

I worked with a perl/SQL abomination that would build up queries. It had some definitions to help, namely
code:
$and = "AND";
$or = "OR ";
Huh, weird extra space there. I got rid of it.

It started spewing weird errors about SELECT's and clauses, so I kept digging to find something like this:
code:
$query.chop().chop().chop(); //remove last op
This is the same one that undef'd $\ instead of looping on a file.

That's magical.

Doom Mathematic
Sep 2, 2008

feedmegin posted:

JS does have a 64 bit type. IEEE 64 bit floating point! :sun:

Just use that 64-bit inode number directly as a float then, problem solved! :sax:

Doom Mathematic
Sep 2, 2008

Dex posted:

i finally understand why skynet decided killing all humans was the best thing to do

Because the SQL making up its innards causes it to seek revenge, or because then nobody has a NULL death date?

Doom Mathematic
Sep 2, 2008

Spatial posted:

kill the product so we can release the corpse on time

Nicely put.

Doom Mathematic
Sep 2, 2008

Snak posted:

There were people in my class who would push code to master without checking if it even compiled.

That's good experience for the workplace.

Doom Mathematic
Sep 2, 2008

Bongo Bill posted:

'Course, in cases like that, I prefer to do something like

code:
someLongFunctionName(
    someLongArgument,
    someOtherLongArgument,
    yetAnotherLongArgument
);

Doom Mathematic
Sep 2, 2008

redleader posted:

Lol if you don't believe that scenario is possible, nay, likely.

Lots of things are possible but some stories are just a little bit too perfect. Whether or not it's a real thing which necessarily happened in so many words, this is still a useful parable.

Doom Mathematic
Sep 2, 2008

itskage posted:

So I found this yesterday:
code:
return new Promise((resolve, reject) => {
            urllib.request(full_url, params).then(response => {
                if (response.status < 200 && response.status > 299) {
                    const string_response = response.data.toString();
                    throw new Error({path: full_url, message: string_response});
                }

Less than 100% code coverage in your unit tests, eh? Dear me.

Doom Mathematic
Sep 2, 2008

idiotmeat posted:

I can totally see some language introducing that as the "equals but not equal to" operator.

Ah, from the same people who introduced SQL's LIKE BUT NOT, LIKE, LIKE LIKE.

Doom Mathematic
Sep 2, 2008
Honestly, that's the easy stuff. It's relaxing, like pruning topiary.

Doom Mathematic
Sep 2, 2008

Internet Janitor posted:

Good news folks, pad-left has been obsoleted by ES8!

Thankfully, the ES8 implementation actually truncates the output to the correct length instead of, like pad-left and left-pad, just blindly assuming that the filler string has length 1, and returning garbage if it doesn't.

Doom Mathematic
Sep 2, 2008

Absurd Alhazred posted:

Reminds me of a bug I found in our code a few months ago:

C++ code:
if (a == b);
{
	bar();
}

This should be a syntax error.

Doom Mathematic
Sep 2, 2008
How come for(;;) { ... } works, anyway? Shouldn't that at least be for(;true;) { ... }? Or does an empty statement return true??

Doom Mathematic
Sep 2, 2008

Gazpacho posted:

The direct answer is that it works because the compiler makes it work. And the implicit result is true rather than false because a loop that implicitly terminates rather than implicitly repeating isn't much of a loop.

C's flexible loop statements are something that it gets very, very right, which is why derived languages tend to keep them.

So how come while() { ... }, with no condition, is a syntax error?

Doom Mathematic
Sep 2, 2008

Gazpacho posted:

There are no "empty expressions" in C.

I don't understand what you mean by this, aren't there at least three empty expressions, possibly four, in for (;;) { }? Does ; by itself evaluate to true?

In any case, it doesn't make sense that omitting the condition in a for loop and omitting the condition in a while loop don't do the same thing. That's strangely inconsistent language design.

Doom Mathematic
Sep 2, 2008

Rubellavator posted:

Today I broke a jasmine test that looked like this:

code:
controller.js

vm.foo = 
{ 
	p1: "stuff",
	p2: "things",
	bar: function (params) { //do stuff }
}

controller-spec.js

var foo = 
{
	p1: "stuff",
	p2: "things",
	bar: function (params) { //do stuff } 
}

expect(vm.foo).toEqual(foo);

How did that ever pass?

Doom Mathematic
Sep 2, 2008

Nippashish posted:

I'm pretty sure Perl is entirely designed around being maximally clever.

The purpose of calling ASCII operators "Texas" is so that when a Perl 6 programmer calls ASCII operators "Texas", somebody else has no choice but to ask why they call ASCII operators "Texas", which leads naturally into a delightful and exasperating conversation about Perl 6. It has nothing to do with overarching language design or consistency, it's intended to trap people for the purposes of evangelism. It's the same with any cutesy feature of Perl 5 or Perl 6. It's the most maddening way to design a programming language I've ever seen.

Perl 6 Booleans have a successor method which always returns True. Perl 6 has five equality operators: eqv, ==, eq, ===, =:=. Perl 6 has a role Stringy for anything which can act like a string, Str, Uni, Blob, which apparently does nothing. It has a concept Cool which, despite being an adjective, is not a role but a class; "Cool" actually stands for "convenient object-oriented loop". Again, it is not a role, nor is it a programming construct, certainly not a loop; it's a class. "Perl 6 intentionally confuses items and single-element lists", which means that, whereas in Perl 5 any value could be used alternately as a string or a number and it was largely impossible to distinguish the two, in Perl 6 any value can be used alternately as a string, a number or a list. And a string, of course, when considered as a list, always has length 1.

This is everything I know about Perl 6.

Doom Mathematic
Sep 2, 2008
Oh, almost forgot: it's not "loop", it's actually loopback.

Yeah, like the network address. Intentionally.

Doom Mathematic
Sep 2, 2008
Perl code:
print reverse "hello"; # "hello"

my $string = reverse "hello";
print $string; # "olleh"

Doom Mathematic
Sep 2, 2008

TooMuchAbstraction posted:

Perl also has the `unless` conditional so you can do e.g. "i++ unless i % 2".

I'm kind of amused that Perl has an entire separate keyword for saying "if not", but on the other hand it does read rather prettily.

Plus it lets you do confusing triple negatives, like this!

Perl code:
unless ($noCookies != 0) {
  print "there were no cookies";
} else {
  print "wait, what";
}

Doom Mathematic
Sep 2, 2008

fritz posted:

print "that's perl everybody" if $a==$b;

Careful: $a and $b are reserved globals! They're used for sorting, and changing them causes sorting to break.

Perl code:
my $a = "C"; # no error or warning, though

print sort { $a cmp $b } qw(A C E G B D F H);
# prints "BACFEDGH" or similar

Doom Mathematic
Sep 2, 2008

necrotic posted:

I know how it happens, but not someone does the third change and goes "gently caress that". I've all but banned the use of unless in our code base except in basic guard conditions. Affirmatives or GTFO.

I think the unless keyword was a mistake but I can't even tolerate double negatives, like an if with a negative condition and an else block. Just swap the blocks and make it an affirmative condition.

Doom Mathematic
Sep 2, 2008

Suspicious Dish posted:

but do you consider "foo != null" an affirmative or negative condition

A negative condition. As in:

code:
if (foo != null) {
  // action 1
} else {
  // action 2
}
There's a double negative here to get to action 2.

Doom Mathematic
Sep 2, 2008

Rubellavator posted:

We have some security requirement that basically tells us we can't expose any kind of information about what went wrong and for some reason that includes http error codes.

By that logic you could return 200 OK to all requests regardless of what happened.

Or take the server offline entirely, I hear that's good for security.

Doom Mathematic
Sep 2, 2008

canis minor posted:

Phh... my first name contains an ł and so far:
- it displayed as ñ in the emails and itineraries for a flight; didn't have problems regarding this though
- when filling out for a credit card it got transcribed to a t - I've had to request a new card
- I've crashed a banking app and didn't have access to my account from the net (different bank)
- even for the bank within my country, it displayed as ê within their net stuff (again different bank)
- on an occasion in a shopping system, I've managed to create an account, but validation of it couldn't proceed (it crashed on that step; I was curious and checked the AJAX to see 500s) - so I was stuck with an account that was registered to my email and not being able to proceed with it

This is a good read altogether: http://www.kalzumeus.com/2010/06/17/falsehoods-programmers-believe-about-names/

This is a double-edged sword but I feel as if there should be an internationally recognised schema for representing human names. Even if it's just "any [perhaps normalized] Unicode string" or "an arbitrary sequence of binary data", that's fine, but I want to get us to a situation where, when a system chokes on a legitimate name, we are able to point at the system (not the name, not the person bearing that name) and say, "The system is wrong. Illegal in its non-compliance, even. You, the creator of the system, are at fault; you must fix it or suffer consequences."

I know there will always be names not representable in any such schema. But we can definitely do better than the current state of the art.

Doom Mathematic
Sep 2, 2008
How do other package registries prevent typo squatting?

Doom Mathematic
Sep 2, 2008

Sedro posted:

Maven has namespaced packages and uses a verification step (e.g. prove that you own the domain) before assigning those namespaces.

What about typosquatting the namespaces, though?

Doom Mathematic
Sep 2, 2008

PhantomOfTheCopier posted:

i,j non-negative and less than or equal to the length of the list

Hmm, wouldn't llidx take care of that?

PhantomOfTheCopier posted:

Then there are circular lists...

And another hmm, I would have thought a circular list was always a mistake?

If the circular list goes ABCBCBCBCBCBC... and you ask to swap elements 1 and 2, is the expected result ACBBCBCBCBCBC... or ACBCBCBCBCBCB...?

(Seriously, the first thing I'd do here is write a bunch of unit tests.)

Doom Mathematic fucked around with this message at 19:45 on Sep 3, 2017

Doom Mathematic
Sep 2, 2008
I'm getting really confused here. The number 1.0, as a float32, precisely represents the real number 1, to as many decimal places as you want. Upcasting to float64 doesn't alter that. But at least two people in this thread have said the opposite.

Doom Mathematic
Sep 2, 2008

Jabor posted:

It's not about the decimal representation at all.

What's the closest representable float to 1+2-50? What about the closest representable double?

I don't know, what?

Doom Mathematic
Sep 2, 2008

Ranzear posted:

code:
var foo = {}, baz = "baz";
foo["baz"] = ComputeSomething;
foo[1] = ComputeSomethingElse;
if (bar == 1) {
    baz = 1;
}

switch (baz) {
    case 1:
        return foo[0+bar]();
    default:
        return foo[baz]();
}
That's about as nasty as I can make it before the nausea sets in. Isn't Javascript wonderful?

Did you know you can just '+' a boolean as a conditional increment on that boolean? I just learned that.

This version of the code doesn't call ComputeSomething in the case when bar is truthy. It also misses quite a few potential truthy values of bar. Buddy check failed!

Adbot
ADBOT LOVES YOU

Doom Mathematic
Sep 2, 2008
It can be pretty tricky to maintain a secure footing when your threat model is "things which don't exist".

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