[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y ] [Home]
4chanarchives logo
/dpt/ - Daily Programming Thread
Images are sometimes not shown due to bandwidth/network limitations. Refreshing the page usually helps.

You are currently reading a thread in /g/ - Technology

Thread replies: 255
Thread images: 20
File: 1448380572619.jpg (298 KB, 1516x810) Image search: [Google]
1448380572619.jpg
298 KB, 1516x810
Previous thread at >>51538850

What are you working on, /g/?
>>
First for garbage collection is not a bad thing
>>
>>51543905
Debatable, but it's undeniable that the shit that goes along with needing garbage collection (i.e. willy-nilly use of the heap) is very bad for performance.
>>
First for GC is shit.
>>
>>51543905
It's not a good thing either.
>>
First for "C memory model"!
>>
>>51543920
True. I can allocate memory on the heap like crazy in C and get code that is slower than allocating on the stack, but it's easier to do so in a language like Java where FUCKING EVERYTHING IS ON THE HEAP.

>>51543928
I disagree, a scripting language without managed memory would be a nightmare. Stuff like node.js have proven that you don't need blazing speeds at all times. GC works fine for stuff like web server backend. Not everything is an embedded device.
>muh 8GB RAM
>>
>>51543959
>I disagree, a scripting language without managed memory would be a nightmare. Stuff like node.js have proven that you don't need blazing speeds at all times. GC works fine for stuff like web server backend. Not everything is an embedded device.
All you're saying is that it's okay that it's bad, not that it's not bad. Which is fair enough, in many scenarios. But >>51543928 is still right.
>>
Is allocating on heap bad due to cache misses?
>>
>>51543974
first
>>
>>51543905
While I like not having to worry about memory, I can see where being forced to use garbage collection is a bad idea.
>>
>>51543959
method-scope varibles and references are on the the stack. you should be wary of allocating too much on the stack regardless of the language
>>
>>51543878
>muh white pride
>>>/pol/
>>>/stormfront/
>>>/out/

or, if you really want to learn,
>>>/his/
>>
>>51543991
you aren't really forced to. only objects that go unused (with no reference pointing to them) get garbage collected. there is nothing that says that you have to instantiate millions of useless little objects unless you're a "muh functional" fundamentalist that demands immutable everything.
>>
>>51543973
I'm saying that the trade off of speed vs. ease of use is worth it in many cases.
Everything has its downsides. (even manual memory management!)

>>51543991
It's hard to create a memory model that allows for sometimes garbage collection. The problem with Rust is that 60% of your code is worrying about the memory model. Programming is about solving problems and writing algorithms.

>>51543994
I'm not being black and white about when you allocate on the stack or the heap, obv. not going to be allocating 10 MB on the stack or something.
>>
>>51544023
This is not how functional programming works retard.
>what are compiler optimisations
>>
>>51543974
That's one reason. There's also overhead associated with heap allocation/deallocation calls, especially to system calls like malloc or free.

>>51543994
Tail call optimization helps to mitigate this a lot.

>>51544023
Here we go.

>>51544028
>Programming is about solving problems and writing algorithms.
Programming is about telling computers to do things. Computer science is about solving problems and writing algorithms.
>>
>>51543878
jews are currently marrying 40% non-jews, the jewish race will be extinct within 100 years
>>
>>51543996
Fuck off.
Jews hating whites is as bad as Chinese hating japs, or whites hating blacks.

But that's not the right pic for a /dpt/...
>>
>>51543905
People who want to return back to the era where Gc were marginal are the amish of computer science. I urge the programming literates of dpt to fight a such stupid ideology at any cost.
>>
>>51544045
>Tail call optimization helps to mitigate this a lot.
i wasn't even talking about recursion you memer. if you're using objects of meaningful size or quantity then you should be allocating them on the heap regardless.
>>
>>51544050
/pol/ is working hard to reduce that to 10.
>>
>>51544050
Except Jewish genes are not recessive.

But then again, THIS DOESN'T BELON ON /g/
>>
>>51544073
>i wasn't even talking about recursion you memer.
Recursion is an area where you need to be wary about putting too much on the stack, so it's relevant.

>if you're using objects of meaningful size or quantity then you should be allocating them on the heap regardless.
This is true, but you should be being more careful than just newing a bunch of objects and hoping that they end up close to each other in memory.
>>
Is it bad to reschedule an interview if you don't feel ready?
>>
>>51544070
>Jews hating whites is as bad as Chinese hating japs, or whites hating blacks.
>Chinese hating japs
what? they are in their right to hate the fucking japanese.
I hope the chinese enslave the japoshits and/or wipe them from the face of earth, japoshits are truly scum
>>
>>51544070
>whites hating x is as bad as x hating whites
ahahahaha
>>
>>51544125
I thought he meant it as chinese-hating japs, like the japs are the ones that hating chinese.
>>
>>51544124
Do you think you'll feel ready next time?
>>
>>51543425
>python3 static typing
SAUCE???
>>
>>51544050
Sure but Jewish wifes kekold their non-Jewish husband with Jewish lover when it's time to procreate
>>
Friendly reminder that there is no reason for heap allocation and there will never be.
>>
>>51544150

