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

/dpt/ - Daily Programming Thread

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 315
Thread images: 29

File: hidamari_dpt_waifu2x_traps.png (2MB, 1618x1308px) Image search: [Google]
hidamari_dpt_waifu2x_traps.png
2MB, 1618x1308px
Old thread: >>61701466

What are you working on, /g/?
>>
>I am too stupid to use a better language, therefore I must complain about it!
>>
>>61705989
t. The entire C & Python community
>>
>>61705989
Exactly. Next time you see non-brainlet langs arguing don't bring you garbage ``collected`` language
>>
>lmao GC fags
>*uses OpenGL*
>manual memory
>*creates file*
>masterrace, who
>*requests port*
>can even compete?
>>
File: 1453302491365.png (129KB, 314x278px) Image search: [Google]
1453302491365.png
129KB, 314x278px
>>61705989
>>61706045
Who the hell are you quoting? I didn't see anybody say that.
>>
>>61706068
whoops i had numlock on
>>
>>61706045
Since when is opengl garbage collected?

The only thing it does is automatically free/overwrite data when you recall glBufferData. That's not really garbage collected.
>>
>>61706122
>something automatically done for you
whoa, cant be having that brainlet shit now. If theres something menial, i need to be in control of it.
>>
>>61706122
the point is that there are resources that are handled automatically and not manually
>>
File: 1490716618886.jpg (69KB, 728x546px) Image search: [Google]
1490716618886.jpg
69KB, 728x546px
>>61706110
Assumptions which most processors have adapted to serve, curiously enough. 64-bit ARM's limitation of conditional execution to just a small subset of instructions was due to that C compilers couldn't make very good use of the facility generally.

>>61706142
>>
>>61706184
>C
>multithreading
>>
>>61706209
C
Multithreading
>>
Someone asked for a linked list in Rust?
https://ghostbin.com/paste/sokqw
>>
File: image.aspx.jpg (34KB, 400x400px) Image search: [Google]
image.aspx.jpg
34KB, 400x400px
>>
>>61706232
How do I use that to make a circular list?
>>
>>61706232
If only Rust had HKTs, then you could have used a fix encoding
>>
>>61706232
>>61706246
or Free
>>
>>61706241
saved
>>
>>61706184
> 64-bit ARM's limitation of conditional execution to just a small subset of instructions
For, well, the history of computers, conditional execution has been limited to a small number of instructions. Conditional execution is a bitch to engineer.

Unless you mean something that I'm not thinking of. I'm thinking of shit like jne. But even then conditional "add/sub/mov" instructions seems completely useless and too bloated for even CISC.
>>
>>61706243
How do you manage memory in a circular linked list without a GC?

>>61706246
Yes also I was thinking it'd be nice to abstract over the Box and be able to swap in [A]RC instead, but that would require HKT's. I think the reason they won't add HKT's is because it won't work very well with iterators
>>
>>61706267
I thought it was a problem with the lifetime system
>>
>>61706232
>60 lines for a linked list
why do you people use this?
>>
>>61706288
data List a = Null | Cons a (List a)
>>
>>61706267
>How do you manage memory in a circular linked list without a GC?
By just managing your shit properly. You know where the head is.
>>
File: go.jpg (38KB, 400x400px) Image search: [Google]
go.jpg
38KB, 400x400px
>>61706258
>>
>>61706277
I'm asking in general how would you manage memory in a circular linked list. Once we answer that then we can think about how to implement it in Rust.
Rust doesn't magically solve all GC problems. The lifetime system does enforce constraints on how you structure your data.

>>61706291
LOL what a shit answer.

>>61706288
60 lines for a linked list that manages its memory without a GC, plus a pretty printer and conversion from arrays into linked list. I don't think that's horrible especially for ugly algol languages
>>
>>61706311
>LOL
Fuck off.
>>
I've tried doing the sicp but it really screws with me at certain parts. is it actually a good learning tool because i feel like i keep on hitting road blocks (i tried doing it when i was 17 the first time and now again a few years later)
>>
>>61706261
Oh, the original 32-bit ARM ISA had conditional execution on most instructions, which is really handy when writing constant-time algorithms such as hardware control and crypto, or when skipping relatively short strings of instructions such as in range-checking or non-constant-time counted comparisons. Imagine addne, cmpne, ldne, stne, and so on. Great for assembler programming.
It's not really that bloated, especially on a scalar 3-operand machine, and doesn't add that much complexity to the pipeline. As I understand it, the condition comparison just rides along the pipeline with everything else and the write-back stage just doesn't bother to write back if the condition doesn't match. It doesn't play nice with out-of-order or multiple execution, so it had to go.

>>61706291
"Manual memory management is only free if your time has no value"
>>
>>61706416
SICP is literally just for learning a Lisp.
>>
>>61706416
http://cs.brown.edu/~sk/Publications/Papers/Published/fffk-htdp-vs-sicp-journal/paper.pdf
>>
>>61706416
you're not the only one
what sucks is I wanna code scheme and Common Lisp and basically all resources assume you've read the SICP
the guile handbook literally discusses extremely basic scheme, has a page of recommended reading with SICP, a racket book, and the fucking lang docs in it, and then discusses no further the languages syntax and use
>>
I'm planning to learn C++ (for now im working as C# web monkey and know C)

Am i fucked? I know people say C++ sucks and stuff, but i feel uncomfortable for not knowing it at all. I love unmanaged/system programming but C is bit too hard sometimes (without ready solutions) in standard library
>>
>>61706456
>discusses no further the languages syntax and use
Maybe because there is no further syntax. Scheme is very small.
>>
>>61706459
C++ isn't really that bad
>>
>>61706465
>my other car is a cdr
>>
>>61706436
>Oh, the original 32-bit ARM ISA had conditional execution on most instructions
God that sounds awful to design with condition prediction desu.

Every instruction potentially causing a mis prediction and dumping the pipeline.

Thinking about the sheer magnitude of such a decoder makes me scared.

Or the number of caches necessary for all the different ways execution could be conditional
>branch prediction cache
>immediate prediction cache
>load prediction cache
Wait a minute...

>addne, cmpne, ldne, stne
How is this different from
>jne skp
>add eax, ebx
>skp:
That seems like a waste of transistors desu.
>>
>>61706568
Just RISC things I guess
>>
>>61706586
Seems like the opposite of what I believed risc was. Just bloat.
>>
>>61706443
isnt it a strong yet convoluted basis for programming though? its just everything is explained so poorly, even normal vs applicative i had to use other resources (sicp wiki, mit page and stackex)

>>61706446
interesting, is htdp a common method (the "best" i suppose)?
>>
>>61706603
>that's bloat
Then use nothing but binary, you picky faggot.
>>
>>61706615
No, its quite literally the actual definition of a "meme book". Its not a general learning tool, its a tool for lisp, because close to all the lessons are focused around lisp-implementations and explanations of the language.

Do not fall for it unless you plan to learn a flavor.
>>
>>61706615
HtDP is used successfully in a few universities. The biggest problem with it IMO is that it's set up to be the idea first semester university CS course, which means that it assumes you're going to enter into more courses afterwards and learn better things. It won't teach you to be an effective programmer on its own but it will set you in the right direction better than most other resources.
>>
>>61706628
God damn, you're fucking stupid.
>>
File: 1475466727417.jpg (19KB, 448x336px) Image search: [Google]
1475466727417.jpg
19KB, 448x336px
This works but is it undefined behavior since x is 8 bits and I'm shifting by 16 or does it get promoted or casted since it's being OR'd with a 16 bit value? If it's undefined behavior then should I just make x a uint16 as well? I'm trying to marshal data before sending it over a socket.

uint8_t x = 3;
uint16_t y = 15;
void *z = malloc(24);
*(uint32_t*)z = (x << 16) | y;

uint8_t a = *(uint32_t*)z >> 16; // a == x
uint16_t b = *(uint16_t*)z; // b == y
>>
>>61706568
The point of predicated execution is that you can have multiple shallow branches in the pipeline at once.

