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
DONT THREAD ON ME
Oct 1, 2002

by Nyc_Tattoo
Floss Finder

Blert the Duck posted:

learn algos in python you'll hate life a lil less

i cast smoke grenade POOF

what's the point of even doing an algo in python

Adbot
ADBOT LOVES YOU

Valeyard
Mar 30, 2012


Grimey Drawer

USSMICHELLEBACHMAN posted:

what's the point of even doing an algo in python

python is a language designed to be relatively good at computations!

DONT THREAD ON ME
Oct 1, 2002

by Nyc_Tattoo
Floss Finder
yeah but it's like what's the point of dealing with things like stacks and linked lists when you're using a language that doesnt have pointers

Valeyard
Mar 30, 2012


Grimey Drawer

USSMICHELLEBACHMAN posted:

yeah but it's like what's the point of dealing with things like stacks and linked lists when you're using a language that doesnt have pointers

it may not have pointers but you could pull of stack and linked list implementations if you want

most languages aim to be versatile i suppose. just because you could do somethign better in C doesnt mean you always have the option to do it in C

gonadic io
Feb 16, 2011

>>=

USSMICHELLEBACHMAN posted:

what's the point of even doing an algo in python

exactly the same point as doing it in any other language:
:nws: http://goatkcd.com/722/ :nws:

DONT THREAD ON ME
Oct 1, 2002

by Nyc_Tattoo
Floss Finder

Valeyard posted:

it may not have pointers but you could pull of stack and linked list implementations if you want

most languages aim to be versatile i suppose. just because you could do somethign better in C doesnt mean you always have the option to do it in C

it's not that it's better in c it's just that if someone told me to make a stack in python i'd use an array

i mean it's fine for learning the broad concepts but trying to reason about space efficiency in a language without memeory management or trying to reason about time efficiency in a language where the details of array.pop are entirely unknown to you is impossible.

like you can just say 'well let's ignore all the trivial details' which is fine and sitll works and you can learn just fine but it bothered me too much


plus implementing all my own data structures in c and then using those structures while i was learning algos was very fun and satisfying

DONT THREAD ON ME fucked around with this message at 23:37 on Jul 10, 2014

Valeyard
Mar 30, 2012


Grimey Drawer

USSMICHELLEBACHMAN posted:

it's not that it's better in c it's just that if someone told me to make a stack in python i'd use an array

i mean it's fine for learning the broad concepts but trying to reason about space efficiency in a language without memeory management or trying to reason about time efficiency in a language where the details of array.pop are entirely unknown to you is impossible.

like you can just say 'well let's ignore all the trivial details' which is fine and sitll works and you can learn just fine but it bothered me too much


plus implementing all my own data structures in c and then using those structures while i was learning algos was very fun and satisfying

lol at caring about space complexity!!

Soricidus
Oct 21, 2010
freedom-hating statist shill

USSMICHELLEBACHMAN posted:

it's not that it's better in c it's just that if someone told me to make a stack in python i'd use an array
that's a sensible design used in many popular libraries, and how i'd do it in c as well. what else would you do? linked lists are a poor naive approach, and anything else is overcomplicated.

in fact there are lots of interesting data structures that can be implemented on top of arrays. for example, heaps are a type of binary tree that's often implemented using a flat array. a nice sample implementation may be found in the standard heapq library that ships with python.

DONT THREAD ON ME
Oct 1, 2002

by Nyc_Tattoo
Floss Finder

Soricidus posted:

that's a sensible design used in many popular libraries, and how i'd do it in c as well. what else would you do? linked lists are a poor naive approach, and anything else is overcomplicated.

in fact there are lots of interesting data structures that can be implemented on top of arrays. for example, heaps are a type of binary tree that's often implemented using a flat array. a nice sample implementation may be found in the standard heapq library that ships with python.

there's nothing wrong with using an array it just hides a lot of details that are very relevant to you if you're taking a data structures/algo class

it's like cheating

Symbolic Butt
Mar 22, 2009

(_!_)
Buglord

USSMICHELLEBACHMAN posted:

