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
Zemyla
Aug 6, 2008

I'll take her off your hands. Pleasure doing business with you!

Soricidus posted:

reminder that the primary design consideration for c++ iterators was “how do we make these look and behave like pointer arithmetic”

there’s a reason why no other language has copied the c++ design

Almost everything I would do with iterators, I do instead with either Foldable/Traversable or pattern matching. It really is a more elegant system.

Adbot
ADBOT LOVES YOU

ynohtna
Feb 16, 2007

backwoods compatible
Illegal Hen
If you ever have to document an iterator, replace one instance of the word with "irritator."

qsvui
Aug 23, 2003
some crazy thing

vOv posted:

Using iterators is cool and good but I really really wish they were simpler to implement and that there was some kind of 'range' type instead of passing begin/end pairs everywhere.

I think I mentioned this before, but ranges have been proposed for inclusion into a future standard.

The Phlegmatist
Nov 24, 2003
The inclusion of range in the standard is waiting for the inclusion of concepts, which has officially been Real Soon Now for over ten years.

But it looks like they might finally get into C++20, so who knows.

Workaday Wizard
Oct 23, 2009

by Pragmatica
I lust for C++ death.

Absurd Alhazred
Mar 27, 2010

by Athanatos

Shinku ABOOKEN posted:

I lust for C++ death.

std::death is due for consideration in C++22

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.
I’m std::launder

The Phlegmatist
Nov 24, 2003

pokeyman posted:

I’m std::launder

sorry about your inscrutability and lack of real-world use cases

VikingofRock
Aug 24, 2008




pokeyman posted:

I’m std::launder

I just looked this up, and this has strengthened my resolve to never, ever use placement new or reinterpret cast.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

The Phlegmatist posted:

sorry about your inscrutability and lack of real-world use cases

Me too bud, me too.

boo_radley
Dec 30, 2005

Politeness costs nothing
From a Twitter thread
Android had a wtf log level:

https://developer.android.com/reference/android/util/Log.html#wtf posted:

wtf(String tag, String msg,Throwable tr)

What a Terrible Failure: Report an exception that should never happen.
Seems about right.

baka kaba
Jul 19, 2003

PLEASE ASK ME, THE SELF-PROFESSED NO #1 PAUL CATTERMOLE FAN IN THE SOMETHING AWFUL S-CLUB 7 MEGATHREAD, TO NAME A SINGLE SONG BY HIS EXCELLENT NU-METAL SIDE PROJECT, SKUA, AND IF I CAN'T PLEASE TELL ME TO
EAT SHIT

It can also tell if you're a goat

repiv
Aug 13, 2009


Or a monkey, for that matter

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



boo_radley posted:

From a Twitter thread
Android had a wtf log level:

Seems about right.

Hmm, I think the anti-Android sass here is "So it's called every time the user turns the screen on or just on each boot? :haw:"

Also, what do you mean 'had'? That looks current and not marked obsolete or anything like that.

baka kaba
Jul 19, 2003

PLEASE ASK ME, THE SELF-PROFESSED NO #1 PAUL CATTERMOLE FAN IN THE SOMETHING AWFUL S-CLUB 7 MEGATHREAD, TO NAME A SINGLE SONG BY HIS EXCELLENT NU-METAL SIDE PROJECT, SKUA, AND IF I CAN'T PLEASE TELL ME TO
EAT SHIT

Is the monkey on the Death Star?

the actual horror is there are gravity constants for real planets too, implying Android Auto for moon buggies is in our future

Internet Janitor
May 17, 2008

"That isn't the appropriate trash receptacle."
given that star wars regularly gives no fucks wrt. physics and all spacecraft in the star wars universe apparently have artificial gravity, on what basis would one estimate the force of gravity on the death star?

boo_radley
Dec 30, 2005

Politeness costs nothing

boo_radley posted:

From a Twitter thread
Android continues to have a wtf log level:

Seems about right.

E: corrected tense

Space Kablooey
May 6, 2009


Internet Janitor posted:

given that star wars regularly gives no fucks wrt. physics and all spacecraft in the star wars universe apparently have artificial gravity, on what basis would one estimate the force of gravity on the death star?


I'd say that someone did the math using whatever data (material density, size and whatnot) they could, but I'm sure there's a canon source that spells out the surface gravity.

Doom Mathematic
Sep 2, 2008
Surface gravity on the Death Star isn't even perpendicular to the surface half the time.

fishmech
Jul 16, 2006

by VideoGames
Salad Prong

Doom Mathematic posted:

Surface gravity on the Death Star isn't even perpendicular to the surface half the time.

You're confusing the intrinsic surface gravity with the gravitomotronic fields invented by biggs darklighter's great great great granduncle in 399393 bby to defeat the sith lord darth unpleasant.

I'm 90% sure thats the real star wars explanation for that.

feedmegin
Jul 30, 2008

Internet Janitor posted:

given that star wars regularly gives no fucks wrt. physics and all spacecraft in the star wars universe apparently have artificial gravity, on what basis would one estimate the force of gravity on the death star?