A week or two would certainly help.
>>
how should i go about caching api data?

It's from the riot games api, using php. I made my own wrapper since other wrappers on the dev site looked shit and out of date
>>
>>51544146
oh, right, I probably misread

>>51544153
py 3.5
>>
>>51544180
You say that now, the situation probably wont change unless the interview was sprung on you early.
>>
>>51544163
Technically, the stack is allocated on the heap, mate.
>>
>>51544163
>>
>>51544182
>riot games api
Try on Agdg, we don't do game Dev here
>>
>>51544200
Technically you're completely incorrect about that.
>>
>>51544203
Except that I am serious.

>>51544200
I don't think you know what heap is.
>>
friendly reminder that if your program touches L3 cache, you're scum
>>
>>51544219
>>51544222
>what is assembly
>>
>>51544207
i don't even play the game anymore, it was just an idea for something to write code on. Literally the fact it's a game api has nothing to do with anything. I'll try agdg anyway.
>>
>>51544200
Nope. Stack is virtual memory as heap but they are two different concepts/data structures.
>>
>>51544222
>Except that I am serious.
Explain to me how you would allocate an abstract-syntax-tree on the stack or in static memory.
>>
File: zakheim.png (138 KB, 327x422) Image search: [Google]
zakheim.png
138 KB, 327x422
>>51544050
Word.
>>
>>51544028
>memory model
the C memory model by any chance?
>>
>>51544246
Allocate an static array/stack of nodes or with recursion (see the meta circular interpreter in sicp for an example)
>>
File: logo-and-text.png (18 KB, 396x120) Image search: [Google]
logo-and-text.png
18 KB, 396x120
>>51544073
> what is TCO
If a function call is in tail position, the current stack frame won't be needed once it is entered and thus can be optimized out. It doesn't matter if it is the same function or not. Sadly, not that many languages succeed at that. Look how every form in http://docs.racket-lang.org/reference/if.html exploits non-recursive TCO according to the description !
>>
>>51544219
>>51544243
>I don't know how computers work
back to homescreen general!
>>
>>51544224
But
1. everything is first load into l3
2. parallel multi threading requires the use of l3
>>
>>51544343
The loading isn't done by your program
If you need multiple threads, you're scum
>>
>>51544313
>meme language
>>
>>51544246
Why necessarily an abstract-syntax-tree? Do you also want to make a compiler for you maybe?

In any case, here it is (I did not test it).

struct bintree
{
struct bintree *left, *right;
};

void
allocNode (struct bintree *node, int right, void (*callback)(struct bintree *, void *), void *arg)
{
struct bintree newNode = {0};
if (node && right)
node->right = &newNode;
else if (node)
node->left = &newNode;
callback (&newNode, arg);
}

void
callback (struct bintree *newNode, void *arg)
{
int *i = arg;
if (i[0]--)
allocNode (newNode, 0, callback, i);
}

int
main (void)
{
int i = 100; /* create 100 new nodes */
allocNode (0, 0, callback, &i);
return 0;
}
>>
File: 1448568355127.jpg (3 MB, 2560x2880) Image search: [Google]
1448568355127.jpg
3 MB, 2560x2880
>>51544370
>that fucking code
>>
File: 1445721041778.png (692 KB, 963x720) Image search: [Google]
1445721041778.png
692 KB, 963x720
>>51544387
W-What's wrong with it?

And why is she smiling? She just broke them.
>>
>>51544291
>Allocate an static array/stack of nodes
But then they would be limited in # of allocations, AND you would essentially be implementing your own heap.

>with recursion
>>51544370
What's the point of complicating your code with callbacks when a heap suffices?
What if I was writing a compiler and I wanted to write a desugaring routine that converts 'let x = e1 in e2' into '(\x -> e2) e1'. With recursion I wouldn't be able to deallocate my 'let' construct.
>>
File: guile-logo.png (14 KB, 399x232) Image search: [Google]
guile-logo.png
14 KB, 399x232
>>51544361
Glad I learned you something son right? You too thought tail call was all about recursion eh? Now excuse me while I sit back and enjoy the practical software freedom I worked hard for
>>
>>51544446
>What if I was writing a compiler and I wanted to write a desugaring routine that converts 'let x = e1 in e2' into '(\x -> e2) e1
This has nothing to do with using a heap or not, but you typically wouldn't want to do that. You'd actually be better off going the other way, since let-expressions are basically explicit substitutions.
>>
>>51544456
>learned you something
memecuks actually believe this
>>
>>51544456
>practical software
bwahahahaha
>>
>>51544479
go away you aussie shit poster
>>
>>51544497
>memes
>>
>>51544456
>You too thought tail call was all about recursion eh?
They are? Reusing parts of the stack doesn't make the calls non-recursive.
>>
File: guixsd-logo-lighttext.png (22 KB, 450x400) Image search: [Google]
guixsd-logo-lighttext.png
22 KB, 450x400
>>51544479
Sure thing, my pleasure. Have fun in your imperfect world.
>>
>>51543878
>Jews know exactly why the world despises them