So if I have a simple if/else clause, the branch predictor need not bother, both get sent on, and which takes effect is decided in the retirement step.
>>
>>61706568
>condition prediction
kek
Thankfully, these original ARMs had short pipelines, maybe seven stages at most. I can imagine forwarding logic being a little convoluted though.
>How is this different
I presume you mean jz skp. Anyway, in the ARM case you don't have to dump the pipeline in case the instruction doesn't execute, you just lose the write-back after the execution stage. Constant-time whether the add actually stores anything or not.
>>
>>61706646
*ideal
>>
>>61706658
It's fine, because of integer promotion.
Those casts of z are dodgy as fuck, though.
>>
>>61706668
Predication is a separate mechanism to branch prediction. You can have short branches being dependent on a predication register instead of branching, the branch predictor is not invoked and the front end sends the code of both predicated branches on. The decision about which takes effect is done on the back end.

Look at Itanium for a more complete example of the idea. (iirc arm only has a few predicatable instructions)
>>
>>61706679
Any idea how I would be able to unpack the values in a better way on the client side? I'm not very familliar with this kind of thing yet. The idea of the casts on z were just so that I could easily select a subindex of the bits, I want to retrieve the leftmost 8 bits for a and chop off the bits that don't fit (first 16 only) for b. In a higher level language I think it would look something like this
a := byteArray[:8]
b := byteArray[8:]
>>
>>61706655
You wanted less bloat. So, if that simple shit is "bloat" use pure machine code. Can't get less bloated than that. What a mouthbreathing retard.
>>
>>61706668
jnz and jne are the same thing though.
>>
Why not put NOPs after JMPs, or any other shit that you would want to run at the same time, instead of prediction? Didn't SPARCs do that?
>>
>>61706853
I'm not sure what you mean. Out of order execution? CPUs do that but it can only go so far.

Nowadays the latency of instruction fetches is crazy high so you wanna know where to fetching instructions before the jump is even executed. Not trying to predict where a jump goes to and if the program will take it is just pain. You don't wanna stall waiting for new instructions.
>>
>>61706853
If I recall correctly, there are some weird architectures where a jump instruction won't happen until AFTER the next instruction.
I think MIPS was one.
>>
>>61706655
Checked.

>>61706834
I know. I said jz, not jnz, since we were using ne for an example.

>>61706752
Oh, I thought you were talking about something like a branch prediction cache where the last branch taken state is cached and assumed the most likely result of the next time that instruction is executed, thus steering fetch and decode stages. ARM cores are far too smol and simple for such extravagance.
If I understand correctly, ARM appears to have used predication, with the condition code register and instruction predicate fixed as the predication register, and only one thread of execution instead of two or three so much simpler.

>>61706853
a) it turned out the branch delay slot didn't get meaningfully filled all that often
b) the complexity of out-of-order execution interacting with delayed branches stunted performance improvements through architecture
>>
>>61706939
Called delay slots. I think MIPS had it, indeed.

https://en.wikipedia.org/wiki/Delay_slot
>>
File: 1478169282604.png (53KB, 712x916px) Image search: [Google]
1478169282604.png
53KB, 712x916px
>>61705964
>traps are not programming related
WRONG
>>
>>61706752
Hmm Itanium seems neat. What exactly was wrong with it that caused it to be such a commercial failure though?
>>
>>61707094
It wasn't x86.
Jew tax.
Perceived difficulty to write compilers/programs for.
>>
>>61706045
>>manual memory
>>*creates file*
Wait, you don't manually allocate your files using fallocate/ftruncate?
>>
>>61706658
learn to use unions and bitfields
>>
>>61706045
Hol up so you be sayin
>>
File: trap.jpg (557KB, 2000x1530px) Image search: [Google]
trap.jpg
557KB, 2000x1530px
>>61705964
>What are you working on, /g/?

Exploring the deepest, darkest corners of Racket.

>>61705964
>traps are not programming related

pic.
>>
>>61707094
The idea was that the compiler would do a lot more optimisation of instruction scheduling, so that the parallel execution logic could be simplified.

It turns out nobody could write a compiler that was all that good at optimising for the architecture's features, so it was never that fast in real world situations.

I kindof want one to play with manually optimising stuff for it, though.
>>
>>61706833
Utterly retarded fucking idiot.
Put a bullet through your head.
>>
>>61707158
What are you actually doing in Rack it?
>>
>>61707166
learning the basics
>>
>>61707024

Some kinds of traps are programming related. Others are not. Where the word "trap" is used to refer to crossdressers and trans women, it is not programming related. Similarly, trap cards in Yugioh and MtG are not programming related, unless of course the MtG trap cards are somehow used to create a Turing machine. Where the word trap is used to refer to a form of exception that causes a switch to kernel mode, it is programming related.
>>
>>61707145
If I use a union I'd only be able to store 1 value, not 2, but I'd be able to store 1 of 2 types of values, is that right? I'm trying to store 2 separate values in 24bits.
As for bitfields, wouldn't the padding mess me up?

I'm not familiar with either so excuse my ignorance, if you could give me an example it might help me understand.
>>
>>61707197
>If I use a union I'd only be able to store 1 value, not 2

union foo {
int32_t i32;
struct {
int16_t i16t;
int16_t i16l;
}
}

Foo foo = {.i32 = 0xAAAAFFFF};
cout << foo.i16t << " " << foo.i16l << endl;
>>
>>61707094
Itanic wasn't helped much by AMD bringing x86_64 and the option of why bother to the table.

>>61707160
I need to get a good FPGA board and brush up on my Verilog skills. I made a shitty little 4-stage CPU years ago but it never kissed any silicon, and it might be fun to rectify that.
>>
>>61707254
Nice. I made a shitty CPU in logisim, also. Might be nice to see it physically working.
>>
>>61707094
cisc: raises the complexity at the hardware level (cpu) but lower it at the software level (compilers)
risc: the inverse of cisc
Itanium: raises the complexity at both level for lower performances.

no bet itanium was doomed, it's pure crap and just another attempt form intel to lock the cpu market for themselves.
>>
>>61706436
>"Manual memory management is only free if your time has no value"
*only if you're retarded.
>>
>>61705964
>Be engineer
>Have to take a statistics unit
>Making us learn R

is R a good language worth learning with diligence?
>>
>>61707223
>>61707145
Thanks, I'm gonna experiment a bit with this.
>>
>>61707280
Well, Itanium required the compiler to form instructions into groups, and could do away with some of the traditional instruction scheduling logic on the chip in tradeoff.

There just weren't compilers that could optimise well enough for it to make it pay off. And the onboard x86 emulation was awfully slow.
>>
>>61707288
If you ever need to statistics and draw fancy graphs, it's good to know R. You could also just Python.
>>
Why did people stop bolting on features to shells?
How is it possible that bash has /dev/tcp and arrays but no floating point numbers?
>>
>>61707317
you can also use arrays
union foo {
int32_t i32;
struct {
int16_t i16t;
int16_t i16l;
}
int8_t bytes[4];
}
>>
>>61707354
Because at some point, people realised that there is some point of complexity where you should stop using a shell scripting language and move to a "real" programming language.
Just look at how dead Perl currently is.
>>
>>61706939
Funny that you should bring this up today. I just grabbed pocorgtfo issue 0x15 released mid-June and it promises to be another goodie for those of us who love weird machines.
>Ryan Speers and Travis Goodspeed have been toying around with MIPS anti-emulation techniques, which this journal last covered in PoCkGTFO 6:6 by Craig Heffner. This new technique, found on page 76, involves abusing the real behavior of a branch-delay slot, which is a bit more complicated than what you might remember from your Hennessy and Patterson textbook.

>>61707277
The grand experiment of that CPU and ISA (16-bit instruction word, 16/32-bit registers) was a 12-bit constant extension prefix instruction that would prepend 12 bits to any instruction's immediate or displacement operand, which was sometimes very small if not implicitly zero. I got it to timing closure at almost 66MHz in a Spartan-3, iirc.