it's not that it's better in c it's just that if someone told me to make a stack in python i'd use an array

i mean it's fine for learning the broad concepts but trying to reason about space efficiency in a language without memeory management or trying to reason about time efficiency in a language where the details of array.pop are entirely unknown to you is impossible.

like you can just say 'well let's ignore all the trivial details' which is fine and sitll works and you can learn just fine but it bothered me too much


plus implementing all my own data structures in c and then using those structures while i was learning algos was very fun and satisfying

what defines a data structure are its properties, not its implementation. a stack is a sequential container thing that you can push and pop. a queue has push and popleft. that's it, with a loop and this stuff you can already implement a bunch of graph search algorithms.

I'm not saying that the low level pointer C stuff isn't important, it sure is, but it's something kind of independent from the theory.

FamDav
Mar 29, 2008

Symbolic Butt posted:

what defines a data structure are its properties, not its implementation. a stack is a sequential container thing that you can push and pop. a queue has push and popleft. that's it, with a loop and this stuff you can already implement a bunch of graph search algorithms.

I'm not saying that the low level pointer C stuff isn't important, it sure is, but it's something kind of independent from the theory.

wait til you tell him data structures also dont need mutability

Dessert Rose
May 17, 2004

awoken in control of a lucid deep dream...
i was giving someone an interview question where i wanted them to implement a linked list where the forward pointer points two items ahead

they decided to use C for it, which I thought was an interesting choice because up until then the interview had been about C#

Dessert Rose
May 17, 2004

awoken in control of a lucid deep dream...
i thought maybe they would pull out some amazing C knowledge or something but no, they fell down at "insert a node" when i was able to take apart their implementation simply by repeatedly asking the questions "what if the list has four elements?" "what if the list has five elements?" "what if the list has four elements?"

they constantly broke the other case when fixing it for the current question. i was pretty sad.

Luigi Thirty
Apr 30, 2006

Emergency confection port.

let me tell you about going from python to C with classes (because nothing else from c++ fits in memory) on my arduino

pointers to arrays of pointers to c-strings... the horror...

Moist von Lipwig
Oct 28, 2006

by FactsAreUseless
Tortured By Flan
im actually preferring c++ to python and im pretty sure that indicates deep mental illness from what ive read

Star War Sex Parrot
Oct 2, 2003

writing a skip list in C++ was fun

Blert the Duck
Sep 23, 2008

sorry i meant use python over java/c# if you are learning this stuff on your own and you don't know java/c#. why not use a more readable lang if you're going to use a high level lang? sure java/c# are plenty readable but python is dang close to pseudocode. for learning you'll get less headaches with python i think.

learning in c will give you a better understanding of how computer work but you need to learn c before you learn data structs + algos.

learn you some pointers and you'll never be confused by why your java obj is getting mutated when it supposed to be a pass by value language!!!

e: removed thing more suited to that other programming thread

Blert the Duck fucked around with this message at 14:18 on Jul 11, 2014

Pie Colony
Dec 8, 2006
I AM SUCH A FUCKUP THAT I CAN'T EVEN POST IN AN E/N THREAD I STARTED

Soricidus posted:

that's a sensible design used in many popular libraries, and how i'd do it in c as well. what else would you do? linked lists are a poor naive approach, and anything else is overcomplicated.

in fact there are lots of interesting data structures that can be implemented on top of arrays. for example, heaps are a type of binary tree that's often implemented using a flat array. a nice sample implementation may be found in the standard heapq library that ships with python.

how are linked lists a poor naive approach for a stack? they literally implement a stack almost trivially, and are the way stacks are generally written in functional PLs (and even python)

Pie Colony fucked around with this message at 21:43 on Jul 11, 2014

Pie Colony
Dec 8, 2006
I AM SUCH A FUCKUP THAT I CAN'T EVEN POST IN AN E/N THREAD I STARTED

USSMICHELLEBACHMAN posted:

it's not that it's better in c it's just that if someone told me to make a stack in python i'd use an array