why so anti-Semitic goy- I mean guy?
>>
>>51544521
>OH SHIT I CANT INTO READING COMPREHENSION
Tail call optimisation can also apply when function a calls totally unrelated function b in tail position, read up it's simple and satisfying. Recursive functions are still recursive, non recursive functions are still non recursive and everyone wins (stack space) for once
>>
>>51544575
I suppose so. To be fair, it's only really a big deal when recursion is in the picture.
>>
File: kid-programming-a-robot.png (155 KB, 478x439) Image search: [Google]
kid-programming-a-robot.png
155 KB, 478x439
>>51544496
Your mom could only do so much last night. Simple and consistent syntax is best for ladies
>>
>>51544370
heap-fags got btfo
>>
Jews practically invented capitalism.
Why do you hate freedom? :^)
It's ironic that people hate Jews, but love to profit from their legacy.
>>
>>51544575
The best part about complete TCO is that it works with indirectly tail-recursive functions without having to actually scope out and identify these recursions.
e.g.
(define (f x)
(g (/ x 2)))
(define (g x)
(if (< x 1)
x
(f (+ x 1))))
>>
>>51544608
Please m8

Freetard is already shitposting, dont start too
>>
>>51544153
If you want statically typed python, jus use F#.
>>
>>51544525
>imperfect
top cuk
>>
>>51544602
>btfo
>heap can grow indefinitely but the stack runs out very quickly
>MUH CACHE
>>
>>51544630
Prove me wrong. Jews are hated because they are the BEST at their own game.
>>
>>51544709
>>heap can grow indefinitely
No, it can't.

>but the stack runs out very quickly
If you used a system where heap did not exist, you would have a giant stack.

lol retard
>>
>>51544749
>If you used a system where heap did not exist, you would have a giant stack.
Tell me about these systems and how significant they are to programming within the last 20 years.
>>
>>51544767
They don't exist, because of heapfags such as you.
>>
Why are we event talking about jews?
>>
>>51544788
Wow, >>51544072 was right.
>>
>>51544810
Thanks for linking me to something unrelated.
>>
>>51544072
>programming literates of dpt
anon...
>>
>>51544788
how do you avoid using the heap? How do you have a function that returns an array with a million bytes without a heap? Do you copy the entire array to the invoker of the function?
>>
Is it possible to do *a lot* of recursion without stack overflow?
>>
>>51544880
See >>51544370
Callbacks

>>51544885
Yes, TCO
>>
>>51544806
>Why are we event talking about jews?
sound like something a jew would say
>>
>>51544957

The only jewish thing I talk about is race mixing.
>>
>>51544944
Does TCO just replace it with iteration?
Is it basically reduce/accumulate?

Can TCO do millions?
>>
I've been having problems with this problem. I've commented the problems in the pastebin. Hopefully that's enough to go on.

http://pastebin.com/zAAz1AG6
>>
>>51545024
>Java
I think I've found your problem
>>
>>51544944
What is the size of the array the method creates is unpredictable? How do you allocate the memory on the stack for the method to save the array to when it can't know how long the array will be in advance?
>>
>>51545024
>import java.util.Collections;
>import java.util.HashMap;
>import java.util.HashSet;
>import java.util.Iterator;
>import java.util.Map;
>import java.util.Scanner;
>import java.util.Set;
>import java.util.SortedMap;
>import java.util.TreeMap;

>class of one function, no fields
>executed once
>>
>>51545050
My Java class is almost done. I've had to put up with 2 semesters of this shit.
>>
>>51544242
agdg is pretty useless. maybe try in >>>/g/wdg since it's php
>>
>>51545060
There are many methods, the easiest is
int array[size];

where size is the argument.
>>
>>51545072
I have a module on developing for android
Java is shitter than I ever thought
My lecturer for it embodies Java. He regularly says the same thing 3 times in a row in different ways (so x explains how we can do x in the context of doing x).
>>
>>51545108
>a shitty lecturer means the language is shitty
>>
>>51544967
that also sounds like something a jew would say
are you a jew? I'm sure you are. I mean, who else would be:
- "anarchist"
- "libertarian"
- capitalism lover
- supposedly christian
- statist
? jews do this purely by convenience and to deceive everyone.
>>
>>51545060

alloca :^)
>>
>>51545132
>i can't into english
>>
>>51545105
i mean if you are doing the equivalent of
int array[] = makeAnArray();

where makeAnArray() returns an array of unpredictable length.
writing
int array[muhSize]

means you need to know what the size will be before you call the function.
>>
>>51545140
There are no Jewish libertarians.
Ben eliminated them in The Purge.
>>
The heap is necessary. The stack is an optimization. Any questions?
>>
>>51545024
what's the problem? and use name.equals(pres) instead of name == pres
>>
>>51545181
JIT
>>
>>51545170
Uhm, you know the american version of "libertarianism" was created by jews, right?
>>
>>51545140

The first three are true, but I'm not a christian or a statist.
>>
>>51545190
>the american version of libertarianism
The only version of libertarianism
>>
>>51545197
>but I'm not a christian
So, you admit that you are a jew.
>>
I want to write a class that can monitor a bunch of different values for easy debugging. Imagine setting "watches" in a visual debugger. I'm picturing something like this:

struct Foo {
int x = 0;
std::string s = "bar";
};

int main() {
Foo f;
ValueMonitor::watch("number", &f.x);
ValueMonitor::watch("string", &f.s);
for (int i = 0; i < 10; ++i) {
++f.x;
if (i > 5) {
f.s = "new string";
}

// print the current value of the variable with the given key
// these should change as the loop goes on
ValueMonitor::print("number");
ValueMonitor::print("string");
// or
ValueMonitor::printAll();

// obviously this would be unnecessary in this example since I
// have easy access to f, but imagine monitoring different
// values from all over a much larger code base
}
}


Then these could be easily monitored somewhere in the application's GUI or whatever.

However, I don't know how to handle the different types that would be stored in this class. Ideally, I should be able to store anything that has a string representation. I have a few ideas but none of them really seem right:

1) Store pointers to a superclass that defines a toString function or operator<<, like Java's Object. But this would require me to make wrappers for any primitives I want to monitor.
2) Something like boost::any or boost::spirit::hold_any. I think any needs to be type casted before I can print it... I guess I could try/catch casting to a bunch of different types, but that would be slow. hold_any requires defined stream operators, which would be perfect... but I can't get it to work with pointers.

Anyone have any ideas?
>>
>>51545197
>anarchist libertarian
fuck off
>>
>>51545166
>>51545166
>means you need to know what the size will be before you call the function.
no, this is not true, consider:
void func(char str[])
{
char newArray[strlen (str)];
...
}
>>
>>51545201

Precisely.

>>51545205

I'm not religious.
>>
>GNUplot
>>
>>51545235
>I'm not religious.
Exactly what a jew would say.
>>
>>51545220

Looks like you're forgetting 'nigger lover' there, too.
>>
>>51545223
but it is true. Your example is different. You aren't assigning anything to newArray. You're defining the length of it based of the str array that was already created for you.
>>
>>51545252
There are no liberties without a state
>>
>>51545262

There will be liberty as long as good men are armed. That is all that is necessary.

Then again, you're probably European so I wouldn't expect you to have any understanding of the concept.
>>
>>51545281
>There will be liberty as long as good men are armed.
How do you determine who's good and who's bad?
>>
>>51545281
What makes a man good?
>>
>>51545304
>>51545309

If he likes black chicks, then he's fine by me, to be honest.
>>
>>51545255
I am not sure I understand what you are trying to do.

Consider:
int *array = makeAnArray();
, the allocation happens inside makeAnArray() probably by calling malloc. So you do know the length of it.
>>
>>51545319
So most men are not good then?
>>
>>51545337

That's right, most of you are shitters.

But really though, this is not /pol/ and let's keep /pol/ on /pol/.

We could always talk about programming, ya know?
>>
>>51545353
tripcode => corpse
>>
>>51545327
but that's a pointer. You can't point to the array to the array that makeAnArray() method allocates, because it allocates it on the stack, and everything makeAnArray put on the stack will be popped off when makeAnArray goes out of scope, and the pointer will be pointing to nothing.
>>
>>51545386
And you can't do
int array[] = makeAnArray()
in C.

>and everything makeAnArray put on the stack will be popped off when makeAnArray goes out of scope, and the pointer will be pointing to nothing
Don't return it then.
>>
>>51545386
>the pointer will be pointing to nothing.

Classic C technique.
>>
Congratulations, you stackfags just reinvented continuation-passing-style.
>>
>>51545440
>using a stack
>not using a queue
it's 2015
>>
>>51545422
>And you can't do int array[] = makeAnArray() in C.
I know. Instead it would return a pointer that points an array on the heap.

>Don't return it then.
Then how do you get the array returned without the heap? Sounds like you haven't thought all this through.

>>51545423
that's true
>>
>>51545218
Use lambdas that return a string representation of the monitored value
>>
>>51545281
>There will be liberty as long as good men are armed. That is all that is necessary.

>The good guys always win

Oh boy.
>>
>>51545440
It does not reinvent it, it IS CPS.

>>51545493
See >>51544370
Callbacks
>>
>>51545521
read the thread. I responded to the callback bit. see >>51545166
Can't do shit like this with callbacks as far as i can tell.
>>
File: 1402684278790.png (154 KB, 327x325) Image search: [Google]
1402684278790.png
154 KB, 327x325
does anyone else think debugging is kind of comfy sometimes?
>>
>>51545538
C has support for dynamic-length stack allocated arrays.
int main () {
int x = rand() % 100;
char buffer[x];
return 0;
}
>>
>>51545565
I know that. Read >>51545166 again, specifically the last part.
>>
>>51545538
I really don't get your problem.

void
makeAnArray (void (*callback)(char [], void *), void *arg)
{
char array[size];
callback (array, arg);
}

void
callback (char array[], void *arg)
{
/* continue the program here */
}

