[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: 316
Thread images: 31

File: 1476800164142.jpg (54KB, 240x248px) Image search: [Google]
1476800164142.jpg
54KB, 240x248px
What are you working on, /g/?

Old thread: >>58781539
>>
https://www.youtube.com/watch?v=O1bsHR2DFvk
>>
File: barron.jpg (115KB, 1000x583px) Image search: [Google]
barron.jpg
115KB, 1000x583px
>>58787146
>What are you working on, /g/?
>>
File: anal beads.png (230KB, 1138x232px) Image search: [Google]
anal beads.png
230KB, 1138x232px
This made has written an operating system.

What are you doing with your life, anon?
>>
can you stop using different OP images each thread
>>
>>58787176
no
>>
File: 1472275794481.jpg (158KB, 850x850px) Image search: [Google]
1472275794481.jpg
158KB, 850x850px
>>58787172
Writing an operating system, I've got a basic interrupt based keyboard driver working.
>>
I'm a spacemacs + intero missile now

https://github.com/syl20bnr/spacemacs
https://github.com/commercialhaskell/intero
>>
>>58787257
OSGTP?
>>
"I had a crisis of faith and thought the Sun was god

God gets angry when you do that"

This dude wrote a variation of C, his own compiler for it, then wrote an OS in it. And I still forget semi colons.
>>
>>58787265
!JohnsonY5g
>>
>>58787295
Don't feel too bad anon, he's literally psychotic, a genius, but still psychotic.
>>
>>58787265
>me using haskell

Come on, you know better.
>>
>>58787146
Just put up this website
www.symmetr.io

let me know what you think
>>
File: tad.png (188KB, 1132x233px) Image search: [Google]
tad.png
188KB, 1132x233px
>>58787295
>>
>>58787376
God seems like a very reasonable person from this example.
>>
>>58787231
>flower elephant
what did he mean by this?
>>
>>58787452
pooter and dong
>>
>>58787452
The flower is the asshole, the elephant is the butt cheeks and benis

come on dude
>>
>>58787459
why would a girl have a dong??
>>
>>58787475
Why not?
>>
Will you be affected by the changes to H1-B visas?
>>
>>58787700
I've already been affected positively.

One of our clients was going to reduce our support and H1-B in a curry.

Curry can't get in due to recent changes.
>>
can I make this any smaller?
#include <stdio.h>

int main() {
for(char c, l ; (c = getchar()) != '\n' ;) {
putchar((c == l && l == ' ') ? 0 : c);
l = c;
}

return 0;
}
>>
File: autism.gif (2MB, 500x342px) Image search: [Google]
autism.gif
2MB, 500x342px
>>58787163
>>
>>58787774
Huh, you would have thought that the client would be prepared to pay a bit more to get someone so skilled that they can only be found abroad.
>>
>>58787804
That's the issue; H1-Bs are meant to find talent when that talent is unavailable in the US.

What they're actually used for is to import (relatively) cheap labor, with the bonus that they can overwork the fuck out of said employee without fear of that employee leaving.
>>
>>58787790
That doesn't even work for me. It doesn't remove the spaces anymore, it just echos back what I type
>>
>>58787845
Oh, definitely.

I dislike many of Trump's policies but doing something to curb H1-B abuse is absolutely a good thing, in my opinion.
>>
>>58787857
works for me, what are you typing
#include <stdio.h>

int main() {
for(char c, l ; (c = getchar()) != '\n' ; l = c)
putchar((c == l && l == ' ') ? 0 : c);

return 0;
}
>>
File: Untitled.png (15KB, 613x437px) Image search: [Google]
Untitled.png
15KB, 613x437px
>>58787875
>>
File: t.png (14KB, 689x335px) Image search: [Google]
t.png
14KB, 689x335px
>>58787895
Don't know what to say desu
>>
>>58787475

>implying girl
>>
>>58787943
Girls are better than boys. You can stop pretending to be a boy and take off that fake beard, Ruby.
>>
>>58787475
all girls have dongs

also, java is the best language
>>
>>58787954
Java 8 is unironically semi-decent.
>>
>>58787953

>Implying pretending

>>58787954

If all girls have dongs, what do you call someone with a vagina? Also, C# is better than Java.
>>
>>58788004
>If all girls have dongs, what do you call someone with a vagina
disabled

fuck C#
>>
>>58788004
>what do you call someone with a vagina
A girlyboy.
>>
>>58787922
I can't get your code to work. Dunno why. Windows 10, CodeBlocks IDE with GCC as my compiler. Compiling as C not C++.

This code did work though
int main() {
for(char c, l ; (c = getchar()) != '\n' ;l = c)
if(!(c==l && l == ' ') ) putchar(c) ;
return 0;
}
>>
I'm using foldr to check for an element in a list, and I want to break when I find it, rather than continuing the fold until its end.

I think call/cc can be used for this? But I'm confused about how to do it? No matter how I try to implement it, it seems to continue the fold.
>>
>>58788064
In Haskell it just werkz because of lazy evaluation.
>>
>>58788063
it seems the problem is in my terminal putchar(0) doesn't print anything while in your terminal putchar(0) is printing a space.
>>
>>58788063
After doing some testing, it seems that if I do putchar(0) I get a space, but you seem to not? Dunno how that should work, I don't usually implicitly cast numbers to char
>>
how do you make a program that locks the terminal window so it can't scroll, where the entire window becomes the program instance? I only know how to make programs that print shit to stdout on individual lines
>>
>>58788083
thanks for nothing

It was a minor syntax hiccup on my part btw
everything is fine now
>>
>>58788115
ncurses
>>
>>58788122
How did they program ncurses though

Everytime someone answers with a library it just leaves me wondering how they did it with the library. If ncurses can move a cursor around a terminal then clearly there is a way to do it in C
>>
File: Capture.jpg (53KB, 987x471px) Image search: [Google]
Capture.jpg
53KB, 987x471px
https://forum.dlang.org/thread/[email protected]
Something big going on over in the D forums apparently
>>
>>58788182
D is dead
>>
>>58788166
look at the termcap/terminfo databases

terminals accept special control characters that move the cursor, print characters, erase characters, change colors, etc.

terminfo.termcap is a database that says what the control codes are for each terminal.
>>
>>58788186
Nope
>>
>>58788188
so ncurses just makes it so you don't have to write a different version of everything for every type of terminal, doesn't it
>>
>>58788063
this should also be faster than
>>58787875
since the putchar function isn't called when it doesn't need to be.

I believe it cannot be optimized any more than this.
>>
>>58788198
yeah + other higher level features like reading a whole string instead of character by character, windows, etc
>>
dead board
>>
>>58788349
it's the middle of the night, pal
>>
>>58787474
.... brb deleting picture from hard drive

it was supposed to be a cute grill damnit
>>
File: 1460883403030.png (28KB, 470x241px) Image search: [Google]
1460883403030.png
28KB, 470x241px
>>58788004
>>
File: felixearwiggles.gif (2MB, 540x304px) Image search: [Google]
felixearwiggles.gif
2MB, 540x304px
>>58788382

Here, have a different cute grill.

>>58788186

It's not dead; it's just that nobody uses it.
>>
http://www.tiobe.com/tiobe-index/go/
What the fuck happened here
>>
>>58787172
Not having schizophrenia
>>
>>58787474
the elephant ears are meant to represent the balls
>>
>>58787146
https://a.pomf.cat/kqoxkv.ogg
How do I fuck up less, /dpt/?
>>
>>58788429
what can you do in Java? Why not use Python then?
>>
File: 3ff36834d035bd4c7041bcbb810006a8.png (577KB, 929x1000px) Image search: [Google]
3ff36834d035bd4c7041bcbb810006a8.png
577KB, 929x1000px
>>58788382
it is a cute grill (male)
don't let something like a penis get in the way
>>
I finished making tetris in JavaFx it was pretty fun and challenging
>>
>>58787146
who gives a shit about you shills and your programming languages. the language doesn't matter, what matters is that you're using the language to study reality.
get the fuck off this japanese anime board and start exploring reality.
>>
>>58789169
Reality has very little to do with programming.
All you're doing when programming is using some bullshit rules to get some bullshit result at the end.
>>
>>58788063
'l' is uninitialised on the first iteration of the loop.
>>
>>58789382
>math isn't real
okay
>>
Started collecting metadata from sourcecode files using pyparsing

I don't ever want to go back to LR parsers ever again
>>
>>58789382
>some bullshit rules
you mean stuff based on reality?
>some bullshit result
you mean stuff based on reality?
>>
>>58788594
>Popular search engines such as Google, Bing, Yahoo!, Wikipedia, Amazon, YouTube and Baidu are used to calculate the ratings.

TIOBE ratings are very dubious.
>>
>>58788429
>implying java is better
>>
>>58789449
>not using the parser monad
>>
i've took a bunch of programming classes at my community college but they only ever teach me to write terminal programs that average grades and sort arrays and shit. how do i learn how to put graphics on it and apply this to actually making useful stuff like android apps or windows applications with graphics and buttons and shit?
>>
File: 1470313936267.png (101KB, 1513x1028px) Image search: [Google]
1470313936267.png
101KB, 1513x1028px
>>58787172
I am also writing an operating system.
>>
>>58789473

They are worse than dubious. They are clearly a horrid meme that are obviously broken every time they get posted.

Yet for some fucking reason, people all over the Internet bring them up in every discussion as if they are an authoritative source.
>>
>>58789612
>sepples
i can already see that it's trash
>>
>>58789629
And I can already see that your programming skills are trash.
>>
>>58789637
they are by definition better than your """"""""""skills"""""""""" so i'm okay with that.
>>
>>58789629
>>58789645
C++ is bad but so are you
>>
File: Screenshot_2017-02-01-16-58-53.png (102KB, 1080x1920px) Image search: [Google]
Screenshot_2017-02-01-16-58-53.png
102KB, 1080x1920px
What the holy fuck is the point of a concreteDecorator in the Decorator Pattern?
>>
>>58789612
I liked geany too but it doesn't remember the file name for some reason
>>
I have a document littered with shit like "\n\n\n", "\n\t\n\n\n\n\n\n" etc that I want to get rid of.

But also some relevant text that happens to have a "\n" stuck on at the end.

Is there a regex expression that can find only linebreaks/tabs of an arbitrary length, but ignore linebreaks attached to something else?
>>
>>58789936
stop using a language shit language.
>>
File: OOP.png (69KB, 1210x467px) Image search: [Google]
OOP.png
69KB, 1210x467px
>>58789905
>falling for the OOPs meme
>>
>>58789905
>the current year
>oop design patterns meme
Why so slow, no one gives a shit about the patterns for a decade now.
>>
>>58787307
I thought we scared him off years ago.
>>
>>58789993
Because I want to get better at designing code?
>>
>>58790029
"""Design patterns""" are a terrible way to design programs.
>>
>>58790037
Care to point me in the correct way then?
>>
>>58790042
Common sense and good taste.
>>
>>58789977
HTML is indeed shit
but what can you do
>>
>>58789936
Post the document and post the desired output.
>>
>>58790029
The purpose of design patterns is to shoehorn inheritance and other OOP concepts where they don't belong.
>>
I was finishing some code some guy asked for help with yesterday.

Both of us were too tired to figure out why it was still fucked when I left him.

This is said code:
>>58790117
>>
>>58790170
What on earth is that supposed to be doing?
>>
>>58790197
Beats the hell out of me.

He needed it to read an unspecified array of length 4096, using a ranged array of length 1024, and redundantly read it, while incrementing by 128 for some reason, and anything that is out of bounds, pad as a 0.

IDK, I just solved it. Not the slightest clue what it's for.
>>
>>58789936
s/^[\n\t]*//g

This?
>>
If I want to replace a substring from a string with another substring, but don't know what the letters are, can I just use

stringName.Replace(stringName[i].ToString + stringName[i+1].ToString, "st");


Not sure if the syntax is correct, but basically I want to replace two characters of a string, defined by the counter, with two different ones.
Is the syntax correct for C#?
>>
Let's say you have a cuda kernel that operates on a pixel basis:

__global__
void clear_screen()
{
int x = blockIdx.x * blockDim.x + threadIdx.x;
int y = blockIdx.y * blockDim.y + threadIdx.y;

float4 gcol = make_float4(1.0f);
surf2Dwrite(gcol, surRef, x * sizeof(float4), y);
}


Is it really better to have a single thread handle one pixel, or should I see a benefit if I wrote a loop and each thread executed the same loop, and cleared x pixels?

What if there was divergence? Could this avoid stalling?

Or is the "goal" about having as few loops as possible and let the scheduler do its job?
>>
what was the first big project you worked on?

how'd it go?
>>
Chapel or D as c++ alternative?
>>
>>58790503
Define 'big'
>>
>>58790486
It's better to work on a group of pixels, say for example a macroblock. You usually work on images that have more pixels than you have available GPU threads/cores. The goal should be to utilize as many of those cores simultaneously.

However, you must also keep in mind that a single thread is slow. A lot slower than your average CPU thread, and it will have a hard time doing even the simplest things. Therefore you must not swamp it with work to do.
>>
>>58790556
20cm
>>
>>58790553
Rust.
>>
>>58790565
Like, a tile of 4 by 4 or 8 by 8?
>>
File: bane-post.jpg (54KB, 500x500px) Image search: [Google]
bane-post.jpg
54KB, 500x500px
>>58790556
>>58790569
For you
>>
>>58790486
Do your Haskel and Arch, pajeet.
>>
>>58790579
Yes.
>>
>>58790486
>float4 gcol = make_float4(1.0f);
Oh, I forgot. CUDA 8 does SIMD now. Coolio

>>58790579
Yes, especially when you can work with vectors.
>>
>>58790578
Rust is dead.
>>
>>58790596
How is Rust dead?
Compare it to an actually dead language, like D.
>>
>>58790602
Rust is deader than Perl.
>>
>>58790602
Both languages are dead. It's only used within the community.
>>
>>58790602
You're really lowering the bar if you have to compare Rust to D in order to "prove" that it isn't dead,.
>>
>>58790611
>it's only used by people who use it
wat
>>
>>58790611
>use language
>be part of the community
I don't get it? You're literally saying that the only people who use it are the people who use it.
>>
>>58790615
He's the one who made the statement, so it's on him to prove it's dead.
I just wanted to shit-talk D, to bait the 2 or so D autists on here.

>>58790611
That makes no fucking sense.
>>
>>58790553
Both try to be better C++ but D can't decide if it wants to have GC or not and pisses everybody by being indecisive.
Chapel has manual memory management and the support for parallelism seems really nice.
>>
>>58790616
>>58790623
>>58790627
Rust only lives in its subreddit.
D only lives in its forum.
>>
>>58790653
Rust lives on the face of every child, on the smile of every baby.
>>
done with K&R
can someone give me ideas for small programs to practice a c pls :3
>>
>>58790653
I see rust discussed here quite often.
I even see mentions of it on the very few news sites I visit.
>>
Which C library to use for basic allocators and containers?
There's so many like: tbox, qlibc, glib, klib, apr.
>>
>>58790668
Sudoku solver.

>>58790672
Roll your own.
>>
>>58790676
>Roll your own.
But the wheel...
>>
>>58790672
glibc for your desktop applications

ulibc for your embedded stuff

thats all
>>
>>58790556
however you choose to define it

please just answer thanks senpal
>>
>>58790672
Use C++ if you want actually fast and memory efficient containers, any pure-C container library is inherently pointer-based and thus inefficient.
>>
>>58790682
What about bionic, pajeet?
>>
>>58790694
>bu.. bu.. BUT C IS INEFFICIENT
fuck off sepples faggot.
>>
>>58790679
Get over it.
If you can't even implement your own data structures, how can you even call yourself a programmer?

>>58790687
The first program I wrote for myself which was actually useful was a thing which read some RSS feeds for anime episodes, and then downloaded them off of XDCC bots on IRC channels.
I didn't use any libraries for the RSS or IRC. I implemented them (shoddily) myself, for a learning experience.
>>
>>58790667
Is Rust skin cancer?
>>58790669
"Rust is a systems programming language that runs blazingly fast, prevents segfaults, and guarantees thread safety." sounds very catchy. Too bad it only works on paper.
>>
>>58790694
Are you seriously implying that whatever meme Sepples shit you're using isn't using pointers?
>>
>>58790705
>Is Rust skin cancer?
This makes me worry about what you have on your face.
>>
>>58790708
Of course it does, but not as much as pure C, since C++ has templates and thus is able to store values in-place instead of pointers.
>>
>>58790701
Neato senpai.

What are you most proud of?
>>
>>58790705
> Too bad it only works on paper
[citation needed]
>>
>>58790723
God damn, sepplesfags really are a special brand of retarded.
>>
>>58790731
Looking back at the code, it's not great. I've gotten a lot better since then.
It was nice being able to have the program while it was still useful to me.
>>
>>58789478
>implying it's not
>>
rust is a lost cause

really they should've just made an updated Ocaml with reference counting GC and a proper concurrency model
>>
File: 1485135642832.jpg (246KB, 400x800px) Image search: [Google]
1485135642832.jpg
246KB, 400x800px
>>58790694
>>58790723
>>
>>58790737
Just look at a typical pure C container library: https://developer.gnome.org/glib/2.50/glib-Doubly-Linked-Lists.html#g-list-append , it operates on pointers instead of data itself, so if you have a structure you can't store it directly in a DLL, you have to allocate memory for it and store pointer to it in a DLL node. Meanwhile templates allow you to write DLL (std::list) which stores that structure directly, meaning less allocations and less indirect data access.

I mean, of course you can do the same shit in pure C by manually adding LL header to every struct you want to use in a LL, but then you have to re-implement container library by yourself. Linux kernel does this and it's just ugly.
>>
>>58790735
>blazingly fast
runtime bounds checking
slow hasmap implementation
>prevents segfaults
unsafe keyword
>guarantees thread safety
unsafe keyword

Also:
slow compile times
poor library support
borrow checker could reject valid code
>>
File: vomit.jpg (90KB, 650x650px) Image search: [Google]
vomit.jpg
90KB, 650x650px
>>58790776
Please, anon.
Don't use glib as an example of anything.
>>
>>58790790
are you saying glib is glib?
>>
>>58790790
Are you by any chance a vegan?
>>
>>58790790
>the most used pure C container library isn't a good example of pure C container library
Whatever you say, bud, here are containers from other libs:
https://github.com/tboox/tbox/blob/master/src/tbox/container/list.h#L125
http://wolkykim.github.io/qlibc/doc/html/qlist_8c.html#a362b854c881d11e4ff063bf2415e1202
https://apr.apache.org/docs/apr/1.5/group__apr__hash.html#ga456beb139bc548728b49c09c2f89b93c
What a surprise, they all use pointers, so you waste an allocation for every node and have to do one more pointer dereferencing to access the data.
>>
>>58790870
>you waste an allocation for every node and have to do one more pointer dereferencing to access the data.
Jesus Christ how horrifying.

There are also macro based solutions that do not have that problem like klib, sglib and probably more.
>>
>>58790785
>runtime bounds checking
These are mostly optimized out, and can be turned off completely in unsafe code.
>slow hasmap implementation
The hashmap is fine, the problem was the default hashing algorithm being suboptimal on small data, and they fixed it.
>unsafe keyword
It's fine as long as you don't use it. And you really don't need to unless you're writing some ffi stuff.
>slow compile times
It sucks, but they're working on it: https://internals.rust-lang.org/t/incremental-compilation-beta/4721 .
>poor library support
It's getting there.
>borrow checker could reject valid code
It's not valid if BC rejects it :3 But yeah, they're working on non-lexical BC.
>>
Will the compiler let me have racist names for everything? I want every function to be a racial slur, like nigger kike etc.
>>
>>58790972
You'll run out of slurs
>>
>>58790885
> Jesus Christ how horrifying.
It's actually quite serious, since excessive allocation takes time and leads to heap fragmentation, while indirect data access kills cache locality. But hey, if you don't care about memory usage and performance why don't you just use Python.

> There are also macro based solutions that do not have that problem like klib, sglib and probably more.
Well yeah, in pure C you have to resort to an unmaintainable mess of macros to achieve something close to performance of a straightforward C++ code.
>>
>>58790870
They have to use pointers, because they're trying to be overly generic.
If you implement that shit yourself, you can get away from it.

Here is a quick generic linked list implementation I threw together.
It's actually capable of handling multiple types of data at the same time, but I don't know if you're going to consider that a feature.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct ll {
struct ll *next;
unsigned char data[];
};