i mean it's fine for learning the broad concepts but trying to reason about space efficiency in a language without memeory management or trying to reason about time efficiency in a language where the details of array.pop are entirely unknown to you is impossible.

like you can just say 'well let's ignore all the trivial details' which is fine and sitll works and you can learn just fine but it bothered me too much


plus implementing all my own data structures in c and then using those structures while i was learning algos was very fun and satisfying

you realize that when people talk about space and time complexity (i'm assuming you mean complexity, not efficiency), they are not talking about individual bytes or seconds but how something performs relative to the input size, right? if by arrays you mean lists, pop() is defined (and even documented) to be an O(1) operation

Soricidus
Oct 21, 2010
freedom-hating statist shill

Pie Colony posted:

how are linked lists a poor naive approach for a stack? they literally implement a stack almost trivially, and are the way stacks are generally written in functional PLs (and even python)
oh, in functional pls they're a good choice, yes, because they fit the paradigm. functional arrays can be complicated.

in imperative pls though they're not so great. they have their place, java's linkedhashmap is a fine example, but if you're not adding/removing elements from the middle then vectors tend to be both faster and smaller, which is why java etc use them rather than linked lists for their stacks.

in particular I don't think I've ever seen a use of a linked list in python where a regular built-in list (i.e. vector) would not have been a better choice. I'm sure such cases exist but they'll be very situational.

Soricidus fucked around with this message at 22:01 on Jul 11, 2014

gonadic io
Feb 16, 2011

>>=
if you're adding and removing elements from the middle then you're not using a stack. Linked lists are the best stack implementation regardless of the language you're working in, you don't get to just say "oh well idk how things are in ~fp land~" to dismiss the point Pie Colony made.

BONGHITZ
Jan 1, 1970

FamDav posted:

wait til you tell him data structures also dont need mutability

:2bongs:

Soricidus
Oct 21, 2010
freedom-hating statist shill

AlsoD posted:

if you're adding and removing elements from the middle then you're not using a stack. Linked lists are the best stack implementation regardless of the language you're working in, you don't get to just say "oh well idk how things are in ~fp land~" to dismiss the point Pie Colony made.
I didn't say that. I have used fp languages and am familiar with the advantages of linked lists in that context. and I brought up doing poo poo in the middle of the list as an example of when linked lists are appropriate, ie not for stacks.

my point, which you don't get to dismiss like that, is: if linked lists are the best stack implementation, why don't java, c++, etc. use them? hint: it's not because you're smarter than the experts who designed their libraries.

MeruFM
Jul 27, 2010
isn't it because they're not making a pure linked list?

Arcsech
Aug 5, 2008

Soricidus posted:

I didn't say that. I have used fp languages and am familiar with the advantages of linked lists in that context. and I brought up doing poo poo in the middle of the list as an example of when linked lists are appropriate, ie not for stacks.

my point, which you don't get to dismiss like that, is: if linked lists are the best stack implementation, why don't java, c++, etc. use them? hint: it's not because you're smarter than the experts who designed their libraries.

what implementation is significantly better for a pure stack (ie one that only implements push and pop and is never accessed in the middle) than a linked list

Arcsech fucked around with this message at 23:20 on Jul 11, 2014

Malcolm XML
Aug 8, 2009

I always knew it would end like this.

AlsoD posted:

if you're adding and removing elements from the middle then you're not using a stack. Linked lists are the best stack implementation regardless of the language you're working in, you don't get to just say "oh well idk how things are in ~fp land~" to dismiss the point Pie Colony made.

nah they dont have good cache locality

DONT THREAD ON ME
Oct 1, 2002

by Nyc_Tattoo
Floss Finder

Arcsech posted:

what implementation is significantly better for a pure stack (ie one that only implements push and pop and is never accessed in the middle) than a linked list

i dont think that making your stack implementation 'pure' is a goal when u make a programming language

i'm just spitballing here but i'd imagine that there are a lot of things you can do to optimize basic data structures even if you don't expose those details to the user

but i am a very bad programmer. possibly the worst

ComradeCosmobot
Dec 4, 2004

USPOL July

Malcolm XML posted:

nah they dont have good cache locality

never mind that you have to carry around pointers with every data element which you don't have to do with a vector and a pointer to the top of said "stack"

then you only have to worry about reallocating a vector if your stack grows too large

same goes for queues if you can tolerate a hard cap on the number of items in the queue just loop over the spaces in the vector to save the pointers and keep cache locality on the items in your queue

i mean, it's not like your call stack is implemented as a linked list

Arcsech
Aug 5, 2008

USSMICHELLEBACHMAN posted:

i dont think that making your stack implementation 'pure' is a goal when u make a programming language

i'm just spitballing here but i'd imagine that there are a lot of things you can do to optimize basic data structures even if you don't expose those details to the user

but i am a very bad programmer. possibly the worst

Oh yeah no by pure I meant that you only have to implement those two functions so it should allow you to do more under the hood optimization not less

Although I did mean if you don't want to preallocate a shitload of memory for a stack that may be tiny or might be huge. As an embedded developer I'd implement a stack as an array because I have to manage all the memory super tightly anyway but if you're not on a $0.25 uC you tend to use different techniques

Nomnom Cookie
Aug 30, 2009



ComradeCosmobot posted:

never mind that you have to carry around pointers with every data element which you don't have to do with a vector and a pointer to the top of said "stack"

then you only have to worry about reallocating a vector if your stack grows too large

same goes for queues if you can tolerate a hard cap on the number of items in the queue just loop over the spaces in the vector to save the pointers and keep cache locality on the items in your queue

i mean, it's not like your call stack is implemented as a linked list

it actually is though if you have frame pointers

Nomnom Cookie
Aug 30, 2009



Arcsech posted:

what implementation is significantly better for a pure stack (ie one that only implements push and pop and is never accessed in the middle) than a linked list

are you loving serious. are you so loving clueless that you made this post

gently caress

DONT THREAD ON ME
Oct 1, 2002

by Nyc_Tattoo
Floss Finder

Kevin Mitnick P.E. posted:

are you loving serious. are you so loving clueless that you made this post

gently caress

as an interloper in the terrible programmer thread the impetus is on you to explain why someone might be a bad programmer and help them out a little in a nice way. this kind of posting is contrary to the spirit of the thread

Pittsburgh Fentanyl Cloud
Apr 7, 2003


USSMICHELLEBACHMAN posted:

as an interloper in the terrible programmer thread the impetus is on you to explain why someone might be a bad programmer and help them out a little in a nice way. this kind of posting is contrary to the spirit of the thread

His emotionally-stunted baby is being raised by an iPad. lol

Forums Terrorist
Dec 8, 2011

why is tori here no one mentioned The City

DONT THREAD ON ME
Oct 1, 2002

by Nyc_Tattoo
Floss Finder

Forums Terrorist posted:

why is tori here no one mentioned The City

because this thread is the pitts

Pittsburgh Fentanyl Cloud
Apr 7, 2003


Forums Terrorist posted:

why is tori here no one mentioned The City

I have to post in every thread. Thanks and god bless.

pseudorandom name
May 6, 2007

Kevin Mitnick P.E. posted:

it actually is though if you have frame pointers

and also if your language uses split stacks

Luigi Thirty
Apr 30, 2006

Emergency confection port.

huh. i got an email from an amazon recruiter wanting to schedule a phone interview for something I applied for a year and a half ago that I'm not very good at

i don't really want to leave the state anymore but whatever let's see where it goes

Soricidus
Oct 21, 2010
freedom-hating statist shill

pseudorandom name posted:

and also if your language uses split stacks
not in the sense that push == cons, though. at the subroutine level, the stack is going to be an array.

Adbot
ADBOT LOVES YOU

MeruFM
Jul 27, 2010

Luigi Thirty posted:

huh. i got an email from an amazon recruiter wanting to schedule a phone interview for something I applied for a year and a half ago that I'm not very good at

i don't really want to leave the state anymore but whatever let's see where it goes

you probably don't want to go to amazon anyways

  • Locked thread