I'm guessing theres a reason it says unspecified imperial rather than SI units.

canis minor
May 4, 2011

Can (a ==1 && a== 2 && a==3) ever evaluate to true? is a fun thought experiment.

Winter Stormer
Oct 17, 2012

code:
bool operator==(const A&, int) {
	return true;
}

The Phlegmatist
Nov 24, 2003
at least go all out with it

code:
#include <iostream>

struct Foo
{
    int a;

    Foo(int a) : a(a){};

    bool operator==(const Foo& rhs)
    {
        return a++ == rhs.a;
    }
};

int main()
{
    Foo foo(1);
    if (foo == 1 && foo == 2 && foo == 3)
    {
        std::cout << "C++ is a language where many things are done and none of them good." << std::endl;
    }
}
The true horror is that it was an interview question. Let's hire the guy who knows how to entirely disregard operator semantics.

Jeb Bush 2012
Apr 4, 2007

A mathematician, like a painter or poet, is a maker of patterns. If his patterns are more permanent than theirs, it is because they are made with ideas.
isn't the simplest (in that it doesn't require malicious operator overloading or the like) answer "there's another thread that can also mutate a"?

VikingofRock
Aug 24, 2008




Winter Stormer posted:

code:
bool operator==(const A&, int) {
	return true;
}

