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.
 
  • Locked thread
fart simpson
Jul 2, 2005

DEATH TO AMERICA
:xickos:

Python code:
big_butts = []
for butt in butts:
    if butt.is_bug():
        big_butts.append(butt)
is only more clear than

Python code:
big_butts = butts.filter(is_big)
if you have severe stackholm syndrome, and it's not because it only takes up one line

Adbot
ADBOT LOVES YOU

Jerry Bindle
May 16, 2003
i get mad now when i have to use a for loop.

Bloody
Mar 3, 2013

Barnyard Protein posted:

i get mad now when i have to use a for loop.

same

Asymmetrikon
Oct 30, 2009

I believe you're a big dork!
make your code as declarative as possible imo

FamDav
Mar 29, 2008

fart simpson posted:

severe stackholm syndrome

mods?

leper khan
Dec 28, 2010
Honest to god thinks Half Life 2 is a bad game. But at least he likes Monster Hunter.

fart simpson posted:

Python code:

big_butts = []
for butt in butts:
    if butt.is_bug():
        big_butts.append(butt)

is only more clear than

Python code:

big_butts = butts.filter(is_big)

if you have severe stackholm syndrome, and it's not because it only takes up one line

big_butts = [butt for butt in butts where butt.is_big()]

e:
lazy_butts = (butt for butt in butts where butt.is_big())

leper khan fucked around with this message at 16:32 on Mar 10, 2016

The MUMPSorceress
Jan 6, 2012


^SHTPSTS

Gary’s Answer
we're not allowed to use linq expressions in our c# code and no one can give me a good reason why. it's so annoying.

Bloody
Mar 3, 2013

leper khan posted:

big_butts = [butt for butt in butts where butt.is_big()]

:barf:

Bloody
Mar 3, 2013

LeftistMuslimObama posted:

we're not allowed to use linq expressions in our c# code and no one can give me a good reason why. it's so annoying.

you work for a company that uses mumps.

fart simpson
Jul 2, 2005

DEATH TO AMERICA
:xickos:

Bloody posted:

you work for a company that uses mumps.

HappyHippo
Nov 19, 2003
Do you have an Air Miles Card?

fart simpson posted:

Python code:
big_butts = []
for butt in butts:
    if butt.is_bug():
        big_butts.append(butt)
is only more clear than

Python code:
big_butts = butts.filter(is_big)
if you have severe stackholm syndrome, and it's not because it only takes up one line

edit: oops I misread

HappyHippo fucked around with this message at 16:35 on Mar 10, 2016

HappyHippo
Nov 19, 2003
Do you have an Air Miles Card?

leper khan posted:

big_butts = [butt for butt in butts where butt.is_big()]

but which is more ~pythonic~?

fart simpson
Jul 2, 2005

DEATH TO AMERICA
:xickos:

HappyHippo posted:

this is a weird example because the second one is clearly better?

that makes it normal and not weird

HappyHippo
Nov 19, 2003
Do you have an Air Miles Card?

fart simpson posted:

that makes it normal and not weird

yeah for some dumb reason i read that as you arguing for the first one

leper khan
Dec 28, 2010
Honest to god thinks Half Life 2 is a bad game. But at least he likes Monster Hunter.

HappyHippo posted:

but which is more ~pythonic~?

the one guido would do obv

fart simpson
Jul 2, 2005

DEATH TO AMERICA
:xickos:

leper khan posted:

big_butts = [butt for butt in butts where butt.is_big()]

list comprehensions are ok when theyre small but they get more confusing more fast. consider

code:
[c.upper() for string in strings for c in string]
vs a language with something like linq methods

code:
strings.flatten().map(lambda c: c.upper())

leper khan
Dec 28, 2010
Honest to god thinks Half Life 2 is a bad game. But at least he likes Monster Hunter.

fart simpson posted:

list comprehensions are ok when theyre small but they get more confusing more fast. consider

code:

[c.upper() for string in strings for c in string]

vs a language with something like linq methods

code:

strings.flatten().map(lambda c: c.upper())

lol if you haven't had to deal with nested list comprehensions

gonadic io
Feb 16, 2011

>>=
Oh I've written plenty in my time, creating nested lists and such

gonadic io fucked around with this message at 17:30 on Mar 10, 2016

gonadic io
Feb 16, 2011

>>=
Picture http://www.cs.nott.ac.uk/~pszgmh/sudoku.lhs but I didn't bother separating my functions properly and just did nested list comprehensions saving literally some lines of code!

jesus WEP
Oct 17, 2004


HappyHippo posted:

but which is more ~pythonic~?
someone do a broswer extension to replace "pythonic" with "stupid"

brap
Aug 23, 2004

Grimey Drawer

fart simpson posted:

Python code:

big_butts = []
for butt in butts:
    if butt.is_bug():
        big_butts.append(butt)

is only more clear than

Python code:

big_butts = butts.filter(is_big)

if you have severe stackholm syndrome, and it's not because it only takes up one line

drat there's even a bug in the loop version of the code. just proves the point more.

Share Bear
Apr 27, 2004

cmon during code review like you dont catch people copy pasting stuff they clearly dont understand from their other code they came up on their own

write poo poo out and be declarative and name things well, birch

Share Bear
Apr 27, 2004

canonically bad example http://docs.spring.io/spring-framework/docs/2.5.x/api/org/springframework/aop/framework/AbstractSingletonProxyFactoryBean.html

i still dont get why java and java projects are this way

FamDav
Mar 29, 2008
don't use spring hth

leper khan
Dec 28, 2010
Honest to god thinks Half Life 2 is a bad game. But at least he likes Monster Hunter.

FamDav posted:

don't use java hth

ftfy