>>61707354
Why carry around all that shell baggage when you could do most of what they and their ancillary programs did in code, and system() out when necessary?
>also, try sleep 0.5
>>
>>61707354
Because we no longer need fucking shell shit.
>>
>>61707288

Is it a good programming language? No, not really. Is it a good domain specific language for statistics? Absolutely. If you plan on doing a lot of work in statistics, you should get to know R quite well.
>>
File: images(2).png (5KB, 225x225px) Image search: [Google]
images(2).png
5KB, 225x225px
Im making Half Life: Odyssey's End
>>
File: 1487997817097.jpg (24KB, 300x300px) Image search: [Google]
1487997817097.jpg
24KB, 300x300px
>>61707165

Says the dude who finds 3 fucking variables "omg so bloated." There are real bloated languages out there and you call a lightweight one bloated. What next, HTML is too complicated? You're either extremely lazy or such a retard that it truly shocks me that you can even form words.
>>
>>61706288
It's 26 lines, the rest is just a test case and some extra traits. Stop being a dumb CIA nigger.
>>
>>61707354

Because shell languages are not designed for these sorts of tasks. They are for automating processes, and maybe a little bit of text manipulation. If you need to do complex arithmetic, it might be better to use a real scripting language, like Perl, Python, or Ruby.

If you absolutely need this sort of functionality in a shell language... you may be interested in PowerShell, which is now cross-platform and free as in freedom.
>>
>>61707448
Stop pushing your shitty POOshell.
>>
>>61707448
Someone could repackage all of those "programs" as functions for a Haskell or OCaml-like language
>>
>>61707408
>>61707345
Cool. Thanks. Just sounds like a chore because I already am advancing with Android and python
>>
>>61707223
>>61707355
I can't figure out how to do this in a way that results in a 24bit union, the struct inside must be getting padded to 4 bytes, no matter which order I use too.
union {
struct {
uint8_t header;
uint16_t payload;
};
unsigned int bytes : 3;
} test;
//sizeof test == 4


Is there any standard way for me to make sure it's exactly 24 bits?
>>
>>61707732
what compiler are you using? with gcc

union {
struct {
uint8_t header;
uint16_t payload;
};
unsigned int bytes : 3;
} test __attribute__((packed));
>>
I'm learning Rust and got a segfault. ;/
I thought Rust was supposed to stop these kinds of things.
>>
>>61707732
There is no standard way, padding is compiler-dependant.

http://gcc.gnu.org/onlinedocs/gcc-4.4.4/gcc/Structure_002dPacking-Pragmas.html
Try this (push, 1 and pop), should work on GCC and MSC.
>>
>>61707783
no pl will be enough to overcome programmer idiocy
>>
>>61707775
>>61707794
Dang, I was hoping there would be a standard/portable way to pack it. If it's compiler dependent I may just stick with my current method of mangling it all into a fixed size variable with bitwise operators before sending it over the network, I can still use the union like that everywhere else though, just not during send.
>>
>>61707795
Yeah man fuck. I'm trying to implement merge sort in Rust and it is so fucking dumb. I couldn't even do something like this
merge_sort(&mut A, 0, A.len());

because the borrow checker says I can't use mutable A as an immutable argument. ;/
The language seems cool, but it also seems too rigid, like I have to do everything in a round about way, I can't do things directly, I have to use methods and stuff.
>>
>>61707810
>I was hoping there would be a standard/portable way to pack it. If it's compiler dependent I may just stick with my current method of mangling it all into a fixed size variable with bitwise operators before sending it over the network,
Network code isn't portable either, so why bother with portability? Just pack the struct, ffs.
>>
>>61707823
The difference here is that the network code being platform dependent can't be avoided where this can. What I'm saying is I can't see any reason to introduce platform dependent code when I already have a method that works without it using only the standard.
>>
>>61707810
most of bitwise operations are implementation defined too
>>
>>61707816
you probably want a language with a dumb type system. Go, for example, was specifically made for people like you.
>>
>>61707838
>The difference here is that the network code being platform dependent can't be avoided where this can
Except it can't, alignment is processor dependent.

>What I'm saying is I can't see any reason to introduce platform dependent code
You already are if you compile your code on two different machines which can result in two different alignment boundaries.

You need to consider this, which is why you should rely on compiler extensions to control it.

You have to think about byte ordering too anyway, I don't understand why you have trouble with alignment?
>>
>>61707810
C++11 and on has the "alignas" specifier for such things.
>>
>>61707907
You can't use alignas to get an alignment more relaxed that the type would normally have.
Also, he's talking about C, you retard.
>>
pleb here, learning C and doing a binary search tree just to get the hang of things.

/g/, any idea what could be crashing my program on a 5th insert?

Node* temp = NULL;
if(root == NULL){

temp = malloc(sizeof(Node));
temp->left = temp->right = NULL;
*temp->value = *input;
root = temp;
printf("%c", *root->value);
return;
}
if(compare(input, root->value) > 0){
root = root->right;
insert(input);
}else if(compare(input, root->value) < 0){
root = root->left;
insert(input);
}


Compare function is just a simple strcmp. The addresses change fine, but whenever I insert an element for the 4th or 5th time it crashes.

basic tree_node struct:

typedef struct tree_node Node;
Node* root = NULL;

//struct definition of Node
struct tree_node {
char * value;
struct tree_node *left;
struct tree_node *right;
};


Any assignment that I'm fucking up on?
>>
>>61707867
My fault, instead of "platform" I should have said "vendor", I want to avoid being dependent on a specific compiler if possible, I can deal with OS and architecture differences with the preprocessor which should work across all of them that impliment the standard.

>You have to think about byte ordering too anyway, I don't understand why you have trouble with alignment?
I'm not sure what you mean here, for sockets I rely on the htonl and friends functions. For shifts I thought they were endian neutral in C? Regardless I am not considering other architectures besides x86 right now, that's to be done later. For now I just want to figure out the best practices on how to marshal data for sending over the wire, I'm going to be packing structs into fixed length byte stream and tagging them, so I need to take multiple elements and mash them into 1 big sequence of bytes to be sent over the network ad unpacked on the client.

>>61707996
I can see how they got confused given the other guy is posting C++ in their examples. No need to get so mad that you assume someones gender like that.
>>
>>61708028
What happens if
compare() == 0
?
>>
>>61708043
then it's already present and doesn't need inserting, presumably
>>
>>61707907
Doesn't seem to work for 24bit/3bytes
>error: requested alignment is not a positive power of 2
struct alignas(3)
>>
>>61708028
You might need to post the whole source.
>>
>>61708035
>I want to avoid being dependent on a specific compiler if possible,
Both Clang and GCC support
 __attribute__((packed)) 
, so unless you plan on compiling on MSVC any time soon (in which case your networking code would most likely break anyway), I don't see why you'd care.

>I can deal with OS and architecture differences
You can't if you rely on the compiler to choose an arbitrary alignment boundary for you. Then you can only run on one family of processors.

>I'm not sure what you mean here, for sockets I rely on the htonl and friends functions.
These are non-portable as they're not part of the C standard, first of all. Secondly, under the hood, they rely on bitshifting and using compiler specific code anyway.

>For shifts I thought they were endian neutral in C?
I'm talking about reading from a byte stream into a variable (aka reading a struct from a TCP socket).

>Regardless I am not considering other architectures besides x86 right now, that's to be done later.
You're doing yourself a huge disfavour by not decoupling your application logic from the nitty gritty low-level details right away.

>For now I just want to figure out the best practices on how to marshal data for sending over the wire
I'm fucking telling you that alignment considerations IS FUCKING PART OF BEST PRACTICE for marshalling data, for crying out loud.

> I'm going to be packing structs into fixed length byte stream and tagging them, so I need to take multiple elements and mash them into 1 big sequence of bytes to be sent over the network ad unpacked on the client.
For the love of all that is holy, consider alignment. Jesus Christ.