void _ll_add(struct ll *restrict *head, const void *restrict data, size_t data_len)
{
// You would probably do something more fancy than an O(n) traversal of the list,
// but I'm doing this for simplicity's sake.
while (*head)
head = &(*head)->next;

*head = malloc(sizeof **head + data_len);
if (!*head)
exit(1);

(*head)->next = NULL;
memcpy((*head)->data, data, data_len);
}

#define ll_add(head, type, data) _ll_add(head, &(type){ data }, sizeof(data))

void *ll_get(struct ll *head, size_t index)
{
for (int i = 0; i < index; ++i)
head = head->next;

return head->data;
}

void ll_free(struct ll *head)
{
while (head) {
struct ll *tmp = head->next;
free(head);
head = tmp;
}
}

#define ll_for_each(head, val) for (struct ll *_iter = (head); \
_iter && ((val) = (void *)_iter->data, 1); \
_iter = _iter->next)

int main()
{
struct ll *head = NULL;

ll_add(&head, int, 10);
ll_add(&head, int, 20);
ll_add(&head, int, 5);
ll_add(&head, int, 50);

int *val;
ll_for_each(head, val) {
printf("%d\n", *val);
}

ll_free(head);
head = NULL;

ll_add(&head, char[], "hello");
ll_add(&head, char[], "from");
ll_add(&head, char[], "inside");
ll_add(&head, char[], "the");
ll_add(&head, char[], "list");

char *str;
ll_for_each(head, str) {
printf("%s ", str);
}
putchar('\n');

ll_free(head);
}
>>
>>58787146
Is that Harambe?
>>
>>58790940
>they're mostly optimized out
>it's fine as long as you don't use it
>it sucks, but they're working on it
>it's getting there
>they're working on non-lexical BC
Sound like a great language.
>>
>>58791066
It's its mother
>>
Can I become a hacker without using python?
>>
>>58790997
>Well yeah, in idiomatic C++ you have to rely on a slow, unmaintainable mess of a compiler to achieve something close to the performance of straightforward C macros.

