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
coaxmetal
Oct 21, 2010

I flamed me own dad

BonzoESC posted:

does python have both comparator sort and a schwartzian transform sort-by method

the same sort method (either sorted(list) or list.sort(), they do the same thing) can take a key function, which will sort by that key, or a cmp funtion, which specifies a comparator. In general a key is prefered because it's faster. You can also tell it to give the reverse if you want.

Adbot
ADBOT LOVES YOU

coaxmetal
Oct 21, 2010

I flamed me own dad

BonzoESC posted:

"In Python 2.4 and above, both the sorted() function and the in-place list.sort() method take a key= parameter that allows the user to provide a "key function" (like foo in the examples above). In Python 3 and above, use of the key function is the only way to specify a custom sort order (the previously-supported comparator argument was removed)."

i guess that's "the new way" or maybe "the only way" now

well the only way in python 3 I guess. I didn't know they removed it, neither did anyone else I guess, nobody uses python 3 :frogbon:

Zombywuf
Mar 29, 2008

Jonnty posted:

then if you suddenly want to change the natural ordering to specifically width or whatever then you just change it and everything works. simple.

You misspelled ButtCheekSizeComparator.

Shaggar
Apr 26, 2006
should be CheekSizeButtComparator

Jonnty
Aug 2, 2007

The enemy has become a flaming star!

Zombywuf posted:

You misspelled ButtCheekSizeComparator.

i don't really see what your point is, nor do i care

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.

BonzoESC posted:

if you're sorting 'em by the same field that much you put a new method on the object to be compared that returns its sort value and sort by that

and a new method in a good language is much simpler than
Java code:
class AgeComparator implements Comparator{
   
    public int compare(Object emp1, Object emp2){
       
        int emp1Age = ((Employee)emp1).getAge();        
        int emp2Age = ((Employee)emp2).getAge();
       
        if(emp1Age > emp2Age)
            return 1;
        else if(emp1Age < emp2Age)
            return -1;
        else
            return 0;    
    }
   
}