Consider the following
struct message
{
int tag;
char name[5];
};


How large is this struct? The answer is, that's implementation specific. Ergo, you need to rely on implementation specifics (aka compiler extensions) in order to control the exact size of that struct.
>>
>>61708066
Does that look correct so far then? The only other function I have implemented is the compare

int compare(char * a, char *b) {
return strcmp(a, b);
}


Also, thanks
>>
>>61708028
>*temp->value = *input;
I suspect that this does not do what you think it does.
>>
>>61708028
Post code of insert.
>>
>>61708157
code of insert is the first block I believe
>>
>>61708106
I'm not going to read your posts anymore, you're way to angry to be useful to anyone, I don't even think you understand the problem, you just want to yell at people, that was made evident by you lashing out at some random person actually trying to help. Waste of time to be honest.
>>
>>61708164
In that case it's leaking memory like crazy and crashing with a NULL pointer dereference, I'd guess.

First insert becomes root.

Second insert, root isn't null, so you do either
root = root->right
or
root = root->left
which in both cases sets root to NULL and you call the function again recursively, root is now NULL and you set root again.

Third insert, same thing happens, you set root to NULL and call insert recursively and root is now NULL so you insert it as root.
>>
>>61708198
>you're way to angry to be useful to anyone,
Fuck off, I'm not angry, I'm telling you that your conclusion is based on an arbitrary decision you've come to and not on any sound reasoning or any existing best practices.

>I don't even think you understand the problem
I do understand the problem, and I'm fucking telling you that you need to fucking consider memory alignment (also known as struct padding) when you plan to send something out on the network.

>that was made evident by you lashing out at some random person actually trying to help
That poster wasn't me you fucking moron.
>>
>>61708223
>I'm not going to read your posts anymore
Can you read mine?
>>
>>61708230
Read the entire post before responding, you huge idiot. This poster >>61707996 is not me and your entire response to me is on the assumption that he was me.
>>
File: all that shit.jpg (33KB, 318x447px) Image search: [Google]
all that shit.jpg
33KB, 318x447px
>>61708247
>>
>>61708252
You can resort to memes if you want, I was genuinely trying to tell you something about why struct padding is architecture dependent and why you should not make the assumption that it is equal on all platforms, but you seem more interested in shitposting than actually trying to learn something.

Enjoy your segmentation faults and unexpected behaviour.
>>
File: read all that shit.jpg (80KB, 643x820px) Image search: [Google]
read all that shit.jpg
80KB, 643x820px
>>61708272
>>
>>61708282
>>61708252
>>61708230
I can smell the butthurt all the way from here.
>>
>>61708198
How exactly does that post come off as "angry" to you?
>>
>>61708297
The person I'm responding to is responding to me with things that aren't relevant to what I'm asking and they're doing so in a way that shows they're upset, either at me or because of personal problem, either way it's not my job to play nanny and listen to them try and take out their aggression. They're upset, I don't know why, I don't know why you'd assume I'm butthurt. Read the reply chain.

>>61708330
Choice of words. You can tell he's frustrated specifically with the phrase "Jesus Christ". I don't think it's worth it to interact with someone in such a mood.
>>
>>61708330
Not him, but once a person goes into wallofgreentext-text mode responding to each point, the arguments pretty much over.
>>
>>61708378
It's not even an argument, I'm legitimately inquiring for information and admit I'm not familiar with this sort of thing. I think they just misunderstood my question and instead of asking for clarification assert what I meant, incorrectly. I don't think I'm at fault here, they're the ones losing their composure for seemingly no reason. I'm obviously confused as to what they're talking about and instead of them clarifying they chose to lace their posts with useless chaff that only displays to me how frustrated they are, as if that's my fault.
>>
>>61708367
>The person I'm responding to is responding to me with things that aren't relevant to what I'm asking
You asked "How can I make a 24 byte struct" and everyone ITT told you to use __attribute__((packed)) and then you started sperging out about it being non-portable, and demonstrating cognitive dissonance since you're already doing non-portable code by doing network programming.

>and they're doing so in a way that shows they're upset
The only one upset here, is you. We are just telling you that you're being ridiculous by insisting on making arbitrary distinctions between what you personally and subjectively consider "okay" to be non-portable and what you insist on having to be COMPILER independent. Yes, emphasis on compiler, because memory alignment is processor specific, so even code and assumptions produced by one compiler will be invalid on another processor family.

>either way it's not my job to play nanny and listen to them try and take out their aggression
It's not our job to respond to you either. I have better things to do than to explain memory alignment to a retard, but I do it because I want to be nice. But if you're going to lash out because we're unwilling to cater you, then fuck off.

>You can tell he's frustrated specifically with the phrase "Jesus Christ".
Because you're dumb as shit and refusing to read what he's trying to tell you. Read any book on network programming, marshalling a struct means that you need to consider struct padding.
>>
>>61708412
I can tell you're the frustrated guy by the first sentence, until you drink your juice and calm down I'm going to continue ignoring you.
>>
>>61708378
Every single of those points are valid, and it's fucking six points. Do you have ADHD if you think six points is a literal wall of text?


>>61708401
>I'm legitimately inquiring for information
No, you're reasserting your own arbitrary distinction.
>>
File: maximum-damage-control.jpg (138KB, 650x650px) Image search: [Google]
maximum-damage-control.jpg
138KB, 650x650px
>>61708427
>>
>>61708401
>explaining why you need to consider alignment boundaries to understand why sizeof a struct with three 16-bit integers is 4 bytes instead of 3 bytes
>"laced with useless chaff"

The Dunning-Kreuger is strong with you.
>>
>>61708427
I'm neither frustrated nor the same guy, but whatever dude. You come off as severely autistic, but that's pretty much what I expect from someone deciding that non-standard function calls are okay but non-standard compiler extensions somehow aren't.
>>
>>61708453
>No, you're reasserting your own arbitrary distinction.
What distinctions? I'm asking them why it would be preferable to move from a portable solution to a non-portable one, after several posts they never answered me, I don't think they understand the question, they just kept repeating themselves as to how you do it, not why you'd do it.

>>61708459
See >>61708401 I'm asking questions, that's not an argument. I legitimately don't know why they were upset in the first place or why they continue to be upset, either way it's not my job to find out or deal with it either, it's theirs. As long as they continue to show a lack of self control I'm going to ignore them flatout.

>>61708478
I don't know who's example you're referencing, in mine I used 2 members, only one of which is 16-bits in size, my struct got padded to 4bytes which is undesirable and unavoidable in a portable way, the solution I had to begin with just requests a block of 24bits and uses them, it's simple and standard. I've yet to hear the argument why I should consider a struct over this method, nobody has told me yet.

Useless chaff is them inserting their personal problems into their posts, I don't care if they're frustrated, why should I, why should you or anyone else here have to listen to that? Take that shit to your friends or blog or wherever.

>>61708504
Sure thing bud, whatever helps you cope.
>>
>>61708504
>why prefer functions over compiler extensions
In case this isn't bait it's easier to port
>>
File: panasonic-toughbook-cf18.png (1004KB, 1024x768px) Image search: [Google]
panasonic-toughbook-cf18.png
1004KB, 1024x768px
Hy /dpt/, how are you? Me, I found my new favourite shitlang. https://try-hy.appspot.com/
>>
>>61708537
>I'm asking them why it would be preferable to move from a portable solution to a non-portable one,
First of all, network code is non-portable by definition.

Secondly, relying on the compiler to do the job and choose the alignment boundary for you is also non-portable when you rely on having two separate systems interact with each other.

If you're going to send a struct over the wire, you can't make any assumptions on the underlying byte representation and you need to think about this.

If you don't want to pack the struct, I suggest doing something like the following:

struct my_struct
{
int16_t first, second, third;
};