int
main (void)
{
makeAnArray (callback, 0);
return 0;
}
>>
Made a .csv viewer in Bash.
>>
>>51545582
>means you need to know what the size will be before you call the function
My example with rand() shows that you DON'T need to know what the size will be. What are you asking?
>>
>>51545201
hahahAHAHHAHA
all the current political definitions were born in europe, hundreds of years ago
murricans are experts on redefining politics, just like their jew masters..

>>51545235
>I'm not religious.
jews are a religious and a national group
>>
>>51545621
>jews are a religious and a national group

The only thing about jews that is 'ethnic' is that they can't stop fucking their cousins and they all have Tay Sachs.

That's about it.
>>
>>51545621
the declaration of independence was the foundation of modern libertarianism
>>
>/dpt/ - daily /pol/ thread
>>
>>51545659
>the declaration of independence was the foundation of modern libertarianism
HAHAHAHAHAHAHAHAHA, you can't be more ignorant and retarded. don't you notice how you are contradicting yourself?
ffs, it's no wonder murrica is a shithole filled with jews, fat cows, ex slaves, paranoid thieves that call themselves politicians and repressed faggots like you or the nigger lover "libertarian"... your education sucks, you are truly retarded and easily manipulated by jews.
>>
>>51545615
>My example with rand() shows that you DON'T need to know what the size will be.
my whole point was you need to RETURN a function of arbitrary length.

>>51545604
Oh, I get you now. Jesus christ that is brutal.

What if you want to create a new array based off the array you created there within callback, but you want to drop the old array to save memory?
>>
>>51545683
>Constantly under actual threat of being literally replaced by foreigners; Often if you don't train your replacement foreigner you lose your severance package
>"W-Why aren't you guize bleeding-heart liberals?"
>>
>>51545749
>everybody who thinks I am annoying is a librul
>>
>>51545749
That's free market capitalism m8. If you want a secure job, make sure you globally competitive at what you do.
>>
>>51545742
In a proper CPS language, anything you don't pass on to the next function gets cleaned up. Of course, this doesn't work if everything is on the stack.
>>
>>51545741
>europe
>free speech
>>
>>51545762
Speaking of liberals, It's "that" time of year, when hundreds of thousands of CS memesters compete for tens of Google internships placements.

Whose ready to pick up the pieces of shattered dreams?
>>
>>51545786
>>51545749
>libruls don't want me to talk about politics!! MUH FREE SPEECH! REEEEEEEEEEEEEEEEEEE
>>
>>51545742
>my whole point was you need to RETURN a function of arbitrary length.
Ok. Since in C arrays are just pointers, you need to return the length of the array separately if you EVER need to know the length of an array returned by a function.
In that case, you would get the length as a variable, and the pointer to the data as well. Then you would create an arbitrary length array on the stack given the length variable, and copy the array data in using memcpy() or a loop.
Have I spelled it out for you enough?
>>
>>51545776
>In a proper CPS language, anything you don't pass on to the next function gets cleaned up
sure, but what if you're doing a lot of data transformed. created a lot of new array based on old arrays etc. You'll always need the last two arrays at least. How do you "clean up" the third last array that is no longer needed when there's two other arrays that are needed sitting on top of it on the stack?
>>
>>51545790
Thankfully, this semester's CS course was one for people who had already studied it quite a bit on their own time, and we get two semesters of material done so I can do 2nd-year courses already. Of course, that means I'm going to be shoved back into the courses with the mongoloids.
>>
>>51545803
>libertarianism without free speech
>>
>>51545741
>nigger lover "libertarian".

At least you've got the labels figured out not.
>>
>>51545814
I'm not the guy defending only using the stack. If you are using a stack (really, it ends up being a queue/ring buffer), then of course, that's the issue. So CPS languages still need a heap.
>>
>>51545830

now**, rather.
>>
>>51545507
Sweet, that worked. Great idea.

class ValueMonitor
{
private:
static std::map<String, std::function<String()>> _values;

public:
ValueMonitor();
~ValueMonitor();
static void monitorValue(String name, const std::function<String()>& value);
static void printAll();
static void clear();
};


    // ...
int _x = 4;
String _st = "butt";
std::string _test = "test";

ValueMonitor::monitorValue("int", [&](){return String::fmt("%d", _x);});
ValueMonitor::monitorValue("String", [&](){return _st;});
ValueMonitor::monitorValue("std::string", [&](){return _test;});
// ...
>>
>>51545811
>Have I spelled it out for you enough?
Yes thanks. That sounds ridiculously unperformant and clusterfucky.

>if you EVER need to know the length of an array returned by a function.
You say that like it's not extremely common in literally every language in common use for functions to return arrays of arbitrary length. Have you actually made any meaningful large programs?
>>
jimmies successfully rustled.
you can now continue talking about meme languages and how this specific feature of this or that language sucks much, that it makes the whole language suck and a joke
>>
>>51545883
>Have you actually made any meaningful large programs?
Not him, but considering that you actually could not understand shit before, I am sure that you have not.
>>
HERE'S HOW YOU AVERAGE TWO INTS IN C

