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
Gul Banana
Nov 28, 2003

double home works on ipad, yes, and four finger swipe works from anywhere.

Adbot
ADBOT LOVES YOU

Jabor
Jul 16, 2010

#1 Loser at SpaceChem

Otto Skorzeny posted:

As a user, my expected behavior here is that if I hit the home button the music keeps playing whereas if I hit the back button the music stops and the app ceases to get cpu time.

Perhaps you should tell Pandora that that's what you want their app to do then!

If you do really want to stop a badly-behaved application, you just hit the "recent apps" button and swipe the application away.

revmoo
May 25, 2006

#basta
Chromecast is a great example of bad Android behavior. If I use Netflix or Youtube to play Chromecast content, I'll wake up the next morning with a dead phone. This has been a known issue for some time and the only resolution is to force quit any Chromecast-using apps after selecting your content.

chippy
Aug 16, 2006

OK I DON'T GET IT

seiken posted:

The original is really really horrible IMO, there's 3 or 4 completely redundant/pointlessly over-complicated things about it. It's not the end of the world but no way I'd let it through code review. InternetJanitor's rewrite takes less than half the time to understand what it does

It's also not very 'pythonic'. Although I'm sure the sort of person that uses that term would probably tell you to do it like this:

code:
toobig = [feature.value for dimension in dimension for feature in dimension if feature.value > threshold]
if len(toobig) > 0:
	return 'failed'
return 'passed'

Shugojin
Sep 6, 2007

THE TAIL THAT BURNS TWICE AS BRIGHT...