// whatever
struct my_struct* sptr = // also whatever
char buffer[sizeof(int16_t) * 3];
int16_t* ptr = (int16_t*) buffer;
*ptr = sptr->first;
*(ptr + sizeof(int16_t)) = sptr->second;
*(ptr + 2 * sizeof(int16_t)) = sptr->third;

send(sock, ptr, sizeof(buffer), 0);


And on the other side do something like this:
char buffer[sizeof(int16_t) * 3];
recv(sock, buffer, sizeof(buffer), 0);
struct my_struct s;
int16_t* ptr = (int16_t*) buffer;
s.first = *ptr;
s.second = *(ptr + sizeof(int16_t));
s.third = *(ptr + sizeof(int16_t) * 2);
>>
>>61708597
>Since Hy transforms its Lisp code into the Python Abstract Syntax Tree, you have the whole beautiful world of Python at your fingertips, in Lisp form!

but why
>>
>>61708570
>easier to port

#if defined(__GNUCC__)
struct my_struct
{
int16_t i;
int8_t b;
} __attribute__((packed));
#else if defined(__MSVC__)
#pragma pack(push,1)
struct my_struct
{
int16_t i;
int8_t b;
};
#pragma pack(pop)
#endif


OH WOW SO DIFFICULT TO PORT
>>
>>61708617
Python has a bytecode that's more way more expressive than its shitty syntax. Hy leverages the bytecode's power, just like Clojure does to the JVM.
>>
>>61706142
this is a bad analogy against manual memory management though
>>
>>61708537
>I've yet to hear the argument why I should consider a struct over this method, nobody has told me yet.
As we've told you repeatedly, you can pack the struct, which allows for nicer code.

Instead of doing this: >>61708612

You can do this:

struct packed
{
int16_t i;
int8_t b;
} __attribute__((packed));


struct packed* ptr = // whatever
send(sock, ptr, sizeof(struct packed), 0);


struct packed p;
recv(sock, &p, sizeof(p), 0);
>>
wtf C++ doesn't have associative arrays?
>>
>>61708711
#include <map>
>>
>>61708711
It has maps.
>>
>>61708718
You never actually want to use std::map.
>>
>>61708722
How come?
>>
>>61708728
It's a terrible, inefficient data structure with the restrictions the ISO standard mandates.
>>
>>61708738
Why is C++ so shit?
>>
>>61708743
Because the ISO and the language are too large.
>>
>>61708738
>inefficient data structure
How is it any different than any other language's implementation of associative arrays?

std::map = RB tree
JavaScript objects = RB tree
Java TreeMap = RB tree
Python dicts = RB tree

???
>>
>>61708612
>network code is non-portable by definition.
I'm not asking about network code, I'm asking how to serialize data. The other person keeps bringing up the network because that's where this data is going to go but the question is pertaining to serialization itself, prior to the data being sent. I really don't know why this keeps being brought up, it's not really relevant.

This is the original question >>61706658
So what I'm asking is, why should I do something like your example there instead of this? Is there a benefit? Your example is a little different too, my datatypes are not all 16bit which is where I'm running into issues >>61707732
when using types of different sizes the padding becomes an issue.

>>61708705
I've mentioned several times that it's not portable compared to the solution that's already in place. "Nicer code" is subjective, I'm looking for things that are measurable and practical. If the only difference is that this is somehow more visually appealing to you personally then that's not really an argument as to why I should use that over the current solution. I don't know why that's so hard to understand. I don't think it's worth it to sacrifice portability for prettiness when the in place solution isn't ugly to begin with.
>>
>>61708764
Oh, PHP associative arrays = RB tree
>>
>>61708635
>gcc and msvc are the only compilers
>every compiler has a pack equivalent
lel
>>
>>61708764
Because in a good language, a RBtree and AA are two different things.
>>
>>61708768
>So what I'm asking is, why should I do something like your example there instead of this? Is there a benefit?
You can do what you're doing, but you have to be careful when shifting. Shifting an 8-bit up by 16 is okay.

This, however, is not okay:
void *z = malloc(24);
*(uint32_t*)z = (x << 16) | y;


Assuming malloc returns a non-aligned chunk of memory, this will not work on big-endian machines, and it only works on your machine because it's little-endian.
>my datatypes are not all 16bit which is where I'm running into issues
That's because you're doing a union of a struct and a bitfield, you should probably use an array instead.

>If the only difference is that this is somehow more visually appealing to you personally then that's not really an argument as to why I should use that over the current solution
If code is easier to read it is
1) easier to maintain
2) easier to understand the intention of the programmer
>>
>>61708789
Both GCC and Clang support GCC extensions?

If you're using any other compiler than those three, you're probably compiling for embedded (aka nothing is portable whatsoever) and need to consider alignment in everything you do all the time anyway.

>>61708809
Name one language where AA is not implemented as an RB tree.
>>
>>61708764
Python's dicts aren't trees since several years.
>>
>>61708850
Well, then it's implemented as a hash table, which is inefficient as fuck in terms of memory use but yields decent lookup and insertion time.
>>
>>61708838
>Assuming malloc returns a non-aligned chunk of memory
malloc is guaranteed to return a pointer with alignment strict enough for any type.
>>
>>61708738
>a terrible, inefficient data
are you sure it's still is?
>>
>>61708865
>malloc is guaranteed to return a pointer with alignment strict enough for any type.
This is "standard speak" for byte-aligned.
>>
>>61708849
D
>>
>>61708899
I can't find the discussion on complexity anywhere, so I assume you're telling the truth.
>>
>>61708899
>d
unordered (like std::unordered_map)
>>
>>61708654

Right, but at least the JVM has some decent performance for a bytecode platform. Python runs like ass, so it would be a silly platform to target.
>>
>>61708955
>>61708951
Unordered implies hash table, since only trees have ordering guarantees.
>>
>>61708951
>>61708955
see for yourself
https://github.com/dlang/phobos/blob/master/std/container/rbtree.d

https://github.com/dlang/phobos/blob/master/std/array.d
>>
>>61708980
I'll take your word for it, since anon said it was unordered.
>>
>>61708968
>>61708980
he comapres std::map to D's AA which is wrong since std::map is ordered. he shall compare D's AA to std::unordered_map
>>
>>61708996
That's a good point.
>>
also, the fastest generic hash table you could find is probably https://gcc.gnu.org/svn/gcc/trunk/libiberty/hashtab.c
>>
>>61709010
But also the most pain to work with.
>>
File: fg2-screenshot-03.jpg (236KB, 1280x1024px) Image search: [Google]
fg2-screenshot-03.jpg
236KB, 1280x1024px
I wonder what language/library Fantasy Grounds was made in.

Somebody knows?

For an interface with that many textures and images, would it make sense to use something like SDL?
>>
>>61708838
>Assuming malloc returns a non-aligned chunk of memory
I don't fully understand this part, could you elaborate? What would it return and why would this break on big-endian? I only understand what endianess is not the implications of it, or rather what is affected by it.

>>61708838
>you should probably use an array instead
I'm not sure I follow here either. The struct is what's padded and forcing the union to be 4 bytes instead of 3, doing this still results in 4 bytes for me.
union {
struct {
uint8_t header;
uint16_t payload;
};
unsigned char bytes[3];
} test;


>If code is easier to read it is
The problem here is that the proposals haven't been easier to read nor understand. The original seems pretty concise and as easy to understand as anything else. It's just casting and shifting much like the examples so far are mostly casting and struct alignment.
>>
>>61708849
>clang and gcc are the only compilers
lel
>>
>>61709045
the only relevant ones, yes
>>
>>61709023
>I don't fully understand this part, could you elaborate?
Okay, first of all, malloc(24) allocates 24 bytes and not 3. Obviously that works fine, since 3 bytes will always fit inside a 24 byte buffer.

I assumed you meant 24 bits as in 3 bytes. If that's the case, then the following is my reason.

Imagine you have this memory layout, the number is the byte count
+-+-+-+-+-+-+-+...
|0|1|2|3|4|5|6|...
+-+-+-+-+-+-+-+...