The MUMPSorceress
Jan 6, 2012


^SHTPSTS

Gary’s Answer

always relevant:
http://java.metagno.me/

Share Bear
Apr 27, 2004

FamDav posted:

don't use spring hth

only work on brand new projects in languages/frameworks of the week, forever, never stopping to maintain

Shaggar
Apr 26, 2006

in spring you have proxies which are interface implementations that are not real implementations, but are instead "proxies" that forward the method calls to the interface on to something that actually handles the implementation. a good example is using CXF soap clients. you specify that a bean is a cxf client and give it the interface and endpoint information and behind the scenes cxf builds a proxy that acts like the interface specified, but behind the scenes sends the requests off to a remote webservice.

one way to generate proxies is using a factory. If implementing your own factory, you would put it into the DI container as a bean.

sometimes the generated proxies are singletons

AbstractSingletonProxyFactoryBean is a base class that handles some of the common tasks related to implementation of a factory bean that generates singleton proxies.

If you don't do actual irl software development this will be confusing because its not your math homework. If you actually do software development then it makes total sense but you probably will never use it ever yourself because its mostly for use by spring and frameworks built upon spring.

HappyHippo
Nov 19, 2003
Do you have an Air Miles Card?

Shaggar posted:

in spring you have proxies which are interface implementations that are not real implementations, but are instead "proxies" that forward the method calls to the interface on to something that actually handles the implementation. a good example is using CXF soap clients. you specify that a bean is a cxf client and give it the interface and endpoint information and behind the scenes cxf builds a proxy that acts like the interface specified, but behind the scenes sends the requests off to a remote webservice.

one way to generate proxies is using a factory. If implementing your own factory, you would put it into the DI container as a bean.

sometimes the generated proxies are singletons

AbstractSingletonProxyFactoryBean is a base class that handles some of the common tasks related to implementation of a factory bean that generates singleton proxies.

If you don't do actual irl software development this will be confusing because its not your math homework. If you actually do software development then it makes total sense but you probably will never use it ever yourself because its mostly for use by spring and frameworks built upon spring.

javas exceptionally poor faculties for abstraction are responsible for this monstrosity

Soricidus
Oct 21, 2010
freedom-hating statist shill

fleshweasel posted:

drat there's even a bug in the loop version of the code. just proves the point more.

the filter version of the code meanwhile isn't python at all, which doesn't prove anything except maybe that it's easy to make things look nice when you don't have to care about real syntax

conversely, here's an actual example of the kind of thing i was talking about :

JavaScript code:
butts.filter(butt => butt.isBig()).forEach(butt => butt.insertProbe())
is not, in my opinion, an improvement on
JavaScript code:
for (let butt of butts) {
    if (butt.isBig()) {
        butt.insertProbe()
    }
}

Bloody
Mar 3, 2013

Soricidus posted:

the filter version of the code meanwhile isn't python at all, which doesn't prove anything except maybe that it's easy to make things look nice when you don't have to care about real syntax

conversely, here's an actual example of the kind of thing i was talking about :

JavaScript code:
butts.filter(butt => butt.isBig()).forEach(butt => butt.insertProbe())
is not, in my opinion, an improvement on
JavaScript code:
for (let butt of butts) {
    if (butt.isBig()) {
        butt.insertProbe()
    }
}
your opinion is wrong

Soricidus
Oct 21, 2010
freedom-hating statist shill

Bloody posted:

your opinion is wrong

you make a compelling argument but i think i'm going to have to stand firm on this issue

The MUMPSorceress
Jan 6, 2012


^SHTPSTS

Gary’s Answer

Soricidus posted:

you make a compelling argument but i think i'm going to have to stand firm on this issue

butts make me firm too

AWWNAW
Dec 30, 2008

Share Bear posted:

only work on brand new projects in languages/frameworks of the week, forever, never stopping to maintain

a good strategy but like musical chairs you gotta be sure your not the last one to leave the party, quit early and often

gonadic io
Feb 16, 2011

>>=

yeah but

JavaScript code:
butts.filter(butt => butt.isBig())
     .forEach(butt => butt.insertProbe())
is better than either of those

Shaggar
Apr 26, 2006
i don't like .forEach

Share Bear
Apr 27, 2004

Shaggar posted:

in spring you have proxies which are interface implementations that are not real implementations, but are instead "proxies" that forward the method calls to the interface on to something that actually handles the implementation. a good example is using CXF soap clients. you specify that a bean is a cxf client and give it the interface and endpoint information and behind the scenes cxf builds a proxy that acts like the interface specified, but behind the scenes sends the requests off to a remote webservice.

time to brew the AbstractSingletonProxyFactoryBean s

seriously, i don't understand why there's that much abstraction for your example of a SOAP client, why does CXF need to build a proxy? why don't you know what you're sending your data to already or what type of interface you're going to be using?

i also do not understand the need for spring in general, but i am not an architect or lead, i will read about it now

Bloody
Mar 3, 2013

Shaggar posted:

i don't like .forEach

.forEach doesn't really exist in c# and i both get why (its purpose is pretty much always to have side effects) and kind of wish it did

Soricidus
Oct 21, 2010
freedom-hating statist shill

gonadic io posted:

yeah but

JavaScript code:
butts.filter(butt => butt.isBig())
     .forEach(butt => butt.insertProbe())
is better than either of those

point taken on the formatting, but otherwise why is it better? it doesn't state the algorithm any more clearly than the loop version, and its performance is less predictable unless you have intimate knowledge of the optimisations provided by every relevant runtime.

Adbot
ADBOT LOVES YOU

Bloody
Mar 3, 2013

the performance is obviously going to be linear in both cases idk how that isn't clear

  • Locked thread