Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Programming advice: DRY

Name: Anonymous 2016-10-07 0:29

Don't Repeat Yourself

Coding tip for y'all: Don't Repeat Yourself.

you can't even *call* a function twice. you have to use map
map(f,[x,y]);
much much beter and more functional than
f(x); f(y);

Name: Anonymous 2016-10-07 1:04

I complained because my coworker used map more than once.

Name: Anonymous 2016-10-07 1:24

>>1
you can't even *call* a function twice
Then you might as well not even bother with functions at all. The whole point of functions is so that you can write a routine once and use it at multiple points throughout your program. If you only call a function once, you're better off just writing it inline, and just using a set of temp variables in the parent namespace to avoid the unnecessary malloc/dealloc on the stack.

Name: Anonymous 2016-10-07 2:52

map(f,[x,y]);
13 characters
f(x); f(y);
11 characters

nice try

Name: Anonymous 2016-10-07 3:34

>>3
just writing it inline
That would be premature optimization. What if in the future you'll need it again?

Name: delete meta 2016-10-07 4:20

>>3
malloc dealloc on the stack
:QUEER LOOKING FACE:

Name: Anonymous 2016-10-07 5:34

>>3
You seem to be missing the fact that >>1 made it a requirement that no function would be used more than once. So it's not a premature optimization. If any decision in software development is "premature optimization" and therefore CONSIDERED HARMFUL, then we'd never get anywhere with anything.

>>6
What meme is this?

Name: Anonymous 2016-10-07 5:49

then we'd never get anywhere with anything.
We got here and now. Premature optimizers are still constructing their assembler sand castles.

Name: Anonymous 2016-10-07 7:51

>>3
malloc
on the stack

Name: Anonymous 2016-10-07 10:57

>>1
The whole point of functions is so that you can write a routine once and use it at multiple points throughout your program.

Yeah, but instead of typing it out every time you just list all those places (or, rather, the data it should operate) once, right after defining it. Recursion is handled by explicit use of y-combinator or something.

That would make quite an interesting esolang I think.

Name: Cudder !cXCudderUE 2016-10-07 11:13

>>10
You just reinvented table-driven programming.

Name: Anonymous 2016-10-07 12:22

>>9
I was using the term loosely, malloc stands for Memory ALLOCation, and I was using it in that sense. There's nothing about the term "malloc" that implies anything to do with the heap, it just works out that way because most stack memory management in C is handled automatically by the function/scope mechanism.

Name: Anonymous 2016-10-07 14:03

>>12
'malloc' generally implies the call to malloc()[/spoiler] function. stack allocation is completely different beast as at heart it's just moving a stack pointer in a desired direction while [spoiler]malloc()[/spoiler] is much more expensive because of the more complex heap-related data structures (how much more expensive they are depends on the allocator you're using) as well as the need to occasionally use a syscall ([spoiler]brk()[/spoiler] on Linux). unless memory restrictions are very strict, you shouldn't care that much about a stack frame or two but you certainly should avoid too many [code]malloc()[/spoiler] and [code]free() calls

Name: Anonymous 2016-10-07 14:04

>>13
why the fuck did I write spoiler instead of code?

Name: Anonymous 2016-10-07 14:17

>>14
Bigger question is how you managed to make text wrap fail so hard.

Name: Anonymous 2016-10-07 14:19

>>15
it seems that it doesn't wrap within code blocks
test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test testtest test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test testtest test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test testtest test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test testtest test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test

Name: Anonymous 2016-10-07 14:53

>>1

Can I rename functions with a construct, which mutates after each call. E.g.:

f(x); mutate0(f,g); g(y); mutate1(g,h); h(z)

See I didn't have to repeat myself and such a feature is possible in say lisp and with a bit more pain in scheme.

Name: Anonymous 2016-10-07 18:04

>>14
I once wrote [prog] instead of [code]

Name: Anonymous 2016-11-29 8:04

>>13
Stack allocation may be fast, but it still uses some resources. If each subroutine will be called only once, and you know that the total amount of live variables will never be bigger than say 16 bytes, you can allocate that amount of memory on the stack upon entering main(), and implement all subroutines as code blocks or macros within main(). Granted, there's very few situations in which this kind of optimization would actually be worthwhile.

Name: Anonymous 2016-11-29 11:54

>>13
The standard doesn't mention stack and heap allocation. Malloc may as well do stack allocation.

Name: Anonymous 2016-11-29 12:55

Why shouldn't I? In op's example, sequental function calls are better than dealing with overhead from using map.
In c i'd better use macro anyway.

Don't Repeat Yourself
And what's the purpose? Each programming style provides it's advantages, but I can't see any arguments about why shouldn't I fucking repeat the function calls. It's just retarded.

Name: Anonymous 2016-11-29 21:18

DUBS

Name: Anonymous 2016-11-29 21:20

Don't Repeat Yourself

Coding tip for y'all: Don't Repeat Yourself.

He repeated himself

Name: Anonymous 2016-11-29 22:14

>>19
That's just a special case of inlining.

Name: Anonymous 2016-11-30 2:04

Allocate my anus

Name: Anonymous 2016-11-30 4:45

>>25
anus_t *anusallocator(void) {
return (anus_t *) malloc(sizeof(my anus));
}

Don't change these.
Name: Email:
Entire Thread Thread List