Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
@tarun93
void swap(int* a, int* b) {
int tmp = *a;
*a = *b;
*b = tmp;
}
int a = 3, b = 5;
swap(&a, &b); -
micfort1377yI have seen this multiple times on devRant now and every time it makes me. Cringe, because of the implementation of python it actually uses an extra nameless variable. It creates an tuple En destroys that tuple again. So yeah you don't have to define an extra variable, but it actually uses more memory and uses more operations. So it doesn't have to be beter than in any other language.
-
PRein11867y@micfort so? It's about readability and ease of writing the code.
I don't care about a few instructions or a few bytes of memory.
It matters when I'm working on embedded stuff.. but then I'm rather forced to use c (wich I also like actually). -
@PRein no one's denying python's readability. But when a problem like this asks you to swap two variables without using a 3rd, the lesson you're learning is to respect memory. That statement in python does not. The C code does.
Obviously in most real life situations this does not matter. But it does in some. -
micfort1377y@PRein sure, I can agree on that. But in any language that support reference parameters or in out parameters you can simple define a function that swaps 2 values. That is not difficult, and even c++ has a function in the standard library named swap. So the whole argument is kinda ridiculous.
Meanwhile, how often do you actually swap variables? Seriously??
I do it in for example implementing quick sort, and it ends very fast there. -
@qookie my favourite so far.
I’d rather have the register names than A and B but I’m sure your assembler is handling that.
makes me laugh every time 😂
joke/meme