It's all about perspective m8.
>>
>>58791141
Yeah, but you have to use ruby.
>>
File: absolutely_harambe.jpg (162KB, 480x496px) Image search: [Google]
absolutely_harambe.jpg
162KB, 480x496px
>>58791066
>>
>>58791165
Hah, now she has a baby.
>>
>>58790997
Is my implementation in >>58791021 an "unmaintainable mess of macros"?
Does it not meet your locality requirements?
>>
Hey anons, could use your help with some VBS programing. I have the following code, and I want to understand everything about it.

CreateObject("Scripting.FileSystemOnject")

From what I understand, this is creating a new instance of FileSystemObject from the Scrrun.dll. if I understand this correctly, I can start interacting with any .dll files by creating an object based on them. But what I don't understand is why I need to input "Scripting.FileSystemObject". Where does this line of code come from? Is it in the .dll? Is there somewhere where I can find out what I need to put in the CreateObject? For example, of I wanted to create an instance of the Calculator, what would I put in create object, and where can I find what to put it?
>>
>>58791173
No, it's actually quite good, I wonder why the other libraries stuck with pointers. Then again, it relies on type erasure and thus type unsafe.
>>
>>58791163
Really though?
>>
>>58791191
Read the documentation.
>>
>>58791215
>Then again, it relies on type erasure and thus type unsafe.
Yes, I know, but as is any implementation that uses void pointers.
To the users, you would just say "do the right thing" or "adding a type different from the first type added to the list is undefined behaviour".
The only way to fix it would require some kind of storage of a "type id". However, C has no defined/robust way of doing this for any possible type.
>>
>>58791220
Thanks for the input! Where can I find the documentation? Do I need to open the .dll file or something?
>>
Today I decided to get started into Java and tried to do some excercices but for some reason I'm getting an error with this one and no idea what's wrong. http://pastebin.com/ggfTZM0k