int avg(const int a, const int b)
{
return a / 2 + b / 2 + (a % 2 + b % 2) / 2;
}
>>
File: 1440996243534.png (422 KB, 820x680) Image search: [Google]
1440996243534.png
422 KB, 820x680
>>51545896
>mfw I'm the guy that shills meme languages because I get paid to constantly rewrite them into the latest fad

You know those contractors HR brought in to write your Ruby shit to Node.js? I'm going to be rewriting that Node.js shit to Go soon enough.

You'll never see it coming.
>>
>>51545914
>but considering that you actually could not understand shit before
There was some bits i didn't get immediately, but i was right in suspecting using nothing but the stack has enormous consequences for performance and code maintainability.

>I am sure that you have not.
I've written quite a lot of shit. Made one product that's used by over 100,000 people in my spare time. Created one 10,000+ line project from scratch for my last job. Worked on several 20,000+ line projects. But yeah, even working on a few small things would make you realise the value of the heap and why every single widely used language uses it.
>>
>>51545972
toplel
>>
>>51545947
>rounding error
>>
>>51546003
nope it's compeletely accurate within the precision of ints
>>
>>51546030
>rounding error
>>
>>51546030
assuming you want truncation (rounding to zero) that is
>>
>>51545947
>>51545962
>>51545972
top kek
>>
>>51546056
>autism
>>
>return a float/double
>specification implied an int

>return an int
>rounding error
>>
>>51543878

Anyone here on a LAN sharing the same pulic IP?
>>
>>51546076
return ((a / 2 + b / 2) << 1) + ((a%2) && (b%2) ? 2 : 0) + ((a%2) == (b%2) ? 1 : 0)
>>
>>51545877
Or you could do it the C++ way (OOP and templates)
template <typename T>
std::string to_string (const T& x) {
std::ostringstream ss; ss << x;
return ss.str();
}
template <>
std::string to_string (const std::string& x)
{ return "\"" + x + "\""; }

class Show {
public:
virtual ~Show () = 0;
virtual std::string str () const = 0;

using ptr = std::shared_ptr<Show>;
};
Show::~Show () {}

template <typename T>
class ShowRef : public Show {
T* _ptr;
public:
ShowRef (T& ref)
: _ptr(&ref) {}
virtual ~ShowRef () {}

virtual std::string str () const { return to_string(*_ptr); }
};

class Monitor
{
std::map<std::string, Show::ptr> _watching;

public:
Monitor () {}
~Monitor () {}

template <typename T>
void watch (const std::string& name, T& ref) {
_watching[name] = std::make_shared<ShowRef<T>>(ref);
}

void show () {
std::cout << " ===== monitoring =====" << std::endl;
for (auto& pair : _watching) {
std::cout << pair.first << " = " << pair.second->str() << std::endl;
}
}
};


int main () {
int x = 1;
std::string y = "a";

Monitor monitor;
monitor.watch("x", x);
monitor.watch("y", y);

monitor.show();
x = 3;
y = "b";
monitor.show();

return 0;
}
>>
>>51546156
overflow but if you wanted a single variable

.5 probably more important than top half of int max
>>
>>51546156
>avg(2000000000, 2000000001)
>-294967296
>avg(2000000000, 2000000002)
>-294967293
>avg(-2000000000, -2000000001)
>294967296
>avg(-2000000000, -2000000002)
>294967295
>avg(2000000000, -2000000000)
>1
>avg(-2000000000, 2000000000)
1
>>
>>51546213
what are you talking about
on any decent compiler with INT_MAX = 10000000000000000000000000000000000000000000000000000000000 and INT_MIN = -10000000000000000000000000000000000000000000000000000000000 this works fine
>>
Can somebody explain asynchronous methods to me, in particular the await keyword?
I can sort of use them, but I get tons of weird problems that likely stem from me not really know what the fuck is going on.
>>
>>51546278
What language?
>>
>>51546240
>avg(0, 2)
>3
>avg(1, 3)
>5
https://www.youtube.com/watch?v=7wVagQ_LVd4
>>
>>51546289
C#
>>
>>51546278
It's probably best to learn how asynchronous calls work without async/await, i.e. using futures directly. Then learn how async/await make futures easier to use.
>>
>>51546303
damnit try this
return ((a / 2 + b / 2) << 1) + ((a%2) == (b%2) ? ((a%2)==1?1:2) : 0)