So
malloc(3)
will reserve bytes 0, 1, and 2 and return a pointer to the address starting at byte 0.

Now, casting that pointer to an
uint32_t
pointer, implies that the pointee is 4 bytes, not 3. So now, when you try to write into the cast pointer, it can potentially try to write to bytes 0, 1, 2, and 3, even though you've only reserved up to byte 2.

Obviously, since you in your example have allocated 24 bytes rather than 3, it works. But if you replace 24 with 3, it might work and it might crash, depending on the implementation.

>The struct is what's padded and forcing the union to be 4 bytes instead of 3, doing this still results in 4 bytes for me.
Yes, you still need to pack the struct. Sorry, I assumed you understood this.

>The problem here is that the proposals haven't been easier to read nor understand.
> It's just casting and shifting much like the examples so far are mostly casting and struct alignment.
As someone who programs for a living, I disagree. Casting and shifting is a lot more hassle to read than just passing a struct pointer around.
>>
>>61709045
For non-embedded, yes, sure. I mean, you can always use icc, but very few people do.
>>
>>61709076
Clang is stupid apple shit.
GCC is the one and only true compiler.
>>
>>61709076

SDCC might also be considered relevant for some embedded platforms not supported by GCC and Clang. However, it is worth noting that SDCC makes all structs packed by default. One could set up a macro that would use the __attribute__((packed)) style of declaration for GCC and Clang, the #pragma pack style of declaration for MSVC, the declaration on its own for SDCC, and an error for any other compiler.
>>
I don't understand the "Rust doesn't have linked lists meme"
https://doc.rust-lang.org/std/collections/struct.LinkedList.html
>>
>>61709091
>I assumed you meant 24 bits as in 3 bytes.
I did, my mistake. I must have just slipped with the talk of bits and bytes.

>I assumed you understood this.
I'm very unfamiliar with the C semantics for working with bits like this, sorry for the burden but I'm finding it difficult to find resources on this, especially without knowing the vocabulary.

If I'm not packing and I have these extra bytes of padding that will vary from platform to platform, how is this typically dealt with? Would I just do as you've done here >>61708612 and force all the datatypes to be of the same size as the largest member?

I appreciate the patience.
>>
File: mods-are-gay.png (52KB, 613x410px) Image search: [Google]
mods-are-gay.png
52KB, 613x410px
>>61709219
It's a /g/ meme/troll. We spent literally several months shitposting about linked lists vs arrays.

Pic related, because mods are retards.
>>
>>61709020
https://www.fantasygrounds.com/forums/archive/index.php/t-35861.html
>>
>>61709263
Mods are computer illiterates, otherwise there wouldn't be hundreds of winshill bait thread everyday
>>
>at interview
>How would you display 5000 items in a list accounting for performance?
>>
>>61709248
>If I'm not packing and I have these extra bytes of padding that will vary from platform to platform, how is this typically dealt with?
Well, usually stuff sent over network is explicitly padded up to the nearest 32-bit word (because that's sort of agreed upon), so you'd typically see struct definitions such as this:

struct message
{
uint8_t header;
uint16_t payload;
uint8_t padding[1];
};


This is convenient if you have tonnes of members. However, this doesn't account for byte ordering, which is something you also might consider.

In that case, you'd create a buffer and then place members in manually, so'd you do something like this.

// assume the same struct definition as above

ssize_t send_struct(int sock, const struct message* msg)
{
char buffer[3];
*((uint8_t*) buffer) = msg->header;
*((uint16_t*) (buffer + 1)) = htons(msg->payload); // note the call to htons

return send(sock, buffer, 3, 0);
}


ssize_t recv_struct(int sock, struct message* msg)
{
char buffer[3];
ssize_t retval = recv(sock, buffer, 3, 0);
msg->header = *((uint8_t*) buffer);
msg->payload = ntohs(*((uint16_t*) (buffer + 1))); // note call to ntohs
return retval;
}
>>
If I want to be a contrarian hipster should I love Javascript or hate it?
>>
>>61709359
Write a blog post about 1 and then another one in 2 months expressing the opposite emotions.
>>
>>61709359
Hate it, and namedrop all the most recent frameworks as the reason why you don't like it. It is imperative that it is the very newest ones, otherwise people will call you out on being dated because framework X has deprecated framework Y two days ago.
>>
>>61709359
hate it, you should like typescript and dart
>>
>>61709333
"Why would I be using the wrong container for the situation?"
>>
>>61709382
TypeScript is not hipster, it's enterprise shit.

Dart is too old, that was hipster 2-3 years ago.
>>
>>61709333
I don't understand the question
>>
>>61709394
Hipsters like to cling to old shit, like "hurr durr 70's were the best" or "I am born in the wrong generation"
>>
>>61709430
hold on a sec
So C programmers are the ultimate hipsters?
>>
>>61709333
All at once or a subset?
>>
>>61709430
>>61709456
>Hipsters like to cling to old shit,
Only ironically.

They wear afros and mustaches and 70s sweaters because they think it is making an ironic statement.
>>
>>61709456
No anon has the wrong idea. Hipsters cling to whatever is unpopular. C is a very popular language still.
I'd you're looking for hipsters you'll find them in a field that has tons of new trends. Because when a trend is established they wish to move on at all costs.

Webdevs.
>>
>>61709456
Yes
>>
>>61709346
Thank you for the explanations, I think I understand it now and will experiment with it a bit more, looking at things in the debugger on both an x86 and a PPC64 machine.
>>
>>61709477
Really. Do you see webdevs come in here asking about the same shit all the time? If we consider app development libraries we only talk about <20 libraries really.
With webdevs every time they come here they're asking about some new hip library. And they're always asking about libraries. They don't ask for programming advice. How to control complexity or whatever. It's because they're hipsters who don't have time to spend on anything but learning new useless libraries.
And that's why webdevs suck. They're for the most part not stupid. They're just kept busy learning useless stuff they won't have any use for in a year. Or even a couple months.
>>
>>61709456
No people using Algol or some other dead language in 2017 could be classified as such.
>>
HS dropout and a very mediocre programmer, been doing it on and off since a young age and although a solid handle on most concepts related to computing and programming. Would like to learn/relearn math, because im literally retarded in that department, but mostly just to apply to general programming without any specific intention of field or end goal. What sort of math should I work towards?
>>
>>61709544
Discrete mathematics, graph theory, numerical series and set theory, Boolean logic, relation theory for starters.
>>
>>61709559
Do I really need all that to program games? Seems a bit excessive.
>>
>>61709559
damn nigga i just want to make games like black ops and far cry
>>
I'm learning C++ and Rust in parallel and I have a question regarding Rust.
fn main() {
let x: &str = "abcdef";
let y = String::from("abcdef");
println!("{:?}", x == y); //prints true
}


Now as far as I understand, x is a reference to a string, right? and y is an actual string. So how come a pointer is equal to a String?
>>
>>61709559
thanks anon, ill look into that
i think someone is doing an ebin /v/ troll
>>
>>61709604
learn linear algebra den
>>
>>61709605
>std::string::String
Ah yes, the power of Rust.
>>
>>61709544
>without any goal
I say learn it as you go but if you don't want that then:
>>61709559
Is a good set.
>>61709604
Then you need 1,2,3 and 5 on that list and add in linear algebra instead.
If you're just making a crappy game (unlike the call of duties) then you just need linear algebra. Linear algebra is important for any game.
>>61709601
>>61709604
>>61709622
Nobody even mentioned games?
>>
>>61709642
There are differences between str and String
>>
>>61709657
Yeah, i saw, and its pretty ridiculous and unnecessary.
>>
>>61709657
Lol

who would have thought, heh
>>
>>61709605
Not a rust programmer but maybe they do implicit dereferences as you normally do with references (not pointers).
I'm guessing the reference is like a C++ reference, not a pointer.
>>
>>61709644
the tricky part about that is go where, since I dont have a pathway or reason to program anything at the moment, it's just something I know a good amount about and would like to be able to use math to make pet projects of some sort

I suppose I do need to learn FP at some point though
>>
Writing a C11 compiler in Agda.
>>
>>61709694
prove that Agda is strictly superior to C
>>
>>61709705
Agda can actually run on embedded syste.. oh wait
>>
>>61709672
Thanks anon
>>
>>61709684
Just set a goal. Make a Pac-Man or something.
Programming is a craft. You get better at it as you practice.
The math is usually there for very specific things. If someone motivated all their code through math they'd be a very slow programmer and they'd probably not be all that much better than other programmers.

So find something to do and expand.
>>
>>61709716
Agda can actually run on embedded systems.

Step 1) Redefine C
Step 2) FFI
>>
>>61709743
>FFI
That's not Agda
>>
https://www.youtube.com/watch?v=K7Hn1rPQouU
>>
>>61709333
IsVirtualizing="true"