All I get is
La raíz de 9.0 es Exception in thread "main" java.util.UnknownFormatConversionException: Conversion = '1'
at java.util.Formatter.checkText(Unknown Source)
at java.util.Formatter.parse(Unknown Source)
at java.util.Formatter.format(Unknown Source)
at java.io.PrintStream.format(Unknown Source)
at java.io.PrintStream.printf(Unknown Source)
at entrada_numeros.main(entrada_numeros.java:8)
>>
After reading some "DYNAMIC ARRAYS ARE ALWAYS BETTER THAN LINKED LISTS" propaganda, I converted some file parsing code to use dynamic 1D arrays instead of linked lists. It took about 30 minutes. Differences in execution times were in sub-milliseconds, so arrays were not faster after all.

After running the whole test array:
- number of allocations: 785057 (arrays), 692585 (linked lists)
- total bytes of memory used: 178311778 (arrays), 23022590 (linked lists)
- no errors or memory leaks

Numbers reported by Valgrind. The high memory usage by the array version genuinely surprised me. I started to wonder if Valgrind misreports realloc() calls, but I doubt it's that. Valgrind has existed for years and such problems would have been fixed by now.

In terms of code amount, linked lists need 85 lines of code and dynamic arrays 108.

Conclusion: I'm going back to linked lists, at least in this case. Less allocations, less memory used. Dynamic arrays are fine if you know beforehand how much stuff you're going to need, otherwise consider using linked lists.
>>
>>58791288
BUILD WALL
>>
>>58791296
What factor did you use to grow the arrays? It looks like you realloc for every insertion.
>>
>>58791296
Nice code.
>>
>>58791296
Depends on how you implemented your dynamic arrays obviously.
>>
>>58791296
I'm going to assume that your dynamic array implementation was very shitty.
>>
Why does this:
float inverse(float a){ return 1.0f / a; }