I'd like to submit the entirety of SAS. I need to know it to do data analysis because it's worked its way in as a standard tool, but:

  • You can literally put the entirety of your code on one line. It reads the procedures as
    code:
    proc (command of some sort);
    
    but if you put another proc command after that semicolon it will be treated as a different line like so!
    code:
    proc print onething; print twothings;... ...print (n-1)things; print nthings;
    
  • You can put a comment in the middle of the line and keep going!
    code:
    proc (I am a command *(I am a comment); I am the rest of the command;
    
  • and of course, the markers for comment blocks which work as
    code:
    /* block of comments */
    
    cannot be in columns one or two because they may in some (but not all!) cases be interpreted as interrupt commands to stop the program!

who the gently caress wrote this thing it's like it was designed explicitly to allow terrible coding practices and promote syntax errors

raminasi
Jan 25, 2005

a last drink with no ice
Those first two are true of C, C#, and Java.

Shugojin
Sep 6, 2007

THE TAIL THAT BURNS TWICE AS BRIGHT...


GrumpyDoctor posted:

Those first two are true of C, C#, and Java.

That's true but they don't have an elearning course where a robot lady voice talks about it like it's a feature and you would ever want to do it before saying don't do it.

Also last I checked you can code all three of those without shelling out $8770 for the smallest license package.

e: well, you don't have to, they have a learning license that consists of a preconfigured virtual machine you load up and swear to God you aren't a business which is what I'm using right now.

vv: also the last thing I used prior was python which is probably why I was so upset :v:

Shugojin fucked around with this message at 17:06 on Jun 18, 2014

ToxicFrog
Apr 26, 2008


Shugojin posted:

I'd like to submit the entirety of SAS. I need to know it to do data analysis because it's worked its way in as a standard tool, but:

  • You can literally put the entirety of your code on one line. It reads the procedures as
  • You can put a comment in the middle of the line and keep going!

This is true of a great many languages; the only one I can think of offhand that I've used that doesn't permit this is Python.

quote:

and of course, the markers for comment blocks cannot be in columns one or two because they may in some (but not all!) cases be interpreted as interrupt commands to stop the program!

That's a new and exciting way to be terrible, though!

fritz
Jul 26, 2003

It's been coming up on 15 years since I had to work with SAS and that's not long enough.

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed

ToxicFrog posted:

This is true of a great many languages; the only one I can think of offhand that I've used that doesn't permit this is Python.
You can have multiple semicolon-separated statements on a single line in Python.

Hiowf
Jun 28, 2013

We don't do .DOC in my cave.

chippy posted:

It's also not very 'pythonic'. Although I'm sure the sort of person that uses that term would probably tell you to do it like this:

code:
toobig = [feature.value for dimension in dimension for feature in dimension if feature.value > threshold]
if len(toobig) > 0:
	return 'failed'
return 'passed'

If we're talking about 'pythonic', you should just write "if toobig".

That said, your code completely fails the requirements because it will process the entire 2-dimensional array even if the condition is violated. I think using a generator instead of a list comprehension may be enough to fix it, if you remove the len() as above. I don't know enough Python internals to be sure if it can short-circuit here, though.

nielsm
Jun 1, 2009



Skuto posted:

If we're talking about 'pythonic', you should just write "if toobig".

That said, your code completely fails the requirements because it will process the entire 2-dimensional array even if the condition is violated. I think using a generator instead of a list comprehension may be enough to fix it, if you remove the len() as above. I don't know enough Python internals to be sure if it can short-circuit here, though.

Python code:
if any(feature.value > threshold for d in dimension for feature in d):
  return 'failed'
else:
  return 'passed'
Like that, I believe.

seiken
Feb 7, 2005

hah ha ha
nonono, to be Pythonic you simply return [feature.value for d in dimension for feature in d if feature.value > threshold] and leave it up to the caller to stick that somewhere truthy

Dr. Stab
Sep 12, 2010
👨🏻‍⚕️🩺🔪🙀😱🙀

Jewel posted:

But apple fixed that (at least with the ipad) where you swipe down with four fingers to bring up the "Apps That Are Open" list, which you can toss them upwards to close them for good, or tap to swap to it.

IMO that's a much better solution because
  • You know what you have open
  • You can close any app without a task manager
  • You can easily swap between apps, ie a browser and a game

How is this different than what's on android, except for the button you use to open the menu?

Hiowf
Jun 28, 2013

We don't do .DOC in my cave.

seiken posted:

nonono, to be Pythonic you simply return [feature.value for d in dimension for feature in d if feature.value > threshold] and leave it up to the caller to stick that somewhere truthy

Still has the problem of evaluating all elements. The post above you pretty much nails it by using any + the generator, which guarantees early exit.

seiken
Feb 7, 2005

hah ha ha

Skuto posted:

Still has the problem of evaluating all elements. The post above you pretty much nails it by using any + the generator, which guarantees early exit.

If you think being "Pythonic" has anything to do with "avoiding problems" you are sorely mistaken!

Munkeymon
Aug 14, 2003

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



quote:

How is this different than what's on android, except for the button you use to open the menu?

Android still has app-related background services that just start and run without any user interaction and you wouldn't know they're there unless you went looking for them in the system menus or installed a process monitoring app. So most Android devices are probably running the Facebook and Google+ services all right now, but going into the recent apps menu won't show that and killing the app won't stop the service (I don't think).

E: oops

Volmarias
Dec 31, 2002

EMAIL... THE INTERNET... SEARCH ENGINES...

Munkeymon posted:

Android still has app-related background services that just start and run without any user interaction and you wouldn't know they're there unless you went looking for them in the system menus or installed a process monitoring app. So most Android devices are probably running the Facebook and Google+ services all right now, but going into the recent apps menu won't show that and killing the app won't stop the service (I don't think).

E: oops

If you really need to care about it, settings -> applications, look at running applications. Usually better than that is to look at what's reporting as using your battery life (although that can be misleading).

If you're still using a 2.2 phone in TYOOL 2014 you deserve everything that happens to you. Just buy a blackberry.

QuarkJets
Sep 8, 2008

seiken posted:

If you think being "Pythonic" has anything to do with "avoiding problems" you are sorely mistaken!

What I hate about "being Pythonic" is that some people are unreasonable and seem to frown on increased readability. For instance, this:

Python code:
my_list = [value for value in x for x in y for y in z]
would be considered by some to be more "Pythonic" than this

Python code:
my_list = [value for value in x
                 for x in y
                 for y in z]
Functionally these are exactly the same, but the first one is all written on a single line and is therefore better for some reason. This becomes way worse when you might have conditions for the various loops. Most Python programmers that I've met would be fine with either version, but gently caress those guys who think that every list comprehension has to be a single line

bobthecheese
Jun 7, 2006
Although I've never met Martha Stewart, I'll probably never birth her child.
So there's a bunch of sql queries in this project, which are built to find specific users for certain promotions (i.e. "currently purchasing item 'x', and previously bought item 'y' in the last 3 months" type poo poo - stuff that marketing has decided is a good idea.)

The way this has been built is that relevant SQL queries get added... to the database... as rows...

Then the code pulls those rows out, and runs them against the database, one by one, to see if the user is due any promotional crap.

The lead dev can't see a single problem with this approach.

ultramiraculous
Nov 12, 2003

"No..."
Grimey Drawer

bobthecheese posted:

So there's a bunch of sql queries in this project, which are built to find specific users for certain promotions (i.e. "currently purchasing item 'x', and previously bought item 'y' in the last 3 months" type poo poo - stuff that marketing has decided is a good idea.)

The way this has been built is that relevant SQL queries get added... to the database... as rows...

Then the code pulls those rows out, and runs them against the database, one by one, to see if the user is due any promotional crap.

The lead dev can't see a single problem with this approach.

:eng99:

Hammerite
Mar 9, 2007

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

QuarkJets posted:

What I hate about "being Pythonic" is that some people are unreasonable and seem to frown on increased readability. For instance, this:

Python code:
my_list = [value for value in x for x in y for y in z]
would be considered by some to be more "Pythonic" than this

Python code:
my_list = [value for value in x
                 for x in y
                 for y in z]
Functionally these are exactly the same, but the first one is all written on a single line and is therefore better for some reason. This becomes way worse when you might have conditions for the various loops. Most Python programmers that I've met would be fine with either version, but gently caress those guys who think that every list comprehension has to be a single line

More or less unrelated, but the order of your "for" clauses is back to front. You'll get a "NameError: name 'x' is not defined" if you try to use that code. (I actually feel it would make a lot more sense if the "for" clauses had to be in the order you've put them in, but the language says otherwise.)

Jewel
May 2, 2009

Huh? I thought that was correct too but on trying it it's not. What's the right way to write that one-liner? I can't work it out for some reason.

Edit: vvv I knew someone was gonna say that when I wrote "right way" :v: You know what I meant; if someone was going to write it in one-line, what's the correct syntax?

Jewel fucked around with this message at 08:26 on Jun 19, 2014

Soricidus
Oct 21, 2010
freedom-hating statist shill

Jewel posted:

Huh? I thought that was correct too but on trying it it's not. What's the right way to write that one-liner? I can't work it out for some reason.
Don't.

seiken
Feb 7, 2005

hah ha ha
That one-liner would be perfectly reasonable if it worked, but python's for clauses have batshit terrible associativity so you can only readably do multiple for clauses in one comprehension when the things you're iterating over are independent of one another.

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
Python code:
[x
 for x in y
 for y in z]
translates to

Python code:
L = []
for x in y:
    for y in z:
        L.append(x)
I'm going to assume that what you want is:

Python code:
L = []
for y in z:
    for x in y:
       L.append(x)
And so:

Python code:
[x for y in z for x in y]
But don't. Seriously. Don't.

nielsm
Jun 1, 2009



Python definitely needs to extend the syntax for for loops to allow constructs like:
for x in y in z

Chin Strap
Nov 24, 2002

I failed my TFLC Toxx, but I no longer need a double chin strap :buddy:
Pillbug
I like Google's Python style guide for list comprehensions:

"Okay to use for simple cases. Each portion must fit on one line: mapping expression, for clause, filter expression. Multiple for clauses or filter expressions are not permitted. Use loops instead when things get more complicated."


Because basically anything more than

[f(x) for x in a if x >= 5]

is just a mess

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
It's certainly one of those features that somebody brought up because "it would be cool" and then they debated it on the mailing list for a while, came up with a "correct solution that's consistent with everything else", but never thought about how dumb and confusing it is.

Python has a lot of those now. It's really disappointing.

Deus Rex
Mar 5, 2005

Suspicious Dish posted:

And so:

Python code:
[x for y in z for x in y]
But don't. Seriously. Don't.

Huh? It's perfectly clear what this does (flattens a list of lists). I'm not really a Python programmer either.

Ersatz Haderach
Aug 1, 2012

Shugojin posted:

I'd like to submit the entirety of SAS. I need to know it to do data analysis because it's worked its way in as a standard tool, but:

I literally started a freelance business to avoid dealing with the shambling abortion that is SAS. Don't forget the lamentable "macro" facility: a language based on the idea that the C preprocessor gave you all the abstraction ability you ever needed.

... or the incredibly high licensing fees. SAS pays "affiliated" consultants kickbacks to push SAS licenses on their customers; it's a business model entirely based on selling hard to the people in an organization with the highest score of (available budget / critical thinking ability) and then locking them in as fast as possible to their unholy PL1/macro-processor hybrid.

e: Shugojin, if you have any choice in the matter and you haven't already, you need to learn R. It's a different kind of shambling abortion, but at least it's a free one and it still works a hell of a lot better than SAS. Imagine a deranged statistician designing a programming language after reading "Structure and Interpretation of Computer Programs" while on a bad acid trip.

Ersatz Haderach fucked around with this message at 13:18 on Jun 19, 2014

Hiowf
Jun 28, 2013

We don't do .DOC in my cave.

Ersatz Haderach posted:

Imagine a deranged statistician designing a programming language after reading "Structure and Interpretation of Computer Programs" while on a bad acid trip.

Maybe it's me but in my imagination the outcome of that sounds like more fun than most of the programming languages we have to deal with.

Disclaimer: I've never programmed SAS.

Ersatz Haderach
Aug 1, 2012

Skuto posted:

Maybe it's me but in my imagination the outcome of that sounds like more fun than most of the programming languages we have to deal with.

Disclaimer: I've never programmed SAS.

R is surprisingly fun, until it's not. The huge number of academics, statisticians, econometricians, whatever writing packages mean that any statistical, machine learning, etc. algorithm you want to play with probably already has a decent implementation in R. And the graphics capability is second to none, especially with some of the better third party packages like ggplot2.

But then sometimes you find yourself reading the documentation for the 10,000 *apply (vapply, mapply, sapply, tapply...) functions for the umpteenth time in an afternoon and wondering where your life went wrong.

Steve French
Sep 8, 2003

Hammerite posted:

More or less unrelated, but the order of your "for" clauses is back to front. You'll get a "NameError: name 'x' is not defined" if you try to use that code. (I actually feel it would make a lot more sense if the "for" clauses had to be in the order you've put them in, but the language says otherwise.)

Holy poo poo, no. I am not experienced with Python and looked at that and thought "no way are pythons list comprehensions that backwards". Speaking of backwards, do you like reading code that way?

Jabor
Jul 16, 2010

#1 Loser at SpaceChem

Deus Rex posted:

Huh? It's perfectly clear what this does (flattens a list of lists). I'm not really a Python programmer either.

It's completely indistinguishible from [x for x in y for y in z]. If you want to flatten something, call a function named "flatten" instead of writing an easy-to-mix-up list comprehension everywhere you want to do it.

Some other code snippets which are "perfectly clear" but should be avoided:

code:
while(!isReady());
code:
/(<([^ >]+)( [^>]*)?>(?1)<\/\2>)/
I'm sure everyone has a few more of their own.

Steve French
Sep 8, 2003

Jabor posted:

It's completely indistinguishible from [x for x in y for y in z]. If you want to flatten something, call a function named "flatten" instead of writing an easy-to-mix-up list comprehension everywhere you want to do it.

Some other code snippets which are "perfectly clear" but should be avoided:

code:
while(!isReady());

code:
/(<([^ >]+)( [^>]*)?>(?1)<\/\2>)/

I'm sure everyone has a few more of their own.

It is most certainly not indistinguishable from that. He was also not saying that's the best way to write that code, just that it is clear what it is doing, which I happen to agree with. It also becomes much more clear when you use reasonable variable names (making some up here):

code:
[user for group in groups for user in group]

Jewel
May 2, 2009

Steve French posted:

It is most certainly not indistinguishable from that. He was also not saying that's the best way to write that code, just that it is clear what it is doing, which I happen to agree with. It also becomes much more clear when you use reasonable variable names (making some up here):

code:
[user for group in groups for user in group]

Sorry, that's still pretty indistinguishable imo. Add user, for group in groups, for user in group.

Compare that to
code:
[user for user in group for group in groups]
which is "Add user, for user in group, for group in groups" which makes total sense even in english.

Especially if you had, for example, "[user.age for user in group" etc.

The worst part is when
code:
[[user for user in group] for group in groups]
is completely valid syntax. This should be parsed the same way with or without the extra comprehension as the result of the outer one.

Hiowf
Jun 28, 2013

We don't do .DOC in my cave.

Jabor posted:

It's completely indistinguishible from [x for x in y for y in z]. If you want to flatten something, call a function named "flatten" instead of writing an easy-to-mix-up list comprehension everywhere you want to do it.

Python has no generic flatten. And that sucks.

See for example:
http://stackoverflow.com/questions/2158395/flatten-an-irregular-list-of-lists-in-python

Deus Rex
Mar 5, 2005


'Flatten' unfortunately means different things to different people. I meant it like the function [[a]] -> [a], not the one that folds an arbitrarily nested list (i.e. a tree) into a list.

Adbot
ADBOT LOVES YOU

Steve French
Sep 8, 2003

Jewel posted:

Sorry, that's still pretty indistinguishable imo. Add user, for group in groups, for user in group.

Compare that to
code:
[user for user in group for group in groups]
which is "Add user, for user in group, for group in groups" which makes total sense even in english.

Especially if you had, for example, "[user.age for user in group" etc.

The worst part is when
code:
[[user for user in group] for group in groups]
is completely valid syntax. This should be parsed the same way with or without the extra comprehension as the result of the outer one.

Setting aside the fact that you must live in a very interesting world where you're completely unable to distinguish between two groups of things that aren't in the same order:

It's more than just some arbitrary ordering where it's hard to remember which is the correct one (which I think might be what you mean when you say "completely indistinguishable"). In one case, the identifier group is used before it is defined. In the other, it isn't. That makes it read completely differently to me, and is exactly why when I first saw the (wrong) code that QuarkJet posted I was in disbelief that Python's list comprehensions would be that bad. Turns out because they're not (but they're still pretty bad).

Flatten is a red herring, it's completely inapplicable to the original code, which wasn't performing a flatten, and doesn't answer the question of whether a nested for comprehension is good or bad or readable or not.

(recursive) flatten would also not work in the following case:

code:
[order for user in users for order in user.orders]
or any number of other ever so slightly more complex situations where a nested for comprehension *might* be suitable.

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