That, and set it to recycling mode if each item is a complex custom control embedded in the list-based control.
>>
>>61709749
Yes it is, you're simply asserting that these values exist, constructing Agda values that constitute a program and then extracting/compiling that program along with another library into another language
>>
>>61709772
>IsVirtualizing="true"
whats this
>>
>>61709605
Doesn't it just use operator == and compare both contents in which case that's why it's true.
There's no pointers involved, I think & in Rust is some lifetime bullshit.
>>
>loop is slow
>rewrite to SSA form before optimizing to make it easy to work with
>loop is now 3x faster
Well done sepples.
Zero cost abstractions my ass.
>>
>>61709798
Thing culling in graphics rendering, except for a GUI.

"The standard layout system creates item containers and computes layout for each item associated with a list control. The word "virtualize" refers to a technique by which a subset of UI elements are generated from a larger number of data items based on which items are visible on-screen. Generating many UI elements when only a few elements might be on the screen can adversely affect the performance of your application. The VirtualizingStackPanel calculates the number of visible items and works with the ItemContainerGenerator from an ItemsControl (such as ListBox or ListView) to create UI elements only for visible items."

https://msdn.microsoft.com/en-us/library/system.windows.controls.virtualizingstackpanel.isvirtualizing(v=vs.110).aspx
>>
>>61709831
Why wouldn't that be the default?
>>
>>61709802
what's SSA form?
>>
>>61709705
agda-a-qt : C ≱ Agda
agda-a-qt = {!!}
>>
>>61709802
Sepplesfags always go on about their zero-cost abstraction fairies, but it's all a load of fucking shit.
>>
>>61709872
static single assignment
>>
>>61709853
It is, on most controls, but it can also introduce issues.

Consider that the elements are rendered "on-the-fly", which can cause slowdowns as the user scrolls through the list. In some cases, you may want to go ahead and render the entire list before showing it. Some of these issues are alleviated by recycling, but at the end of the day, there's pros and cons to "load fully, then show" and "lazy load, and figure it out as you go".
>>
>>61709605
If you want to compare memory addresses, use ptr::eq
>>
Any ideas where to start laerning programming from a minimum level.
I only know the basics of Java anda bit of C
>>
File: superthumb.jpg (21KB, 300x250px) Image search: [Google]
superthumb.jpg
21KB, 300x250px
How do I learn to extract data from JSON?
For example, if I wanted to get the thread subject (/dpt/ - Daily Programming Thread) from http://a.4cdn.org/g/thread/61705964.json how would I go about doing that? In Python.
>>
>>61710135
>How do I learn to extract data from JSON?
Oh, this is easy, you can ju-
>In Python.
Never mind.
>>
>>61710155
Can you elaborate?
>>
>>61710185
It's easy in Python, don't get me wrong. You can likely accomplish what you're trying to do with it, but I'll be damned if I'm going to bother looking up the docs for that shitlang.
>>
>>61706603
The point of RISC is getting as close to control signals as possible. Since control signals for conditional execution would have been left unused and they had 4 bits out of 32 left, they decided to use them this way. Back when it was first proposed predictors were a pipe dream for the market they were selling processors to.
>>
Why is optimization so satisfying?
>>
File: 123456.png (34KB, 783x553px) Image search: [Google]
123456.png
34KB, 783x553px
>>61710155
install requests and
made a one liner for you
>>61710135
print (__import__('json').dumps(__import__\
('requests').get("http://a.4cdn.org/g/thread/61705964.json")\
.json()["posts"],indent=2))
>>
File: umarusee.jpg (113KB, 1280x720px) Image search: [Google]
umarusee.jpg
113KB, 1280x720px
>>61710135
import urllib.request as req
import json

# fetch and return a json object from an url
def get_json (url):
request = req.urlopen(url)
txt = request.read().decode('utf-8')
return json.loads(txt)

# example of use
js = get_json("https://a.4cdn.org/g/thread/61705964.json")
print(js["posts"][0]["sub"]) # prints subject of first post (= op post = thread subject)
>>
>>61710227
At first you get the feeling something is bad. Then you get the feeling that things are better than expected.
It's a Skinner box.
But forget that I said that. It does nothing but hurt your ability to enjoy it.
>>
>>61710240
>>61710254
Appreciate these. Thanks a bunch.
>>
File: 1444061512754.png (685KB, 1321x1080px) Image search: [Google]
1444061512754.png
685KB, 1321x1080px
>>61710254
cute~
>>
>>61706939
bltzall
a best
Who had the idea this was ever going to be used enough?
>>
File: 887[1].png (323KB, 600x600px) Image search: [Google]
887[1].png
323KB, 600x600px
>>61710302
>bltzall
A-anon
>>
File: programming considered harmful.png (87KB, 853x621px) Image search: [Google]
programming considered harmful.png
87KB, 853x621px
>>61706241
In the time OCaml got traction, its concurrency model wasn't so stupid. In the 90s, Intel and co. made the industry dream of THz single-core CPUs, so SMP and multi-core needed not apply in that concurrency model.
But the housefire fiasco of the later Pentium 4s (Brescott :DDD) put that dream to the ground. RIP OCaml.

>>61706300
>pic related
>>
Is C for Dummies a good starting point if you know nothing about it?
>>
>>61710453
>For Dummies
The answer is never. Get C Programming: A Modern Approach
>>
>>61710453
Youtube is better...
>>
>>61710205
>It's easy
>You can likely accomplish what you're trying to do with it
>shitlang
Ogay
>>
>>61706853
You can at least use prepare-to-branch instructions (as in the Cell) instead of fixed delay slots.
That being said, though, on OoO architectures it probably doesn't help that much in reality, since the distance from where the condition result is available for a prepare-to-branch instruction to the actual branch instruction is likely tiny compared to the OoO window, especially for tiny loops.
>>
>>61710489
>>61710496

Interesting, what makes it bad? I just picked it up on the library. I'll look into that book and Youtube. Any recommended channels?
>>
File: bltzall.png (41KB, 1701x2201px) Image search: [Google]
bltzall.png
41KB, 1701x2201px
>>61710339
>branch on less than zero and link likely