Gets compiled to this:
0000000000000000 <inverse>:
0: c5 f2 53 c8 vrcpss %xmm0,%xmm1,%xmm1
4: c5 f2 59 c0 vmulss %xmm0,%xmm1,%xmm0
8: c5 f2 59 c0 vmulss %xmm0,%xmm1,%xmm0
c: c5 f2 58 c9 vaddss %xmm1,%xmm1,%xmm1
10: c5 f2 5c c0 vsubss %xmm0,%xmm1,%xmm0
14: c3 retq

?

You'd think it'd just need to vrcpss once and maybe move the value back to xmm0 (I don't know if it allows destination to be the same as source), so at most 3 instructions with the retq.

So, the question is, what the fuck is up with the add/sub/mul shenanigans?
>>
>>58791342
What compiler are you using?
GCC 6.3.1 with -O3 is just giving me
inverse:
movss .LC0(%rip), %xmm1
divss %xmm0, %xmm1
movaps %xmm1, %xmm0
ret

.LC0:
.long 1065353216
>>
>>58791374
Use I use -Ofast -march=native -mrecip -mtune=native -ffinite-math-only -funsafe-math-optimizations -fno-math-errno -ffast-math

-mrecip is required to generate the rcp instruction.
>>
>>58791390
Okay, not I'm getting the same result.
Compiler optimisations are weird. It probably gives you better results somehow, but fuck if I know why. I don't know the specifics of how long each instruction might take,
>>
What does /g/ think of hackathons? Will any of you be attending one this weekend?
>>
>>58791288
System.out.printf("%1.2", Math.sqrt(num2));
This isnt a valid format as far as I can tell. Are you trying to set the amount of decimals?
Im not that familiar with printf() (because Im new to Java aswell), but if its formating the decimals you want, you could try this class : DecimalFormat (https://docs.oracle.com/javase/7/docs/api/java/text/DecimalFormat.html)

DecimalFormat myFormat = new DecimalFormat("0.000"); for example
>>
File: Screenshot_2017-02-04_15-49-52.png (69KB, 581x693px) Image search: [Google]
Screenshot_2017-02-04_15-49-52.png
69KB, 581x693px
Macros are love.
>>
File: 93tbq90cqupx.png (609KB, 703x1000px) Image search: [Google]
93tbq90cqupx.png
609KB, 703x1000px
are there any cute and cozy IDE's to learn c++ on windows?
>>
>>58791487
notepad
>>
>>58791487
Visual Studio
>>
>>58791487
Install Gentoo
>>
>>58791487
Ganoo/loonix + veem
>>
>>58791427
actually new DecimalFormat("0.###") is better IMO, that way you wont get results such as 3.000, but rather just 3
>>
>>58791409
I just checked in a debugger, and what it does is compute a more accurate result. With an input of "4", the value computed by vrcpss is off by 0.00006104, after the two muls, the result is off by .000122055, but after the final add/sub, it's off only by .000000015, which is still of as 0.25 is exactly defined in IEEE754.

I don't know why it's doing that, even though I specified every fucking math flags I could think of. I don't care being off by less than a 1000th.
>>
>>58791427
Just found out what's the problem. It missed an 'f'
System.out.printf("%1.2f", Math.sqrt(num2));
I'm an absolute retard
>>
>>58791553
>I'm an absolute retard
Yes, I agree.
>>
>>58791296
post your realloc
>>
>>58791553
thanks, I think I just understood printf() too.
>>
>>58787295
have you seen him explain pre-emptive vs cooperative tasking? They're not hard concepts really but he wrote both into the OS and went with cooperative tasking so "it would be different than linux"
>>
when contributing to libgdx you need to sign a Contributor License Agreement. generally speaking is this overkill or necessary?

https://github.com/libgdx/libgdx/blob/master/CLA.txt
>>
>>58791728
https://www.change.org/p/mr-wesley-wolfe-stop-the-dmca-takedown-of-the-bukkit-and-spigot-minecraft-server-platforms
>>
is there any point in learning assembly in 2017?
>>
>>58791779
I dont see any ruling on this case. just some sperg dcma'ing.
>>
>>58791487
Visual Studio is equal parts cute and cozy.
>>
>>58791809
The codebase contains contributions of Wesley. I don't know why, but he wants to pull his contributions from the codebase. That's legal because he's still the owner of the contributions. Thus the codebase broke and all hell broke loose.
That couldn't happen if he signed a CLA. A CLA transfers the copyright of the contributions from you to the project.
>>
>>58791881
but is there a court case with a ruling in his favour? there must be some precedence
>>
Why does
$stmt = $db->prepare('INSERT INTO Account VALUES ("312", "asd", UTC_TIMESTAMP(), "lkj"');
if(!$stmt)
return $db->error;


When the query works just fine when executing directly in MySQL?

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
>>
>>58791934
Wrong thread, bud: >>58785763
>>
>>58791926
He sent a DMCA takedown notice. I don't know if that requires any legal actions.
>>
>>58792009
technically you can dmca everything. but if the affected party challenges it then you have to show that you are in the right, I guess. so Im interested if he can go through with it.
>>
>>58791934
Oh fug, I had forgotten a ) at the end.
>>
>>58792023
I guess both parties didn't go to court because of financial reasons. Bukkit is a community project, so there's little to no money involved. I don't know of any actual court cases, but those involving copyright are indeed interesting.
Anyway, he threw a tantrum with the DMCA and succeeded: Bukkit and its community died and got replaced by Spigot.
>>
What's a good site to find programming jobs on?
>>
Any good books to get into asm?
>>
>>58790988
And yet we'll never run out of kikes :(
>>
>>58792125
google --> programming jobs
>>
>>58792199
It's all Java, memelangs, or webshit
>>
>>58792208
Nobody wants to hire you if you talk like that.
>>
>>58792208
>waah why can't i get a job with haskell its so unfair :((
>>
>>58792228
I only talk like that on here, obviously.

I just want a job where I won't have to use a shitlang.
>>
>>58792208
java and webshit are the only things that make money
>>
>>58792240
What is not a shitlang.
>>
>>58792240
>I won't have to use a shitlang
How about you list everything you consider to be shit, and we can go from there.
>>
>>58792426
>c
>c++
>java
>python
>c#
>>
>>58792441
>c
>shitlang
really now? everything else is true though.
>>
>>58792441
Looks like you're going to learn Javascript if you want a job, then.
>>
>>58792458
C is like metallica

One of the few options in its day, but other people are doing the same gig much better now.
>>
>>58792476
>other people
care to name a few?
>>
>>58787374

Browsers will block your popup that comes up when you press H

also it's boring
>>
>>58792476
C is and always will be used. It's simple, portable, and fast.

There's newer shit, safer shit, and more expressive shit, but C will never go away.
>>
File: 1478652948096.gif (565KB, 246x205px) Image search: [Google]
1478652948096.gif
565KB, 246x205px
>>58787146
>tfw trying to learn android app development and all the official android studio tutorials are out of date

GOOGLE STOP DROPPING THE FUCKING BALL
>>
>>58791461
What language is this? Scala?
>>
>>58792731
They never update them, they just make new ones for the new features.

It's all very "muh sekrit club" and "fuck you for not starting sooner".
>>
File: VID_20170204_171056122.webm (952KB, 1920x1080px) Image search: [Google]
VID_20170204_171056122.webm
952KB, 1920x1080px
>>58787146
>What are you working on, /g/?
still going strong with my attiny13.
>>
>>58792755
>the_current_year
>he can't recognize Rust
>>
>>58792796
That's exactly what it feels like. Lazy as shit too because there's a stack overflow answer for almost every tutorial saying, "Yeah just ignore the official tutorials and do this"
>>
>>58792807
What is this, fag-o-meter?
>>
>>58792755
Rust. I wrote a small syntax highlighting library to link through C and ams.js/WASM in the browser. Have not tested it out yet.
>>
File: mona_test_lines.png (743KB, 396x600px) Image search: [Google]
mona_test_lines.png
743KB, 396x600px
My generation program now uses lines (Thank you, based Bresenham) instead of triangles, and the results are pretty good.
>>
>>58792828
Yes, a light barrier.
Atm not sure if I will make it with IR or laser shits.
>>
>>58792731
Android has to be the only fucking language libraries where the API is out of date
>>
>>58792731
everything about developing for android is cancer, it's one of the reasons why I refuse to buy an android phone
>>
>>58792893
What does that even mean? Out of date compared to what?
>>
>>58792814
>>58792836
Thanks, just wanted to know so I could avoid it in the future
>>
>>58792731
android is the worst but this is a huge problem for all mobile and even web development.

its ironic really, you'd think that the most recent additions to our field (app dev) would have the best practices of documentation, etc. but it's the opposite. The older code is concrete and thorough and the newer shit is broken

>>58792912
Not him but they make changes to the API (changing methods, deprecating shit, etc.) and they don't update their documentation online. So if you looks up the api and tutorials they wrote on how to use their libraries and it's all wrong. You'll get errors and then go on a goose chase until you find that one stackoverflow post telling you that the documentation/guide is wrong and to not do what they say
>>
>>58792913
>needing to know which languages to avoid
>not just avoiding everything that isn't Assembly or Python
Either get to the bare metal or abstract the fuck out of it. Any language in between is useless
>>
@58792950
>Python
>abstract the fuck out of it
what did he mean by this?
>>
I just installed Visual studio and I got a bunch of botnet processes running in the background plus 10GB of shit no one cares, my pc is so dirty that I need to to roll back to a previous state.
>>
>>58792989
>@
what did he mean by this
>>
File: 1481216521442.jpg (10KB, 250x238px) Image search: [Google]
1481216521442.jpg
10KB, 250x238px
>>58792912
>>58792912
>What does that even mean? Out of date compared to what?

>want to do A
>lookup how to do A
>guide says to do B, C, and D
>you do that
>errors out the ass
>search online for errors
>turns you need to use B.2
>C doesn't work and it needs E and F
>also D isn't supported below 3.0
>still errors
>turns out B is compatible with E and F but B.2 isn't
>three weeks later you find out how to do A
>it doesn't work for anything above 4.0

I only do android when I'm intoxicated
>>
>>58791296
>Less allocations, less memory used. Dynamic arrays are fine if you know beforehand how much stuff you're going to need, otherwise consider using linked lists.
No.
Linked lists always use more memory. You fucked up your implementation.
>>
@58793004
>being this new
>being this shit at programming
what did he mean by this?
>>
I'm working on a implementation of a Bimary Decision Tree in C as a coursework.
I was supposed to do it with 3 other people but they're fucking slackers, so I did every single line of code.
And now i'm having SEGFAULT out the ass, jesus.
>>
>>58791296
Literally how could a linked list every use less memory than an array? For a single linked list it should ALWAYS be the size of a struct pointer times the number of items in the list larger than the equivalent array. Thats even more for a doubly linked list.

A linked list literally holds more data. Period.
>>
>>58793056
You should have learned C first
>>
>>58790776
That's a terrible implementation.
Use an intrusive list like the Linux kernel list, that will get you even better perf than std::list.
>>
>>58791296
>probably I/O bound task
>"dynamic 1D array" that uses way more memory and allocations because you're a retard
>no code
>>
>>58792989
ummm, who are you replying too ??
>>
Is there some kind of emacs equivalent of vimtutor?
>>
>>58793103
to the retard who thinks plebthon can somehow be described as "abstract the fuck out of it"
>>
>>58793056
use gdb for debuggin C SEGFAULTS
>>
>>58793071
> Use an intrusive list like the Linux kernel list, that will get you even better perf than std::list.
1) Not it won't, it will be exactly the same.
2) Your data will have to have LL headers even if you don't store it in a LL, so you're gonna waste memory.
3) What if you want so store some instances of a struct in LL and others - in a hash map. Does that mean you have to have a LL header AND a HM header in every instance of the struct?