This was my first thought as well, but the question specifies "in JavaScript" (which doesn't have operator overloading).

Eela6
May 25, 2007
Shredded Hen

The Phlegmatist posted:

at least go all out with it

code:
#include <iostream>

struct Foo
{
    int a;

    Foo(int a) : a(a){};

    bool operator==(const Foo& rhs)
    {
        return a++ == rhs.a;
    }
};

int main()
{
    Foo foo(1);
    if (foo == 1 && foo == 2 && foo == 3)
    {
        std::cout << "C++ is a language where many things are done and none of them good." << std::endl;
    }
}
The true horror is that it was an interview question. Let's hire the guy who knows how to entirely disregard operator semantics.

It's like Wizards in Discworld. I want to hire a programmer whose job is knowing how to dynamically refrain from abusing operator overloading.

canis minor
May 4, 2011

VikingofRock posted:

This was my first thought as well, but the question specifies "in JavaScript" (which doesn't have operator overloading).

That's correct, though tbf after I've read through the SO, I've started thinking of how to do it in other languages.

define made a visit in those thoughts as well.

also - it's fun to see how JS allows such simple statement to be abused.

Doom Mathematic
Sep 2, 2008

Jeb Bush 2012 posted:

isn't the simplest (in that it doesn't require malicious operator overloading or the like) answer "there's another thread that can also mutate a"?

Not in JavaScript, no.

VikingofRock posted:

This was my first thought as well, but the question specifies "in JavaScript" (which doesn't have operator overloading).

Yet.

Doom Mathematic fucked around with this message at 22:08 on Jan 16, 2018

Nude
Nov 16, 2014

I have no idea what I'm doing.

The Phlegmatist posted:

at least go all out with it

code:
#include <iostream>

struct Foo
{
    int a;

    Foo(int a) : a(a){};

    bool operator==(const Foo& rhs)
    {
        return a++ == rhs.a;
    }
};

int main()
{
    Foo foo(1);
    if (foo == 1 && foo == 2 && foo == 3)
    {
        std::cout << "C++ is a language where many things are done and none of them good." << std::endl;
    }
}
The true horror is that it was an interview question. Let's hire the guy who knows how to entirely disregard operator semantics.

It's actually easier in C#:
C# code:
public class Program
{
    static int _a;
    static int a
    {
	get
	{
	    return _a++;
	}
	set
	{
	    _a = value;
	}
    }

    public static void Main(string[] args)
    {
	if (a == 0 && a == 1 && a== 2)
	{
	    Console.WriteLine("Horror!");
	}
    }
}
I always kind of wondered why C# allowed properties in general instead of just explicit getters and setters functions honestly.

E: fixed typo.

Nude fucked around with this message at 01:23 on Jan 17, 2018

Doom Mathematic
Sep 2, 2008
Everybody is missing the more important line in that SO question.

quote:

This is interview question asked by a major tech company. My answer was that it's impossible. They said nothing is impossible. It happened 2 weeks back

Somebody in this company is, just to begin with, using non-strict equality. So, no linting is going on here. That's the first alarm bell.

But on top of that, they either wrote a custom implementation of toString/valueOf which doesn't always return the same value OR they used a as a global variable with a non-deterministic getter which doesn't always return the same value OR they've exhumed the rancid corpse of with OR MAYBE WORSE. Not as a thought experiment! This happened for real!

Back slowly away from this organization.

Eggnogium
Jun 1, 2010

Never give an inch! Hnnnghhhhhh!

Doom Mathematic posted:

Everybody is missing the more important line in that SO question.


Somebody in this company is, just to begin with, using non-strict equality. So, no linting is going on here. That's the first alarm bell.

But on top of that, they either wrote a custom implementation of toString/valueOf which doesn't always return the same value OR they used a as a global variable with a non-deterministic getter which doesn't always return the same value OR they've exhumed the rancid corpse of with OR MAYBE WORSE. Not as a thought experiment! This happened for real!

Back slowly away from this organization.

I doubt it came about like that, they probably just thought it up as a way to suss out candidates who really think about what's going on under the hood of the code they're writing. I'm not claiming it's a good way to do that.

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.




:ohdear: I'm afraid to look

Nude posted:

I always kind of wondered why C# allowed properties in general instead of just explicit getters and setters functions honestly.

Properties are a guarantee the compiler can rely on in an object's interface so the JIT can probably do more optimizations around property access than hand-rolled getter/setters and are a lot less annoying to use. Dunno if either of those is the reason, but both seem good.

canis minor
May 4, 2011

Doom Mathematic posted:

Everybody is missing the more important line in that SO question.


Somebody in this company is, just to begin with, using non-strict equality. So, no linting is going on here. That's the first alarm bell.

But on top of that, they either wrote a custom implementation of toString/valueOf which doesn't always return the same value OR they used a as a global variable with a non-deterministic getter which doesn't always return the same value OR they've exhumed the rancid corpse of with OR MAYBE WORSE. Not as a thought experiment! This happened for real!

Back slowly away from this organization.

That turned grim pretty quickly.

I'd rather hope this is to get a programmer that thinks everything is possible and can separate right from wrong (but you're probably right, as I assume the best in people)

Munkeymon posted:

:ohdear: I'm afraid to look

Oh, you kind of can - for `+` (but that's not proper overloading, but rather casting (?)). I think operator overloading won't come soon to JS, if at all. Still people try to do it

canis minor fucked around with this message at 22:43 on Jan 16, 2018

Doom Mathematic
Sep 2, 2008
Well, I wasn't in the interview, we only have the candidate's paraphrase for it, but "They said nothing is impossible. It happened 2 weeks back" says to me that it happened.

But even if it was dreamt up as a thought experiment, the only way code like this can happen is if you disobey hard-earned years of best practice and deliberately shirk industry standard code quality tools. Nobody should ever need to know how == or with work anymore. These practices are, in large part, why programming in JavaScript is more tolerable now than it was in ages past. This says something about practices at this potential employer, about the kind of code they are responsible for, the level of nonsense that employees are going to have to put up with.

Maybe somebody wrote a non-deterministic getter somewhere along the line, and this is a simplification of that problem intended to highlight the issue. Getters have legitimate use cases and I guess they can go wrong in that way if they become too complex. Still doesn't explain the double-equals thing though.

Dirty Frank
Jul 8, 2004

Doom Mathematic posted:

Well, I wasn't in the interview, we only have the candidate's paraphrase for it, but "They said nothing is impossible. It happened 2 weeks back" says to me that it happened.

But even if it was dreamt up as a thought experiment, the only way code like this can happen is if you disobey hard-earned years of best practice and deliberately shirk industry standard code quality tools. Nobody should ever need to know how == or with work anymore. These practices are, in large part, why programming in JavaScript is more tolerable now than it was in ages past. This says something about practices at this potential employer, about the kind of code they are responsible for, the level of nonsense that employees are going to have to put up with.

Maybe somebody wrote a non-deterministic getter somewhere along the line, and this is a simplification of that problem intended to highlight the issue. Getters have legitimate use cases and I guess they can go wrong in that way if they become too complex. Still doesn't explain the double-equals thing though.

You're missing the full stop

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe

Nude posted:

It's actually easier in C#:
C# code:
public class Program
{
    static int _a;
    static int a
    {
	get
	{
	    return _a++;
	}
	set
	{
	    _a = value;
	}
    }

    public static void Main(string[] args)
    {
	if (a == 0 || a == 1 || a == 2)
	{
	    Console.WriteLine("Horror!");
	}
    }
}

You can make it even easier than that if you're going to swap && for ||...

steckles
Jan 14, 2006

Not a coding horror per se, but Sage sells two distinct pieces of software with the same name. We went to install our interface software on a client's machine and Whoops! this Sage 50 is not like the other Sage 50s. Why are there two? What benefit does having two Sage 50s with incompatible APIs provide?

Obviously they know something we don't. At our next dev meeting, I'm going to propose splitting our main product into three incompatible versions that are assigned to new clients randomly.

Nude
Nov 16, 2014

I have no idea what I'm doing.

Hammerite posted:

You can make it even easier than that if you're going to swap && for ||...

:doh: My bad that was a typo my code works if you do &&.

Adbot
ADBOT LOVES YOU

raminasi
Jan 25, 2005

a last drink with no ice

Munkeymon posted:

Properties are a guarantee the compiler can rely on in an object's interface so the JIT can probably do more optimizations around property access than hand-rolled getter/setters and are a lot less annoying to use. Dunno if either of those is the reason, but both seem good.

I'm pretty sure they're just syntactic sugar for getters and setters. I don't think that the CLR has any special use for them.

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