>>61710135
https://docs.python.org/2/library/json.html
https://docs.python.org/3/library/json.html
>>
So /g/ doesn't have any mods at all?
>>
>>61710295
What does Akari smell like?
>>
File: 1498966480903.png (87KB, 975x522px) Image search: [Google]
1498966480903.png
87KB, 975x522px
Looks like C++ is trying to emulate D-style ranges, lads
https://stackoverflow.com/questions/18549717/are-there-any-c-language-obstacles-that-prevent-adopting-d-ranges
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4382.pdf
https://github.com/ericniebler/range-v3
>>
>>61710828
I encourage C++ to steal as much as the ISO want. The more it steals the worse it gets and closer to full implosion.
Any feature it adds will ultimately be a dim comparison and make the language even more unusable.
>>
>>61710828
kek
>>
>>61710602
download visual studio community edition and just start coding something
>>
File: 1484699914718.jpg (993KB, 1182x1581px) Image search: [Google]
1484699914718.jpg
993KB, 1182x1581px
>>61710883
Good goy. 12 shekels have been deposited to your online MS evangelism account
>>
>>61710898
You're not funny.
>>
>>61710928
He's clearly pointing out the unhealthy attitude MS has towards developers and recommending anon to reconsider his preference of compiler.
>>
File: git cheat sheet.png (336KB, 1100x850px) Image search: [Google]
git cheat sheet.png
336KB, 1100x850px
What's the easiest way to break up old commits into smaller ones and maintain the timestamp before publishing? Do I just have to manually go back, break them up into patchs, commit those, and rebase or Is there a tool that makes this easier when dealing with multiple commits?
>>
>>61710928
You are not helpful.
>>
>>61710849
>>61710828
Why do people hate C++ so much?
>>
>>61710898
I actually posted this on /g/ but everyone ignored my thread ;_;
>>
>>61710959
Because it has no direction.
>>
>>61710959
Its single-handedly ruined generations of programmers, plagued every corner of software, held us back decades. And the worst part is we wont see it completely die until most of us are on our deathbeds.
>>
>>61710959
>Why do people hate C++ so much?
Because it's a poor compromise and people praise it far more than they should. Especially people who don't understand it. I'd wager most C++ programmers are actually better served by languages like Rust/D/Go. The rest are better served by C.
Then there's the committee who don't really do any programming in the language. I'm not sure they belong anywhere else.
>>
>>61710795
seriously
why is there a porn thread on this board right now?
>>
>>61710993
Well put
>>
>100,000++ line 1.5 year old application
>I became the lead developer halfway through
>written entirely by interns
>costing states 100s of thousands of dollars with bugs
>just given permission to write integration tests now
>just getting a decent QA strategy now
>just given permission to introduce PRs now
>code is riddled with duplication and anti patterns and terrible error handling and terrible UX
has anyone had a project that recovered from worse?
>>
File: ZPw0TAj.jpg (215KB, 800x570px) Image search: [Google]
ZPw0TAj.jpg
215KB, 800x570px
In C++, what's the best way to handle signed/unsigned arithmetic? (Specifically, uint8_t += int8_t).
>>
>>61711053
Cast them to the same type. :^)
>>
>>61711021
I hope youre porting modules at a time in a better language that i assume is probably sepples/C#.
>>
>>61711071
we're not making any drastic changes until we have tests.
>>
File: Luba.jpg (189KB, 791x1200px) Image search: [Google]
Luba.jpg
189KB, 791x1200px
>Netflix releases deep learning library in D as free software
https://medium.com/@NetflixTechBlog/introducing-vectorflow-fe10d7f126b8
>>
>>61710945
I haven't had a need to check it out myself, but my understanding is that this is what programs like Quilt are for.
>>
>>61711124
Youre late m8.
You should check out Ebay's stuff for working with giant data chunks. The D implementations are actually faster than C stuff.
>>
>>61711189
I'll check it out, thanks.
>>
>>61711058
Not sure what the caretnose is for, because that's literally what you should do. The compiler will enforce conversion to one or the other anyway, so just make it explicit what you want to do instead.
>>
Why is C so shit?

#include <stddef.h>
#include <limits.h>
#include <assert.h>

static void foo(char bar[static 1]) {} // valid function

int main(void) {
int x;
short y;
ptrdiff_t z = &x - &y; // undefined behaviour
short *w = &x; // undefined behaviour
char shit = "crap"; // read-only, without const
char crap[] = "shit"; // works fine
int bar = INT_MAX;
++bar; // undefined behaviour
assert(~x - 1 == -x); // not guaranteed by the standard
char mc = 'haha'; // this is valid implementation-dependant code
// no return needed for main because lol
}
>>
>>61711257
There's literally nothing wrong with any of that.
>>
>>61711257
also

const int x;
int *y = &x;
*y = 5; // undefined behaviour, even though x is not constexpr
>>
>>61711257
Because it was a half/ass improvement on B to the point of being called B-
>>61711281
(you)
>>
>>61710982
>>61710990
>>61710993
*tips fedora*
>>
>>61711257
>>61711289
You are surely aware of the reason behind any of those instances of undefined behavior, so why are you complaining about them?
>>
>>61711327
Well for one, any assert that cant assert needs to throw a compiler error. But god forbid the C compiler make your life easier with a shred of quality of life.
>>
>>61711327
You have to dig deep into the standard to find these pitfalls. C is so outdated it doesn't even assume a linear memory model.
>>
>>61711345
If you're talking about static asserts they made it in C11. Most C programmers either don't know about them, refuse to use C11 or call it bloat.
>>
>>61711345
But that assertion isn't necessarily false, since, as you wrote, the standard doesn't guarantee that. And there are reasons the standard doesn't, in order to include architectures that you might just not know about.
>>61711352
>it doesn't even assume a linear memory model.
Well indeed, because it's used on architectures that don't have linear memory models.
>>
new thread when?
>>
>>61711403
On bump limit, faggot.
>>
>>61711375
>that you might just not know about
>Sacrificing the convenience of 99.999% of programmers for the 0.001% of machines that practically nobody uses.
How smart.

>Well indeed, because it's used on architectures that don't have linear memory models.
Like what? Also, what machines don't use 2's complement?

Maybe we should expand the undefined behaviour to support machines with less then 8 bits in a byte, or that compute in ternary/decimal instead of binary?

Also, it's 2017. #include <threads.h> is not implemented in the most widely deployed libc, the mingw wrapper.
>>
jesus
I kinda got in to programing and now I am updating some older work of mine

I cant get in to it, concentrating solely on it like I used to
I write 4 lines, its go in to browser check 4chan
I get back, edit some shit and its again browser time checking reddit
I write another few lines and its reddit <new> section now,...

fuck I dunno, maybe thats because project is done and adding some bells and whistles cant capture my full attention.. at least I hope so that its that
>>
>>61711564
go blog about it on reddit you dumb faggot
>>
>>61710959
same reason why they hate java, it's good and popular, and they project their own failings onto the language
>>
My game engine is coming to life
// Core
void dgInit(void);
void dgExit(void);
void dgLoopInit(float r, float g, float b);
void dgLoopExit(void);
bool dgMustExit(void);
float dgGetWinW(void);
float dgGetWinH(void);

// Cfg
typedef struct { float sclx, scly, movx, movy, rot, r, g, b, a; } DgCfg;
void dgCfgModel(const DgCfg *cfg);
void dgCfgSpace(const DgCfg *cfg);
void dgCfgWorld(const DgCfg *cfg);

// Batch
void dgBatchVertex(float x, float y, float r, float g, float b, float a);
void dgBatchTriangle(float x1, float y1, float x2, float y2, float x3, float y3, float r, float g, float b, float a);
void dgBatchRect(float x, float y, float w, float h, float r, float g, float b, float a);

// Frames
typedef struct DgFrames DgFrames;
DgFrames *dgFramesLoad(const char *path);
void dgFramesFree(DgFrames *frames);
int dgFrameCount(const DgFrames *frames);

// Draw
void dgDrawBatch(void); // mode=triangles, start=0, end=all, reset=true
void dgDrawFrame(const DgFrames *frames, int frame);
>>
New thread:

>>61711760
>>61711760

>>61711760
>>61711760

>>61711760
>>61711760
>>
>>61711764
thank you
>>
>>61710135
I know you want this in your Python script directly, but here's a neat thing you can do with Python's json module:

curl http://a.4cdn.org/g/thread/61705964.json | python -m json.tool
>>
is there a concise way to define an array of structs in rust?

C/C++ makes this shit pretty simple, I really enjoy the freedom of positional (unnamed) struct members that still have a name when you actually want to use them

the closest thing I can seem to find is, writing a function that takes each member and returns a valid struct, but it's still a lot more typing for such a simple data definiton

this type of shit is why I can never seem to settle into rust programming, there's so much that becomes a hassle for no real reason
Thread posts: 315
Thread images: 29


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

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
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.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.