Overall, containers story in pure C is a sad one comparing to C++.
>>

import java.util.Scanner;

public class LeapYear {

public static void main(String[] args) {
Scanner reader = new Scanner(System.in);
System.out.println("Type a year:");

int year = reader.nextInt();

if ((year%4==0) && (year%100 == 0 && year%400 == 0)){
System.out.println("The year is a leapyear.");
}else{
System.out.println("The year is not a leap year.");
}

}
}

Anything I should make better in this code?
>>
>>58793133
Needs more gotos
>>
Got a new job where Go will be my main language of use so I'm looking up some tutorials etc. to try get up to speed in some sense.
>>
File: ss1.png (200KB, 1380x718px) Image search: [Google]
ss1.png
200KB, 1380x718px
>>58793115
Just use spacemacs, it's basically emacs with vi keybingins and tons of enhancement bound together in a coherent way.
>>
>>58793133
Stop using Java.
>>
>>58793156
Please don't use spacemacs, it doesn't have a code of conduct.
>>
https://github.com/syl20bnr/spacemacs/pull/3484
>>
File: 1459999999999.png (367KB, 470x415px) Image search: [Google]
1459999999999.png
367KB, 470x415px
gonna (slowly) mimic the XP image viewer for simplistic / nostalgic / educational reasons (and play gifs)
>>
>>58793133
#include <stdio.h>