also note that this code is wrong (no offence I know you were writing it fast but it is a good example) you need to check if emp1 or emp2 are null and you need instanceof checks or you will possibly get classcastexceptions (using generics obviously will prevent this, unless you're working w/ an implementation that only takes Comparator and not Comparator<T>). there's probably something else im missing too

Shaggar
Apr 26, 2006
if ur using <java 5 u should probably kill yourself.

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

trex eaterofcadrs posted:

also note that this code is wrong (no offence I know you were writing it fast but it is a good example) you need to check if emp1 or emp2 are null and you need instanceof checks or you will possibly get classcastexceptions (using generics obviously will prevent this, unless you're working w/ an implementation that only takes Comparator and not Comparator<T>). there's probably something else im missing too

i copied it from some .in about java programming, i haven't written java since 2006 and never professionally

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

Shaggar posted:

if ur using java u should probably kill yourself.

skeevy achievements
Feb 25, 2008

by merry exmarx

trex eaterofcadrs posted:

also note that this code is wrong (no offence I know you were writing it fast but it is a good example) you need to check if emp1 or emp2 are null and you need instanceof checks or you will possibly get classcastexceptions (using generics obviously will prevent this, unless you're working w/ an implementation that only takes Comparator and not Comparator<T>). there's probably something else im missing too

ehhhh yeah on one hand it's smart to write defensively

otoh language choice isn't going to save you if you decide to write defensively, you would have to do the same safety checks in Clojure for example

I liked bertrand meter's design by contract ideas back in the day but I don't know if anything came of them

Zombywuf
Mar 29, 2008

Shaggar posted:

if ur using java u should probably kill yourself.

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

Internaut! posted:

ehhhh yeah on one hand it's smart to write defensively

otoh language choice isn't going to save you here, you would have to do the same thing in Clojure for example

programs aren't cars, it's okay to let 'em crash: http://www.multicians.org/unix.html

quote:

We went to lunch afterward, and I remarked to Dennis that easily half the code I was writing in Multics was error recovery code. He said, "We left all that stuff out. If there's an error, we have this routine called panic, and when it is called, the machine crashes, and you holler down the hall, 'Hey, reboot it.'"

this is the big thing in erlang, where instead of making sure your processes never crash, you just set them up (with otp supervision trees) so that when an error happens the process that had the error dies and the system spawns a new process to replace it

Shaggar
Apr 26, 2006
lol @ all the morons who cant figure out java or why its the best

skeevy achievements
Feb 25, 2008

by merry exmarx

BonzoESC posted:

this is the big thing in erlang, where instead of making sure your processes never crash, you just set them up (with otp supervision trees) so that when an error happens the process that had the error dies and the system spawns a new process to replace it

if I'm an IS manager that sounds like a good approach as it lets you maintain an SLA standard and get your bonus at the end of the year even though individual customers are crashing out all over the place every time your lazily written system encounters something slightly unexpected

Toady
Jan 12, 2009

does anyone have any opinions on LISP? thanks

Catalyst-proof
May 11, 2011

better waste some time with you

Toady posted:

does anyone have any opinions on LISP? thanks

oh jesus christ i do :smith:

Shaggar
Apr 26, 2006

BonzoESC posted:

programs aren't cars, it's okay to let 'em crash: http://www.multicians.org/unix.html


this is the big thing in erlang, where instead of making sure your processes never crash, you just set them up (with otp supervision trees) so that when an error happens the process that had the error dies and the system spawns a new process to replace it

ya lets ignore a code defect and just keep restarting. that will make it go away, right? - excerpt from Design Philosophy of PHP

standardtoaster
May 22, 2009
I'm learning to code and the book I'm read said this:

BOOK ON CODING posted:

The computational processes inside the computer are like magical spirits that we can harness for our work. Unfortunately, those spirits only understand a very arcane language that we do not know. What we need is a friendly Genie that can direct the spirits to fulfill our wishes.

Is this accurate?

e. Also this:

BOOK ON CODING posted:

We communicate with the Genie through a special language of spells and incantations.

I had no idea that this is what you guys do.

standardtoaster fucked around with this message at 18:54 on May 29, 2012

gangnam reference
Dec 26, 2010

shut up idiot shut up idiot shut up idiot shut up idiot

standardtoaster posted:


May 22, 2009


I'm learning to code and the book I'm read said this:

quote:

BOOK ON CODING posted:
The computational processes inside the computer are like magical spirits that we can harness for our work. Unfortunately, those spirits only understand a very arcane language that we do not know. What we need is a friendly Genie that can direct the spirits to fulfill our wishes.

Is this accurate?



:effort:

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.

Toady posted:

does anyone have any opinions on LISP? thanks

ya use clojure

vapid cutlery
Apr 17, 2007

php:
<?
"it's george costanza" ?>
Gas

Emacs Headroom
Aug 2, 2003

standardtoaster posted:

Is this accurate?

nah theyre more like daemons than spirits (at least in *nix)

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

Internaut! posted:

if I'm an IS manager that sounds like a good approach as it lets you maintain an SLA standard and get your bonus at the end of the year even though individual customers are crashing out all over the place every time your lazily written system encounters something slightly unexpected


Shaggar posted:

ya lets ignore a code defect and just keep restarting. that will make it go away, right? - excerpt from Design Philosophy of PHP

lol way to make your processes have too much responsibility

if i was parsing an http request header i'd do that in a per-request handler process, so if the header's malformed and puts the parser into a crash state, you can safely throw that request away and let the vm/os handle freeing all its resources

if you've never studied parsers or the architecture of operating systems you probably wouldn't understand this

Shaggar
Apr 26, 2006
if ur writing ur own http request parser ur beyond all help

skeevy achievements
Feb 25, 2008

by merry exmarx
eh I don't think anyone's advocating architectures where bad input from a single user brings down the entire system

just pointing out the user experience of processes crashing is less than optimal

I read that Amazon web services rant like someone suggested and it was interesting, one of the lessons learned was "write your services like you don't trust anyone" and having worked in a couple large teams in my time I don't think it's a bad idea even at the code level

Zombywuf
Mar 29, 2008

standardtoaster posted:

I had no idea that this is what you guys do.

What did you think we were doing with the goat?

double sulk
Jul 2, 2010

The advantage of Python over Java is that it’s less heavyweight, there isn’t a huge syntactic thicket of declarations and codicils and stuff that from a point of view of a Python programmer is extraneous junk that gets in the way of comprehension. There are languages that are much worse that way, see my rant about C++. Java is a bit too syntax-heavy and cluttered for optimum long-term maintainability. That is my opinion anyway.

double sulk
Jul 2, 2010

Yes, I really like Python. I like it for a very specific reason. I like Python because of all the languages I have ever used, it is the one that maximizes ease of long term maintainability. That is, the ease with which you can read your code six months later. The longer I program, the more convinced I am that that is THE most important metric of a language, bar none… Most of the programming I do these days is in either Python or C.

vapid cutlery
Apr 17, 2007

php:
<?
"it's george costanza" ?>

Sulk posted:

The advantage of Python over Java is that it’s less heavyweight, there isn’t a huge syntactic thicket of declarations and codicils and stuff that from a point of view of a Python programmer is extraneous junk that gets in the way of comprehension. There are languages that are much worse that way, see my rant about C++. Java is a bit too syntax-heavy and cluttered for optimum long-term maintainability. That is my opinion anyway.

where's this from

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug
don't post in yospos


Sulk posted:

The advantage of Python over Java is that its less heavyweight

gonna stop you right here because even if you were not sulk the entire concpt of "heavyweight" and "lightweight" in programming is overplayed the gently caress out to the point where it doesn't mean poo poo

if you want to say that python doesn't take two seconds to start like java does just say that

Sulk posted:

Java is a bit too syntax-heavy and cluttered for optimum long-term maintainability.

i actually agree with this though because somebody itt actually said you should have separate files and classes for each kind of sort you want to do

Zombywuf
Mar 29, 2008

BonzoESC posted:

if you want to say that python doesn't take two seconds to start like java does just say that

Python on the other hand takes 11MB, just to start. Urgh.

Hammerite
Mar 9, 2007

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

vapid cutlery
Apr 17, 2007

php:
<?
"it's george costanza" ?>

Zombywuf posted:

Python on the other hand takes 11MB, just to start. Urgh.

it's no lua, that's for sure

Lysidas
Jul 26, 2002

John Diefenbaker is a madman who thinks he's John Diefenbaker.
Pillbug
i don't mind java but it's no python3

and shaggar your point about only changing the single comparator implementation once is a strawman; you can write a single python key function for your objects and change that one function in one place too

Lysidas
Jul 26, 2002

John Diefenbaker is a madman who thinks he's John Diefenbaker.
Pillbug
the best key function is random.random

Shaggar
Apr 26, 2006

Lysidas posted:

i don't mind java but it's no python3

and shaggar your point about only changing the single comparator implementation once is a strawman; you can write a single python key function for your objects and change that one function in one place too

yes and at that point you're effectively using a comparator (except worse by 1000x because its a lovely function) which is what pytards were saying not having to do was a big pro of python (which is obv isnt as you point out)

Shaggar
Apr 26, 2006
functions are for morons who want to spend the extra effort to make maintainable code without actually making maintainable code.

vapid cutlery
Apr 17, 2007

php:
<?
"it's george costanza" ?>

Shaggar posted:

functions are for morons who want to spend the extra effort to make maintainable code without actually making maintainable code.

:staredog:

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.

ya i mean even :staredog: is kinda underwhelming in the face of that comment

Adbot
ADBOT LOVES YOU

Shaggar
Apr 26, 2006
function pointers make me want to vomit

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