(it's supposed to be shifted left by 1)
>>
>>51546278
>weird problems that likely stem from me not really know what the fuck is going on.
I feel like this pretty much sums up C# fulll stop, every version they add a ridiculous amount of new amazing features but nobody has time to put them to practice before you've got to start learning all the new shit they imported from F#.

Meanwhile still no VB.NET's XML literals.
>>
>>51546278
await basically takes code like this:
Console.WriteLine("downloading String...");
var str = await downloadStringAsync(url);
Console.WriteLine("string downloaded: " + str);

and compiles it to something that would otherwise look like this:
Console.WriteLine("downloading String...");
downloadStringAsync(url, (str) ->
Console.WriteLine("string downloaded: " + str);
);

basically it's a way of avoiding writing callbacks for tonnes of this.
>>
>>51546354
actually nvm that's fucked


conclusion from past x threads
it is not possible to average 2 ints in C
>>
>>51546366
It's a thought experiment to get us used to working in the software industries where you're always one step behind the project requirements
>>
>>51546366
but then who was >>51545947
>>
>>51546363
JavaScript needs this.
<3 monads
>>
>>51546359
>but nobody has time to put them to practice before you've got to start learning all the new shit they imported from F#.
It really doesn't take that long to learn, and it's useful as fuck. You also don't *have* to use it, it's just syntactic sugar.
>>
>>51546379
that guy was wrong because rounding error
the .5 is more important than the top half of int max

because the top half of int max means you're pushing C limits
>>
>>51546382
It's being worked on for ES8 i think.
>>
>>51546382
that's no monad...
>>
>>51546382
How is this related to monads?
>>
File: hqdefault.jpg (22 KB, 480x360) Image search: [Google]
hqdefault.jpg
22 KB, 480x360
>>51546413
It's a space station
>>
>>51546382
That's CPS

>seeing a lambda and thinking monad
You're a meme and the reason functional programmers get so much flak over category theory
>>
>>51546394
it's not wrong if you want truncation

avg(2000000000, 2000000001) = 2000000000
avg(2000000000, 2000000002) = 2000000001
avg(-2000000000, -2000000001) = -2000000000
avg(-2000000000, -2000000002) = -2000000001
avg(2000000000, -2000000000) = 0
avg(-2000000000, 2000000000) = 0
>>
>>51546421
Not him. It;s not, but I think F# implements it using monads, in its computational expressions.

I'm honestly still not sure what a monad is exactly..
>>
>>51546413
>>51546421
>>51546429
Continuation passing and monad composition (>>=) are very similar, one can emulate the other. I suppose they aren't _exactly_ the same.

http://stackoverflow.com/questions/4525919/continuation-passing-style-vs-monads
>>
>>51546421
It's not a monad, but it is related

Futures are a monad, and async/await are another way of using futures
>>
no state <=> no interesting computation is taking place
>>
>>51546432
>if you want truncation
if you want the wrong answer
>>
>>51546503
that's how ints typically get rounded. 3/2=1 for instance.
>>
>>51546498
Good thing even pure functional languages allow you to build up computations that work on state
>>
>>51546444
>I think F# implements it using monads, in its computational expressions.
I think it doesn't, even though it supports monads.

GHC 7 supports automatic async IO thanks to monads, but are also severely limited by them -- you can't start two calls and wait for them for example.

In C#, that's the whole point of await
>>
>>51546536
with extra work
>>
>>51546570
Not really, no

Thanks to things like do-notation you can express a computation just as naturally as in an imperative language
>>
>>51546552
Well, F# does support async/await. In fact it was the first language anywhere to have it afaik.
>>
>>51546552
>you can't start two calls and wait for them for example.
>In C#, that's the whole point of await
huh? How do you await two things in C# with async/await?
>>
await Task.WhenAll(AsyncMethod1(), AsyncMethod2());
>>
>>51546612
Await them in sequence and they're performed in parallel.
>>
>>51546638
for
>>51546612
>>
>>51546639
Source? I don't think that's true. I think you gotta do this: >>51546638
>>
File: intredasting...jpg (59 KB, 685x567) Image search: [Google]
intredasting...jpg
59 KB, 685x567
>finally figured out what was causing the bizarre error
>i had forgotten to put a piece of my shit in a synchronized block
>>
>>51545749
>under actual threat of being literally replaced by foreigners
What's wrong with that? If they can do the job better than you (i.e they can accept less wages or be more efficient), then you are the one with the problem. It sounds like you really have a problem with capitalism.

But don't complain about the people who just want jobs. The point of the capitalist system is to trick fools (i.e people like you) into misdirecting their anger at people rather than businesses which do the practice in the first place.

If they do hire foreigners, then you hate the foreigners. If they don't hire foreigners, then they get you to like the company for "taking a stand" or being "patriotic" etc.

It's a win-win situation for them, so long as they trick fools like you. Grow up.
>>
>>51546723
They actually can't do the job, at all, that's why you've got to train them.

Are you daft m8?
>>
how good is learn python the hard way?
>>
>>51546741
>They actually can do the job, at all, that's why you've got to train them.
fixed that for you.

After you've trained them they'll be able to do the job. That's why you're afraid of them replacing you.
>>
>>51546684
Always have at least one piece of shit in your synchronous code. The shit acts as a magnet for the asynchronous computations
>>
>>51546169
Holy crap that's awesome.

Can you explain your thought process while writing that? I knew there had to be *some* OOP way to do it, but I couldn't think of how to write it.
>>
File: muh monads.png (10 KB, 581x152) Image search: [Google]
muh monads.png
10 KB, 581x152
class Maybe(T)
{
bool Empty;
this() { Empty = true; }

static if(!is(T==void))
{
T Value;
this(T value) { Empty = false; Value = value; }
}
else
this(S)(S value){ Empty = false; }
}

auto bind(alias S = x => x, T)(auto ref Maybe!T y)
{
alias return_type = Maybe!(typeof(S(y.Value)));

static if (is(return_type == Maybe!void))
return y.Empty ? new return_type() : S(y.Value), new return_type(1);
else
return y.Empty ? new return_type() : new return_type(S(y.Value));
}
>>
>>51546767
>That /lit/-tier logic
10/10, you'll graduate soon.
>>
>>51546552
Yeah, even in Haskell you still should use futures to properly do async I/O

The full category menagerie then lets you do a bunch of different stuff:
>Applicative: combine multiple futures into one
>Monad: sequence another asynchronous operation onto a future
>Alternative/MonadPlus: "race" multiple futures against each other, taking the "winner"
>>
>>51546791
fyi a Maybe!void can't call anything without 4 more lines of code (suboptimal usage of D)
>>
>>51546787
Not him, but I'd have come to the same conclusion based on this Haskell pattern:
https://wiki.haskell.org/Existential_type
>>
>>51546799
I'm right though. If all you need to do is train them for a couple of weeks for them to do the job you do, but for cheaper. Then you're overpaid. Basic supply demand fella.

I'm 29 btw. Happily employed as mobile developer.
>>
>>51546741
Whether they can do the job is irrelevant. So long as the company can make some money off them, that's the only relevant part.

If you're mad that you've got to train them, you still have no justification for being mad at them instead of the company that hired them to replace you.

If you were really so mad about it, you would just walk out of the job and refuse it. The company will get someone else to train them.

The fact is that they have an edge over you no matter how you look at it. They (apparently) can be quickly trained (probably unlike you) and may even accept lower wages.
>>
File: 1427768707479.jpg (196 KB, 822x556) Image search: [Google]
1427768707479.jpg
196 KB, 822x556
>>51546843
>a couple of weeks
>a couple of weeks
>a couple of weeks
>a couple of weeks
Shitting out Android shovelware in your basement isn't employed anon.
>>
>>51546787
I've written stuff before where you have a base class and then a templated class that subclasses it.
It's kind of cool because you're creating new classes each time you instantiate the template, but they all subclass the base class. W
And then I made the "to_string" function generic too, with template specialization to show off some more fancy C++ features. Also shared_ptr because manual memory management is for scrubs.
>>
>>51546868
I work at a medium sized company of about 30 people. I earn about €32,000 a year, but only working in the industry a year and a half.

>a couple of weeks
How long do you spend training people then?
>>
ITT: White boyz mad that they spent over 100k on their college education learning stuff any motivated individual can learn in under 3 months.
>>
>>51546884
>it doesn't use template template parameters
dropped
>>
>>51546743
i haven't followed it myself but i've heard bad things about it in /dpt/ and zed shaw is a douche
>>
>>51546908
Are US/Indian universities really that expensive?
>>
>>51546910
I should've used variadic templates, and r-values and move semantics, and probably boost. Like a REAL C++ developer.
>>
mixin(transcompile_to_d!("language as D string literal", "code as D string literal"));

daily reminder that with the right library, all your code could be valid D code
>>
>>51546906
>How long do you spend training people then?
30 days training, another 6~ weeks shadowing and then around 60 days transitional is the usual.
>>
>>51546965
valid D code. But not desirable.
>>
File: 1448380553493.jpg (203 KB, 900x506) Image search: [Google]
1448380553493.jpg
203 KB, 900x506
>>51545683
When the Nazis came for the communists,
I remained silent;
I was not a communist.

When they locked up the social democrats,
I remained silent;
I was not a social democrat.

When they came for the trade unionists,
I did not speak out;
I was not a trade unionist.

When they came for the Jews,
I remained silent;
I wasn't a Jew.

When they came for me,
there was no one left to speak out.
>>
>>51547035
not too bad. And they are qualified skill wise as much as you are otherwise?
>>
>>51547039
>converting your code to D
>not desirable
>>
I need to change this program to use a array instead of an arraylist. Apparently I need to create an array of objects and cast it to E[] but I don't understand how to do this. Any help is appreciated.

public class GenericStack<E> {
private java.util.ArrayList<E> list = new java.util.ArrayList<E>();

public int getSize() {
return list.size();
}

public E peek() {
return list.get(getSize() - 1);
}

public E push(E o) {
list.add(o);
return o;
}

public E pop() {
E o = list.get(getSize() - 1);
list.remove(getSize() - 1);
return o;
}

public boolean isEmpty() {
return list.isEmpty();
}
}
>>
>>51547068
you got it
>>
>>51546908
That kind of motivation is certainly commendable but exceedingly rare. It's not easy to cover a full college degree by oneself, especially when people have to work to live. Going to face to face college means you have peers to accompany your study and also have a solid pathway to your education structure.

Sheer motivation of those levels are rare.
>>
>>51547092
triggered
>>
>>51547056
What? No?

Your responsibility doesn't even end there btw, often you've got to be contactable by your previous employer for up to a year to explain any legacy shit you left laying around, for free.
>>
>>51547068
how is D supposed to be any good?
Thread replies: 255
Thread images: 20

banner
banner
[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y] [Home]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com, send takedown notices to them.
This is a 4chan archive - all of the content originated from them. If you need IP information for a Poster - you need to contact them. This website shows only archived content.