int main() {
int year;
scanf("%i", &year);
if(year % 4 == 0)
printf("%i is a leap year.", year);
else
printf("%i is not a leap year.", year);

return 0;
}
>>
>>58793133
just use the built-in function for it, nerd
>>
>>58793234
>
if(year % 4 == 0)
printf("%i is a leap year.", year);

but that's wrong
>>
>>58793311
year % 4 == 0 && year % 100 != 0 || year % 400 == 0
>>
>>58790653
>2017
>not using Holy C
HEATHENS
>>
>>58793132
1. Yes it will, much better control over data layout and allocation, can put data before and after node pointers depending on what needs to be in which cache line.

2. You obviously don't make any struct not needing to be in a list have the list header. And you save memory if things need to be in multiple lists.

3. Not all containers are best done intrusively. Hashing is rarely useful for things other than integers/pointers, so you don't even need a generic one in the first place.
That being said, an intrusive list allows for better persistence of node pointers so you can get a hash key for free.
>>
>>58793133
Is this a joke? Your logic's completely wrong.
>>
>>58787374
>www.symmetr.io
thumbs down desu
>>
File: 4640558.jpg (185KB, 596x1055px) Image search: [Google]
4640558.jpg
185KB, 596x1055px
>>58793230
>>
>>58793378
All of this is possible with templates without actually being intrusive.
>>
>>58793407
Nope.
>>
>>58793234
Your is more correct, but doesn't take into account that if year%100 and !(year%400), it's not a leap year.
https://www.wwu.edu/skywise/leapyear.html
>>
>>58793322
>http://www.templeos.org/Wb/Doc/HolyC.html
>no F32 float.
What did he mean by this?
>>
>>58793411
Yep. Maybe not with std::list but in general, yes.
>>
>>58793173
Intelligent people don't really care about this, right?
>>
>>58793428
No, it's bait.
>>
>>58788166
just look at the fucking source code then.
>>
>>58793415
A float is made by the CIA niggers to spy on us
>>
How much Elixir have you written today, /dpt/?
>>
this is the correct way, brainlets.

#include <stdio.h>
#include <stdlib.h>

int main (int argc, char *argv[]) {
int i = atoi(argv[1]);
puts(((!(i%4)&&(i%100))||!(i%400))?"yes":"no");
return 0;
}
>>
>>58793416
Control over exact layout and reusing nodes in multiple lists require intrusiveness.
Persistent nodes either needs a special allocator or intrusiveness (you probably want both actually, especially if combined with being in multiple lists).

C++ has the potential abstraction facilities to be better, but they unfortunately dropped the ball with the standard library, especially the std::allocator monstrosity, but even just the basic containers are neutered because of retarded requirements in the spec leading to suboptimal implementation (std::map being the prime example)
>>
>>58793378
1. That's literally useless and no one does that, just looks at the kernel code.

2. You missed my point: if you have to put only some values of a struct in a LL, not every value of that struct. With intrusive headers you still have to have LL header in every struct instance, thus wasting memory.

3.
>Hashing is rarely useful for things other than integers/pointers, so you don't even need a generic one in the first place.
This is just bullshit. How do you map from a string to a value in pure C then? Do you compute hash from a pointer to a string or what?
>an intrusive list allows for better persistence of node pointers so you can get a hash key for free
wat
>>
>>58793458
Why would I use Elixer over Go?
>>
>>58793509
Because OTP has 20 years of success in the real world.
>>
>>58793546
Elixer does not.
>>
>>58793568
Elixir uses directly OTP and runs on the same VM.
>>
>>58793502
1. You might wanna look more carefully at the structs in the kernel. Especially the ones which are shared in multiple threads, they make sure certain fields are on certain cache lines to avoid false sharing.

2. I got your point - and I'm saying don't put the header in those structs. You can easily make seperate structs, that's the beauty of the intrusive container, code which doesn't care about the fact that the struct isn't in a list will never even try to use those fields anyway.

3. A string is represented with a pointer, just need another hash function.
>>
>>58793581
Does that mean I can use Erlang in Elixer?
>>
>>58791963
SQL is /dpt/.
>>
>>58793387
What's a joke about it?
The site asked me to write it with these conditions:
A year is a leap year if it is divisible by 4. But if the year is divisible by 100, it is a leap year only when it is also divisible by 400.

So.
2012%4 = 0?
A leapyear.
And the other condition is
1200%100 =0?
1200%400 =0?

So (year%4 equals zero) AND (year%100=0 AND year%400=0)
is wrong?
>>
>>58793593
Yes. The interop is pretty good.
>>
>>58793614
I might give it a shot one day. Go sucks, but gets the job done. I don't know about Elixer.
I'm liking Racket too much, so I don't have time to learn Elixer.
>>
>>58793606
Yes, it's wrong. Have you tested your code with several cases?

>>58793319 is the correct logic.
>>
>>58793640
It's super fun. You won't be disappointed.
>>
>>58793606
You don't understand how && works? a&&b is only true if a and b are true.

You're saying that
leapyear = (year%4==0) && (year%100 == 0 && year%400 == 0).

So it's only a leap-year if it's divisible by 4, AND divisible by 100 and 400. In other words, it's only a leap-year if it's divisible by 400. Very wrong.
You need to do something more like
leapyear =  (!(year%100) ? !(year%400) : !(year%4))
>>
File: mqdefault.jpg (7KB, 320x180px) Image search: [Google]
mqdefault.jpg
7KB, 320x180px
>>58787176
lrn2search the catalog, you fag
>>
File: autism.gif (698KB, 200x113px) Image search: [Google]
autism.gif
698KB, 200x113px
>>58787176
>>
File: Nim.png (228KB, 750x750px) Image search: [Google]
Nim.png
228KB, 750x750px
Is Nim worth learning, /g/?
>>
>>58793774
>garbage collected
>>
New thread:
>>58793783
>>58793783
>>58793783
>>
>>58787159
Who the hell is this guy?
>>
>>58793796
He's to our time what Saint John the Baptist was to Our Lord Jesus Christ's time.
>>
>>58793597
That anon's issue is a specific interaction with how PHP works with MySQL
>>
>>58790751
Thats really not the point of rust but if you want to make ocaml with threads then be my guest
>>
>>58791101
Rust will be "it will be good in 5 years!!" for longer than 5 years
Thread posts: 316
Thread images: 31


[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.