[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: 320
Thread images: 22

What are you working on, /g/?

Old thread: >>62258573
>>
>>62266919
God I love anime
>>
>>62266919
How would you implement a real-time software audio mixer without locking, given that you can afford to load whole uncompressed PCM files (yup, all 3-5MB right into RAM).
The interface is, of course, a callback from another thread, this is the way it works in PortAudio, SDL2 and libsoundio (which I'm using), where you have to fill the buffer.
The solution I've seen is a circular buffer, but it works bad when you want to loop a song, also this approach was designed with music streaming in mind. I'm looking for a simpler solution.
This is what I've come up so far:
typedef struct DgAudioTrack {
DgAudio *audio;
bool looping;
size_t index;
} DgAudioTrack;
struct DgAudio {
size_t bufferSize;
uint8_t *buffer;
};


The API is quite simple too:
1. Play sound.
2. Loop sound.
3. Stop sound (must be atomic operation).

Now the hardest thing is the callback: how to make it not to segfault in various circumstances that can could happen.

So I came up with this solution:
for each frame
for each track
retrieve audio pointer // must be atomic
// now at this moment either playSound or stopSound
// or loopSound could have been called, so *everything else*
// in DgAudioTrack may be utterly incorrect except
// the audio pointer
add audio frame // this must be always safe
// no matter what track.index and track.looping is
// it might be glitchy for 1/22050 of a second (playing
// invalid frame because track.index or track.looping has
// been corrupted immediately after the atomic audio
// pointer retrieval, however unlikely that might be), but it's
// ok


And playAudio and loopAudio is just:
stopTrack // atomic
track.looping = looping
track.index = 0
track.audio = audio


So this is blazingly fast and simple, in expense of heavy memory usage. What do you think?
>>
File: Zig.png (3KB, 200x200px) Image search: [Google]
Zig.png
3KB, 200x200px
Code in Zig!

http://ziglang.org/
http://andrewkelley.me/post/intro-to-zig.html
https://github.com/zig-lang/zig
https://news.ycombinator.com/item?id=11060282
https://www.reddit.com/r/programming/comments/44skm2/introducing_the_zig_programming_language/
https://www.reddit.com/r/Zig/
https://www.youtube.com/watch?v=AiintPutWrE
https://www.infoworld.com/article/3113083/application-development/new-challenger-joins-rust-to-upend-c-language.html
>>
File: ss (2017-09-05 at 05.29.17).png (23KB, 722x232px) Image search: [Google]
ss (2017-09-05 at 05.29.17).png
23KB, 722x232px
Writing a type-checker and machine-code compiler for a dependently-typed language based on QTT.
>>
>>62267015
>How would you implement a real-time software audio mixer without locking
i dont really know what an audio mixer is nor what locking means in the context of audio

is what i think
anyways gl
>>
>>62267052
>reddit
Go back
>>
>>62267080
Bitch I'm gathering all resources I can
>>
File: andybalaam.png (6KB, 779x56px) Image search: [Google]
andybalaam.png
6KB, 779x56px
>>
int main() {
double xpos, ypos, rad;
cin >> xpos >> ypos >> rad;
cout << xpos << '\t' << ypos << '\t' << rad << endl;
}
>>
>>62267124
1.8,1.99,20
1.8 0 6.95289e-310
>>
>>62267078
>what locking means in the context of audio
Thread locking.

>what an audio mixer is
the audio driver needs some yummy samples to feed the speakers
its fat and lazy so it sends out her light servant, the callback
the callback finds all the tracks and asks them what music they're currently jagging to
they all say different things
the callback sums them up and carries back to the sound driver
driver is happy again (not for long though)
>>
I had a dream that inspired to me to make a game, so I'm making one. I have this really strong gut feeling that it will make me super rich. Maybe not on the scale of Notch, but certainly on the scale of the Stardew Valley guy. Can't wait until I'm raking in the big ones and /g/ is calling me a fag or some shit.
>>
>>62267015
you first need to make a non-locking software mixer

>>62267154
take this
>>
>>62267177
fuck i slept too little, meant to link the other way around
>>
>>62267154
hah, implying we won't call you a fag now
fag
>>
>>62267136
>Thread locking.
what you mean deadlocks?

what's the difference between tracks and music though, isn't a track basically music or is track also a technical term

so basically you want your program to play multiple audio files at the same time in real time?
>>
>>62267052
>
const io = @import("std").io;

pub fn main() -> %void {
%%io.stdout.printf("Hello, world!\n");
}


Holy fuck no that looks worse than sepples and Rust
>>
>>62267052
>AT&T syntax
tl;dr
>>
>>62267244
>what you mean deadlocks
without needing to interrupt other thread (the callback thread). This can only be achieved with atomic operations.

>so basically you want your program to play multiple audio files at the same time in real time
precisely

>what's the difference between tracks and music though, isn't a track basically music or is track also a technical term

sample is the most basic sound element, an integer/float
channel can be 1 (mono) or 2 (stereo), or more but I don't support them
frame is the smallest sound slice, if mono it's a single sample, if stereo it's two samples (for left ear and right ear)
tracks are sounds playing/looping/mute at the same time
sounds are arrays of frames
>>
>>62266919

Trying to learn how to work with Raspberry Pi to pull information from another machine and setting up a webserver with like xamp or something. How does nagios work? o.o
>>
>>62267349
geez that's a lot of new words
im actually planning on making something music related so i'll have to learn about this sort of thing

thx for explaining
>>
What book(s) should I get if I'm an intermediate level C++ programmer and want to learn Java from scratch?
>>
File: 1503781260947.jpg (1MB, 610x5332px) Image search: [Google]
1503781260947.jpg
1MB, 610x5332px
>>62266919
What needs to be added?
What needs to be changed?
>>
>>62267558
Zig needs to be put as the best lang
>>
>>62267304
>%%
Why
>>
>>62267558
deleting the whole thing
>>
I just scraped all the usernames from the first page of /g/ with python, yey me

results:
users: ['Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous', 'Anonymous']
>>
>In the fragment shader, there is no default precision given for floats: Every shader must declare a default float precision or specify the precision for every float variable. In addition, OpenGL ES 2.0 does not require that an implementation support high precision in the fragment shader.
Okay if the shader compiler doesn't support highp couldn't it just default to mediump and still compile even if you declare the default to be highp.
Not compiling is the most retarded way of dealing with this. Fucking opengl was mistake.
>>
>>62267639
It's that famous hacker. He surely seems to spam a lot.
>>
What are some good books on optimising and refactoring code?
>>
https://stackoverflow.com/a/614420

this is bollocks right? why shouldn't your own project's headers go on the top?
>>
>>62267641
there's a macro if highp is available you fucking retard

use ifdef
>>
>>62267684
>have to write
#ifdef GL_FRAGMENT_PRECISION_HIGH
precision highp float;
#else
precision mediump float;
#endif

>for every shader instead of the compiler just doing the right thing
Fuck opengl.
>>
>>62267702
kill yourself clueless whiny fag
>>
>>62267702
how does one post codeblock on 4chin?
>>
>>62267702
just use mediump everywhere you fucking mong
no float precision will fix your shit being shit
>>
>>62267721
"[C" your code here "C]"
>>
>>62267721
markdown newfriend
>>
>>62267720
>opengl couldn't just include macro for the highest available precicion
fuck off dumb khronos shill
>>
>>62267721
 code here [\/code]
>>
>>62267674
Please don't mock the hacker known as 4chan
>>
>>62267751
fucking pointless. if your shader works fine with mediump you should just use mediump. using highp cuts perf by ~50% and gl es devices are already constrained as it is
>>
>>62267768
Rule 1: don't talk about the hacker
>>
>>62267776
Rule 2: don't talk about the rules that talk about the hacker
>>
Hey /g/,

Will this work, or is this UB/potential troubles with aliasing?

Shared header file:
struct handle
{
int some_member;
};


void init_handle(struct handle** handle);

void free_handle(struct handle* handle);



Handle-related source file:
struct wrapper
{
int other_member;
struct handle actual_handle;
};


void init_handle(struct handle** handle)
{
struct wrapper* w = malloc(sizeof(struct wrapper));
return &w->actual_handle;
}


void free_handle(struct handle* handle)
{
struct wrapper* w = (struct wrapper*) (((unsigned char*) handle) - offsetof(struct wrapper, actual_handle));
free(w);
}



Some caller:
int main()
{
struct handle* handle;

init_handle(&handle);
// do stuff
free_handle(handle);
}
>>
class CellRendererProgressWindow(Gtk.Window):

def __init__(self):
Gtk.Window.__init__(self, title="CellRendererProgress Example")

self.set_default_size(200, 200)

self.liststore = Gtk.ListStore(str, int, bool)
self.current_iter = self.liststore.append(["Sabayon", 0, False])
self.liststore.append(["Zenwalk", 0, False])
self.liststore.append(["SimplyMepis", 0, False])

treeview = Gtk.TreeView(model=self.liststore)

renderer_text = Gtk.CellRendererText()
column_text = Gtk.TreeViewColumn("Text", renderer_text, text=0)
treeview.append_column(column_text)

renderer_progress = Gtk.CellRendererProgress()
column_progress = Gtk.TreeViewColumn("Progress", renderer_progress,
value=1, inverted=2)
treeview.append_column(column_progress)

renderer_toggle = Gtk.CellRendererToggle()
renderer_toggle.connect("toggled", self.on_inverted_toggled)
column_toggle = Gtk.TreeViewColumn("Inverted", renderer_toggle,
active=2)
treeview.append_column(column_toggle)

self.add(treeview)

self.timeout_id = GObject.timeout_add(100, self.on_timeout, None)

def on_inverted_toggled(self, widget, path):
self.liststore[path][2] = not self.liststore[path][2]

def on_timeout(self, user_data):
new_value = self.liststore[self.current_iter][1] + 1
if new_value > 100:
self.current_iter = self.liststore.iter_next(self.current_iter)
if self.current_iter == None:
self.reset_model()
new_value = self.liststore[self.current_iter][1] + 1

self.liststore[self.current_iter][1] = new_value
return True

def reset_model(self):
for row in self.liststore:
row[1] = 0
self.current_iter = self.liststore.get_iter_first()
>>
>>62267805
Rule 3: don't talk about the rules that talk about the rules that talk about the hacker.
Rule 4: don't talk about the rules that talk about the rules that talk about the rules that talk about the hacker.
Rule 5: don't talk about the rules that talk about the rules that talk about the rules that talk about the rules that talk about the hacker.
Rule 6: don't talk about the rules that talk about the rules that talk about the rules that talk about the rules that talk about the rules that talk about the hacker.
Rule 7: don't talk about the rules that talk about the rules that talk about the rules that talk about the rules that talk about the rules that talk about the rules that talk about the hacker.
Rule 8: don't talk about the rules that talk about the rules that talk about the rules that talk about the rules that talk about the rules that talk about the rules that talk about the rules that talk about the hacker.
Rule 9: don't talk about the rules that talk about the rules that talk about the rules that talk about the rules that talk about the rules that talk about the rules that talk about the rules that talk about the rules that talk about the hacker.
Rule 10: don't talk about the rules that talk about the rules that talk about the rules that talk about the rules that talk about the rules that talk about the rules that talk about the rules that talk about the rules that talk about the rules that talk about the hacker.
>>
@62267890
kys retard
>>
>>62267854
this should work I think
>>
>>62267908
>@
>>
@Anonymous #62267908
:+1-skintone5:
>>
>>62267890
Babby's first Python loop
>>
>>62267916
So I'm not causing any potential problems for myself by doing this, except alignment issues for contiguous wrappers maybe?
>>
>>62267927
This was in C faggot
>>
>>62267938
I'm not an expert but I can't see why there would be any alignment issues at all
>>
>>62267972
Okay, thanks.
>>
>>62267951
Proof.
#include <stdio.h>

int main(void) {
for (int rule = 3; rule < 11; ++rule) {
int repeat = rule - 1;
printf("Rules %d: don't ", rule);
for (int i = 0; i < repeat; ++i) {
printf("talk about the rule that ");
}
puts("talk about the hacker.");
}
}

And yes, the prototype was in Python:
for i in range(3, 11):
adder = i - 2
root = "Rule "+str(i)+": don't talk about the rules that "
for i in range(adder):
root += "talk about the rules that "
root += "talk about the hacker."
print(root)
>>
Difficulty of writing a nintendo emulator in Rust from scratch? Im an "intermediate" programmer. Several years of school under my belt looking to improve my skills and emulators seem really neat
>>
>>62268012
>int main
>No return value
>>
>>62268088
rax is the return value
>>
>>62268012
>the prototype was in Python
lol
>>
>>62267154
fag
>>
>>62268057
make a kernel in rust
>>
>>62268173
make a better language in rust
>>
>>62268173
make a kernel in haskell instead
>>
File: pathetic.jpg (24KB, 680x419px) Image search: [Google]
pathetic.jpg
24KB, 680x419px
>>62268088
>he doesn't know about 5.1.2.2.3
>>62268120
I'm better at both than you
>>
>>62268057
A GameBoy Color emulator shouldn't be that hard I guess.
>>
>>62268203
make a haskell in kernel
>>
>>62268238
I have no respect for non-asm code.
>>
>>62268246
make you a kernel
>>
>>62268265
in haskell this is just <&>>>= <*> & <$> <|> fmap id
>>
>>62268012
>the prototype was in Python
pathetic
>>
>>62268057
What do you mean by Nintendo? If it's a game boy like some other anon said then it won't require much work.
>>
>>62268293
>
<&>>>= <*> & <$> <|> fmap id

Can you give me a run-down on what this actually does m8?
>>
>>62268303
linux, it does linux
>>
>>62268303
I just ran it in GHC and got an erection
>>
https://jsfiddle.net/ez9Lf1wa/

rate my fizzbuzz
>>
>>62268303
Nobody knows
>>
>>62268326
I see your productivity is evaluated based on the number of lines you write. 10/10
>>
>>62268057
Should not be more difficult than writing an emulator in another language
>>
>>62268385
this is 2 lines, the first one is empty
>>
So, I actually did some benchmarks and on my particular compiler, allocating 256 mb of 4 1 byte sized record fields and filling them, then assigning to a variable, was twice slower than doing the same thing with 256 of 4 byte integers.
Both when compiled to 32 bit and 64 bit.

The compiler is pretty much a community project, so it was to be expected.
I guess it's time to write my own library: a record syntax wrapper around a 1D array of int.
>>
>>62268408
And the bible is just a one line long string.
>>
Got fired but they need me to fix an application due September 15th I'm sad
>>
>>62268430
>they need me
>get fired
Makes sense.
>>
>>62268439
I wish it did senpai
>>
>>62268444
And how are you obligated in any way to do that?
Let alone legally when you are no longer being paid.
>>
>>62267076
Sounds yummy. Care to explain in more detail for those of us that don't into type-checkers? What's all that funny stuff in your picture?

>>62267558
It's neither accurate nor ironic. Your memes are bad and you should not feel good.

>>62267919
That looks like a duck, hehe, quack quack.
>>
Writing an implementation of ActivityPub
>>
>>62268464
depends on the employment laws where he lives if it's a delay or he needs to work a bit longer to get his last paycheck or w/e
>>
>>62265728
How can they be so stupid to not realize that they are only hired as PR candy? Nobody considers then nothing more than a joke in regards to coding, MS just hires couple of them to sit around and make coffee, and maybe write some html templates, so they look good to the public because "look at as we hire le coder wimenz"
>>
>>62268575
Are you seriously saying that women all suck at programming? One of the best graduates in my class was female.
>>
>>62268399
>language designed to make it a pain to write anything
I'm sure it won't.
>>
>>62268589
Out of all women who call themselves programmers 98% of them suck cock at it
And the best programmers in the world are, big surprise, males
>>
>>62268591
>language designed to stop you from doing retarded """shortcuts""" that end up making your program fail in the long run

Fixed.
>>
File: 1479417088030.png (103KB, 270x320px) Image search: [Google]
1479417088030.png
103KB, 270x320px
>>62268591
>language designed to make it a pain to write segfaulting programs
fixed it, senpai
>>
>>62268609
Don't worry, I'm sure if you change your fedora to a trilby the cute red haired girl in the office will date you then bro
>>
>>62268615
>>62268618
You're right. Preventing users from write programs is a good way to make sure they won't do anything harmful!
>>
Are there any legitimate alternatives to OOP? Like, is there anything on the horizon that might work in more than just a "look at this really elegant cherry picked example" kind of way?
>>
>>62268701
Proof based programming
>>
>>62268701
If youre on C#, you can use LINQ and do a lite-version of FP'ing.
But if your language supports actual constants/immutables, then just force yourself to only use pure functions.
>>
>>62268731
?
>>
>>62268746
?
>>
>>62268746
>>62268750
??
>>
>>62268731
>pure functions
I'm sure passing everything by value is the patrician alternative to OOP
>>
>>62268746
a pure function is one with zero side-effects and all your input and outputs are balanced.
The most basic example is an add x + y function which returns the sum and nothing else.
When you need to mutate a variable. Instead of that, make a new constant version with said value.
>>
>>62268746
>>62268750
>>62268762
???
>>
>>62268776
You can pass by immutable reference too.
>>
>>62268785
And how is that an alternative to OOP exactly?
>>
>>62268795
What about resulting objects? Pure FP is fine if you do not care about function call overhead but I'm still looking for the thing that will simplify programming soft real time agent based simulations
>>
>>62268820
OOP tries to hide mutable state in objects, which is usually where errors come from. The next step is getting rid of it altogether.
>>
>>62265728
I hate the fact that this is probably true
>>
>>62268820
How is it not?
anything you can do in POO, you can do in FP, only much cleaner and with near-zero run time errors.
>>
>>62268840
I suspect that any decent compiler would be able to optimize something like
>foo = ChangeFoo(foo);
to not allocate at all.
>>
>>62268862
Making these assumptions is what lead us to clunky and bloated programs in the first place
>>
>>62267513
Anyone?
>>
I'm writing a program where the graphical client is just a dumb terminal that sends input to and displays output from a (possibly remote) server. Are there any design patterns for this? I was thinking model/view/presenter but putting the model and presenter on the server. However, that would mean that the view would have networking code. Is that bad?
>>
>>62266919
#include <stdio.h>

int main(){

int c = 5, d;
d = ++c + ++c + ++c + ++c + ++c + ++c + ++c + ++c + ++c + ++c + ++c + ++c;

printf("%d\n", d);

return 0;

}


How much is d?
>>
File: rust_diversity.png (136KB, 1222x550px) Image search: [Google]
rust_diversity.png
136KB, 1222x550px
https://blog.rust-lang.org/2017/09/05/Rust-2017-Survey-Results.html
So much for "Rust is for traps" meme.
>>
>>62269071
It is exactly
++c + ++c + ++c + ++c + ++c + ++c + ++c + ++c + ++c + ++c + ++c + ++c
>>
>>62269071
Depends on compiler.
>>
@62269071
why do you post this shit everyday?
>>
>>62269085
>19% of Rust devs consider themselves underrepresented
>>
It's for SJWs, so who cares?
>>
>>62269071
more than your mom
>>
>>62269099
I bet it mostly the same 60yo lame communist muslim queer illiterate trans-women of color from Sudan checking all the boxes.
>>
>>62269085
None of these groups covers traps
>>
>>62269086
>>62269090
>>62269106
Incorrect. The correct answer was 138.
>>
>>62269147
>or perceived as woman
>>
>>62269071
That's such a retarded question. Who would ever write something that stupid? This same shit is here everyday. "Look at me, I can make my retardation compile without errors hurrdurr"
>>
>>62269085
If they "feel underrepresented" they should do more.
>>
>>62269147
mental disability is right there.
>>
>>62269157
wrong

https://ideone.com/GCLcdi
>>
File: Capture.png (5KB, 239x80px) Image search: [Google]
Capture.png
5KB, 239x80px
>>62269157
u sure
>>
I feel like a huge retard when I program.
How do I get good?
>>
>>62269085
leftist fags are overrepresented if anything
>>
What does unwrap do in Rust? I haven't yet found a satisfactory explanation.
>>
>>62269199
Switch to Python
>>
>>62269085
How exactly should lesbians and gays be represented in tech? I can understand that women might feel they're not taken seriously or whatever, but nobody can even tell you're gay without you ranting about it.
>>
>>62269202
Return T if value is Some(T) or Ok(T), otherwise panics.
What's not to get?
>>
>>62269213
>Switch
>Python
>implying
>>
>>62269202
match value {
Some(v) => v,
None => panic!("wtf are you doing retard"),
}
>>
>>62269231
Sorry, I've forgot that Python doesn't have switch.
>>
>>62269226
>>62269235
Why is it considered bad practice? What are you supposed to do instead?
>>
>>62269216
> "So I and my gf went to this cafe last night..."
> "Cool, tell us more"
> "So I and my bf went to this cafe last night..."
> "WTF stop ranting about it"
Naturals, everyone.
>>
Hey guys, how do I learn programming? Like where should I start as an absolute beginner?
>>
>>62268974
If it's really simple, sounds like you just need a loop that does
input = readInput()
output = processInput(input) // this sends a request to a server
display(output)

Don't think there's a name for something like this. It's just basic IO handling.

>>62269085
>180 /pol/acks use Rust

>>62269086
Does it really?
>>
Hi is there a special kind of list i would use if i just want the ability to move an element to the top
>>
>>62269253
you can implement it
switch(a,
(1, a),
(2, a*2),
('default', a**2)
)

switch is just a function with variable number arguments

ez
>>
>>62269263
Actually process the error with pattern matching or `or_else`-like methods. Your program shouldn't crash just because it failed to parse an int.
>>
>>62269264
If you don't want your coworkers to treat you differently because you're faggot, don't tell them about your personal life, faggot. But do tell me: Now that we know that you're gay, what is it that you want us to do about it exactly? How do we make you feel adequately represented?
>>
>>62269265
Visual Basic 6
>>
>>62269265
1. pick the field you want
2. try all the popular languages in that field
3. pick the one you hate the least
4. pirate a book
5. learn
>>
>>62269263
You should handle the error in some way, even if it's as simple as an early return. with the error.
>>
>>62269263
You're supposed to actually handle the error, by either doing something with it or bubbling it up the abstarction layer.
.unwrap() is only used for short examples where concrete error handling is distracting. It is similar to exception based languages when not catching exceptions when you're actually able to.
>>
Are there any languages that are designed for composition over inheritance? I like entity component system frameworks but I wish they had more compile time safety.
>>
>>62269297
hey that's actually a useful function
>>
File: ganbatte.png (829KB, 1437x1080px) Image search: [Google]
ganbatte.png
829KB, 1437x1080px
>>62267154
>>
>>62269315

I don't know any fields though
>>
I can't figure out why python is telling me this is invalid syntax
    if choice1loop==True:
choice1=int(input("")
if choice1==1:


File "Main.py", line 46
if choice1==1:
^
SyntaxError: invalid syntax
the arrow is pointing to the colon in case the formatting is fucked up by posting.
What am I doing wrong?
>>
>>62269308
>You're either a gay or a homophobe
Guess what, I'm neither, I just don't think it's reasonable to treat people differently just because they're gay, that includes being able to talk about it.
>>
>>62269368
Do you want to do webshit, mobleshit or desktop shit?
>>
>>62269320
>>62269304
What's the most concise way to just ignore an error like you would an exception (i.e. by returning the error early)
Pattern matching seems a bit syntactically heavy if you're calling a lot of functions that return Results.
>>
>>62269372
You're missing a )
>>
>>62269372
probably your indentation.
>>
>>62269384
You didn't answer the question, so fuck off.
>>
File: 1503166647040.jpg (105KB, 790x700px) Image search: [Google]
1503166647040.jpg
105KB, 790x700px
>let me know if you get any other offers, you're a strong candidate and I don't want to lose you. expect me to get back to you next week
>Aug. 10
>>
>gl specs says int is 32, float is 32, short 16 and so on...
>niggers still use sizeof(SOME_FUCING_C_VALUE) as offset for opengl
>even though their int might be 16 bits
WTF
>>
>>62269406
He'd run into indentation error then.
>>
>>62269398
>Returning errors early
Use the Question Mark operator:
fn run() -> Result<(), Box<Error>> {
let sdl = sdl2::init()?;

Stolen from my own code.
>>
>>62269419
having a platform api solves this
>>
>>62269323
Most functional languages.
>>
>>62269403
Didn't notice that, fixed, but didn't solve the problem.
>>62269406
indented the 2nd if statement, said indentation error.
>>
>>62269414
sorry anon
>>
>>62269444
What fucking platform API?
Graphics drivers don't implement no "platform API".
>>
>>62269444
OpenGL provides types like GLint, GLfloat, etc. that you are supposed to use.
>>
>>62269434
Beautiful. What's the best way to learn Rust from a C++ background?
>>
>>62269398
> ignore an error like you would an exception
The ? operator will. `or_else` functions are handy if you just want to keep going with some default value in case of error.
>>
>>62269213
Seriously though. I see people on here do all kinds of fancy shit and being able to spot bugs and errors easily and I'm just trying to make my clunky, hacked together shit work
It's discouraging
>>
>>62269320
>.unwrap() is only used for short examples where concrete error handling is distracting.
It's also an assertion that the value will be Some(x).
>>
Why does some obscure russian analog of 4chan has a board dedicated to programming and generals for different languages and topics and 4chan, international chan, has one shitty generals filled with memes?
>>
>>62269294
plz reply??
>>
>>62269385
Which one pays more?

Actually which is the least boring?
>>
>>62269513
blame moot for scrapping prog and text boards
>>
>>62269458
they had already brought me to their campus for two interviews and a programming exercise
>>
>>62269514
Perhaps you want a zipper that can focus on elements instead?

What's your actual usecase?
>>
>>62269471
That's kind of difficult to tell, I learned Rust through the book (https://doc.rust-lang.org/book/) + random exercises.
>>
>>62269294
..a stack? A tree? A linked list?
>>
>>62269534
It's for a gui
I want to use the order the windows are in to figure out which window should be clicked if they're overlapping
>>
>>62269569
modality my nigga
>>
Which book should I buy first, TAOCP 1-4A or the dragon book?
>>
>>62269398
The best way is to use or_else to set a sane default value.

let x = maybe_int().unwrap_or_else(|| -1);
>>
>>62269591
Harry Potter and the Sorcerer's stone
>>
>>62269582
Im not using any libraries or creating windows in the os like a dialog box
>>
>>62269624
I think you should use a stack then.
What is it you are doing?
>>
>>62269598
Yep, part of my code looks like this:
fn neigbor(&self, from: (i32, i32), to: (i32, i32)) -> PixelType {
let new_x = from.0 + to.0;
let new_y = from.1 + to.1;

if new_x < 0 || new_y < 0 || new_x > self.width || new_y > self.height {
return Wall;
}

*self.data.get(&(new_x, new_y)).unwrap_or(&Empty)
}
>>
>>62269616
I already have the entire HP series
And it's Harry Potter and the Philosopher's Stone by the way
>>
>>62269646
a gui with multiple windows that can be dragged around
>>
>>62269616

It's Philosphers stone you fucking pleb

JK really needs to update Pottermore, I want to know the rest of the schools
>>
>>62269533
have you reached out to them?
>>
>>62269652
>>62269671
Sorry for that boys, I mistranslated.
>>62269665
so vague, love it. rawr
>>
>>62269709
umm how can you not understand??

im just trying to move an element to the top
>>
>>62269591
Honestly TAOCP is way too expensive for what it's worth, for the same price you can buy many state of the art books on the covered subjects. The dragon book is quite outdated but will probably be a better read if you're not an expert in compiler theory.
>>
>>62269709
burger version is called sorcerer's stone
>>
>>62269728
you just said shit that I already know
>>
>>62269414
>Thanks for applying! Your application is currently being reviewed by our team.
>Aug. 2
I'm not waiting for them, just moved on without telling them, their loss.
>>
>>62269569
Probably an array based list, then, since you'll be iterating the windows much more often than moving elements to the top.
>>
A community platform using Golang. However, I need /g/'s advice and feedback on how I'm going to implement some of it.

I HAVE: Several microservices offering among other things 
wiki, account, media storage services.
Each of them run as an independent application.

I WANT: A gateway that routes traffic onto these services,
and also handles sessions and authentication.
I do not want to use third party applications to do this for me.
So no etcd, consul and so on.

MY IDEA: I have a POST http handler on the gateway, and each
of the microservices make a request to the gateway.
It has a JSON document describing the endpoints they want routed to them.

1. I start up the gateway.
2. I start up the user service.
3. The user service finds the gateway through DNS or through
an ip:port parameter, and makes a http POST request which just says "/users".
4. The gateway after authenticating this request, now routes everything
request matching /users* to the user service.
5. ????
6. PROFIT


Is it retarded? Am I missing something obvious here?
>>
>>62269591
>dragon book
nah
check those

http://www.cs.princeton.edu/~appel/modern/
https://www.amazon.com/Engineering-Compiler-Keith-Cooper/dp/012088478X

taocp is a great poop book imo, plus Bill Gates will hire you after reading it
>>
>>62269828
>Golang
>Is it retarded?
Yes
>>
>>62269828
No clue about how those web apps are made, but if you want to avoid memesters (or at least, have a less condescending bunch) you should cross post to >>>/g/wdg/ if not already done.
>>
File: images.png (6KB, 185x272px) Image search: [Google]
images.png
6KB, 185x272px
>>62269828
>Golang
>Is it retarded?
Gee, I wonder.
>>
>>62269533
And you never wrote them? What are you, some kind of a beta

Reach you, refresh their fucking memory
>>
File: portrait.jpg (19KB, 500x335px) Image search: [Google]
portrait.jpg
19KB, 500x335px
>>62269878
>>62269854
FUCKING DELETE THIS

THE KEY POINT HERE IS OUR PROGRAMMERS ARE GOOGLERS, THEY’RE NOT RESEARCHERS
>>
>>62269852
Appel's books are practical introductions and clearly don't replace anything found in the Dragon book. That being said I haven't read the second one you linked.
>>
>>62269878
Seriously though, Rob Pike needs to divorce or just not let her wife design mascots ever again.
>>
>>62269854
>>62269857
>>62269878
>tfw the gopher is retarded
I trusted a Pike. I'm sorry /g/
>>
File: e55.png (150KB, 680x680px) Image search: [Google]
e55.png
150KB, 680x680px
>>62269916
It's cute! CUTE!
>>
What's your favorite example of OO fuckery /g/? I like Spring's AbstractSingletonProxyFactoryBean.
>>
>>62269995
The programming industry.
>>
>>62269976
exceptionsfags will be the first to go on the day of the gopher
>>
>>62269976
Go error handling >>>> Exceptions
>>
>>62269995
>What's your favorite example of OO fuckery /g/?
Smalltalk is just marvelous as a whole
>>
>>62270047
Monadic Error handling >> All
>>
>>62270057
Agreed
>>
>>62270057
What does that mean?
>>
>>62270075
It means you use sum types to return either a result or an error.
>>
>>62270023
>>62270047
>They think exceptions is the only alternative
Besides, exceptions require less boilerplate and you can't just silently ignore them, so I'm not sure it's worse than Go.
>>
>>62270075
Returning ADTs instead of throwing exceptionns.

t. Rustfag
>>
What do mobiledevs use these days?
>>
>>62270093
>you can't just silently ignore them.
Unless your language has checked exceptions, that's not true.
>>
>>62270089
So what's the difference with something like:
try:
return result
except:
return error
>>
>>62270075
Retardspeak for error value
>>
>>62270057
>>62270097
>when you realize that you're always in a monad and throwing an exception is equivalent to returning Left err.
procedural programing wins again
>>
>>62270135
caller can use result without checking error unless you have checked expections

>>62270047
Go doesn't have error handling. Returning pairs of maybe an error and maybe a value FOR GENERAL ERROR HANDLING is the most retarded shit ever. 99% of the time you have either an error or a result. 1% of the time you have a result with some potential error (more like warning) alongside it. Go's error handling is "I hope you remembered to check err first 100% of the time". It's the most braindead shit, it's using completely wrong thing and it's all manual. It really baffles me.
>>
>>62270131
trade secret
>>
>>62270135
I don't understand the question.
>>
>>62270135
The most important difference for me:
It's not invisible, it's part of the type siignature, e.g.:
void foo() {}

may or may not throw, you don't know unless the writer decided to document it, whereas
fn foo() -> Result<(), FooError>

it is extremely obvious that foo is fallible and the type system forces you to handle the error
>>
>>62270133
Right, I mean than in Go you can write code like
result, err : = some_func();
//Ignorign err here
use_resutl(result);

and the compiler will eat it. I'm not sure, but I think you can even write stuff like
result, _ = some_func();

With exceptions, you can do `try {...} catch(...) {}`, which is bad but at least 1) it's explicit 2) the thread will be interrupted at the point of the error. In Go, you can just ignore an error and go ahead using an invalid value.
>>
All you retards believing your comparisons between exceptions and return types hold should stop posting. Exceptions are meant to break control flow.
>>
>>62270231
This is why I don't mind Java's checked exceptions so much.
>>
>>62270231
Alright, that makes sense. Thanks.
>>
>>62270265
>he can't into monads
>>
>>62270261
>the compiler will eat it
Go doesn't let you have unused variables
>>
>>62270265
Is that supposed to be a good thing?
>>
>>62270274
>he thinks he understands category theory

>>62270283
Yes, because exceptions are orthogonal to error values.
>>
>>62270277
In a language with multiple return, that's fucking dumb.
>>
>>62266919
Trying to do TDD in C but it's taking SOOO LOOONG. And to boot, I don't even look forward to writing code because I am stuck writing tests. And I am not really sure how to test some things, or if my test covers all the bases. It's too much to consider for a one-man project ffs, it's hard enough just cowboy coding.
>>
File: canvasd.png (33KB, 640x400px) Image search: [Google]
canvasd.png
33KB, 640x400px
>>62266919
>>
>>62270277
What is _?
>>
>>62270325
>I would like everyone to know I have never read a single line about the language
>>
>>62270305
>he thinks anyone cares about category theory
>>
>>62270349
... not a variable name? The _ symbol is the explicit way to discard a result.
>>
>>62270305
That doesn't explain why hidden execution paths are good.
>>
File: goland_error_handling.png (18KB, 548x411px) Image search: [Google]
goland_error_handling.png
18KB, 548x411px
>>62270277
So what? https://godbolt.org/g/EoYwqH
>>
>>62270335
or don't use C?
>>
File: 1480952587241.png (259KB, 1665x1022px) Image search: [Google]
1480952587241.png
259KB, 1665x1022px
>>62266919
Making a falling sand game clone in Rust + SDL2
>>
>>62270371
So we don't use some variable returned by a function, right?
>>
>>62270391
Yes, that's what discard means.
>>
>>62270265
The problem is that a ton of people (including language devs themselves) use exceptions in cases that aren't exceptional. NumberFormatException shouldn't exist. When you call parseInt(str) the case where str doesn't represent a number is perfectly valid, not exceptional.
>>
what are you guys using perl for nowadays :)

i use it for gui programs, scripting, and websites
>>
>>62270426
Python uses exceptions to terminate iterators. It's fucking insane.
>>
>>62270426
Agreed, because they believe exceptions and errors are related.
>>
int
isapos (char number[]) {
for (; number != '\0'; number++) {
if (number == '\'') return 1;
}
return 0;
}

Is there anything wrong with the code?
>>
>>62270475
Yes, it assumes the string is null-terminated.
>>
>>62270385
Yes, what's your point? You do realize the Rust equivalent would be wrapping your whole code in unsafe right?
>>
>>62270501
If it's the only problem, then it's fine.
>>
ruby, python, rust, go and other millennial languages are dead once Perl 6 drops
>>
>>62270513
If you're going to use it on user input make sure you have a length-limited version available
>>
>>62270475
>comparing a pointer to char against a char
>>
>>62270517
>Perl 6 drops
Not even released and we've already already dropped it fa.m
>>
>>62270524
Thanks.
>>62270525
Oh well, thanks.
>>
>>62270504
I've stated my point already: in Go, you can just ignore an error and go ahead using an invalid value.
>the Rust equivalent would be wrapping your whole code in unsafe
The Rust equivalent of what, of the broken code that ignores errors and uses invalid values? I don't thing even unsafe would help you do it, that's the point.
>>
java programmer here
>>
>>62270570
do you suck dicks?
>>
>>62270570
learn C++
>>
>>62270570
Are you employed?
>>
File: Capture.png (1MB, 1507x1493px) Image search: [Google]
Capture.png
1MB, 1507x1493px
switched out ffmpeg for streamlink + added inline videos. starting to shape up.
>>
>>62270570
Are you a Java programmer or are you an AbstractJavaProgrammerFactoryBeanManager?
>>
>>62270567
> I don't thing even unsafe would help you do it, that's the point.
Akshually:
use std::mem::uninitialized;

fn main() {
let undef: i32 = unsafe { None.unwrap_or(uninitialized()) };
println!("Whatever: {}", undef);
}
>>
>>62270611
gtfo with your real women, 2D bitches only!!!
>>
>>62270567
You're not ignoring it, you're explicitly discarding it. It'd be like stating the Rust BC is pointless because you're unsafing everything on purpose when it's a developer decision.
>>
>>62270647
:(

somebody should make a cam site where 2d anime girls could whore themselves out for tokens :)
>>
File: EVc3Nm0.png (427KB, 770x478px) Image search: [Google]
EVc3Nm0.png
427KB, 770x478px
>>62270638
Good one, but not exactly.
>>62270651
With unsafe you have to actually write `unsafe`, and the compiler won't allow to use unsafe code outside of `unsafe`, you can't be more explicit.
With Go's error handling, all you have to do is to forget to check the value or to write `_` instead of `err`, it's not automatically enforced and hardly visible in the code, especially if it's already full of `if err != nil` every other line.
>>
>>62270737
>With unsafe you have to actually write `unsafe`,
With _ you actually have to write _. It's not as verbose but it's still explicit.
>>
A systems programming language with features like type constructors, traits, lambdas, and dependent types. Not for safety, though, just code reuse.

>>62270786
What happens if you ignore the error but it occurred? Does the program keep running or does it panic?
>>
>>62270737
>It's ok if WE do it!
It's almost like the Rustlets memes write themselves.
>>
>>62270786
How explicit is this?
a, err := fun();
if err != nil {}
//Wew, I don't have to check `err` anymore.
// Btw the compiler is reusing `err`, despite me using := here.
b, err := fun();
c, err := fun();
d := a + b + c
>>
>>62270802
You can't ignore the error unless you discard it.
>>
>tries to make a program that prints a diamond in '*' signs in Java through using for loops
>can't do it

HELP A BRAINLET
for(space=-12;space<linje;space++)
{ System.out.print(" ");
}
for(star=0;star<2*linje;star++)
{
System.out.print("**");
}

System.out.println("");
>>
>>62270893
I mean, if you match the error to _ but it occurs.
>>
everything is becoming worse
prove me wrong
protip: you cannot (because i'm right)
>>
It shouldn't be possible to implicitly ignore an exception. If it's something that won't blow up the universe if it's ignored, then it's not an exception.
>>
File: 1494715042532.png (253KB, 645x773px) Image search: [Google]
1494715042532.png
253KB, 645x773px
>>62270898
fuck I accidentally posted when I fucked up using tab
for(space=-12;space<linje;space++)
{
System.out.print(" ");
}
for(star=0;star<2*linje;star++)
{
System.out.print("**");
}

System.out.println("");
>>
File: 1483543721292.png (87KB, 853x621px) Image search: [Google]
1483543721292.png
87KB, 853x621px
>>62270868
>he still thinks the comparison is valid
It's like all they say about Go defelopers is true.
>>62270893
False, see >>62270889.
>>
>>62270889
Pretty fucking explicit considering you wrote a whole line to discard it. At this point it's quite obvious you're just being of bad faith.
>>
>>62270932
The first error has been caught. The rest have naught.
>>
>>62270925
>linje
Why do you use Yugoslavian is programming?
>>
>>62270932
> all software bugs are just bad faith
At last I truly see.
>>
>>62270963
I am using norwegian. It means line. What I posted is my current results after 2 hours of countless fuck ups. So I don't know if it even makes sense to you
>>
>>62271020
forget about doing any of these dumb "draw a shape in the terminal" type programming problems
they don't help you become a better programmer; I still can't do those kinds of problems after 15 years of programming
>>
>>62271017
>software written to be bugged is bugged
Leaves one pondering. There are various examples of how to achieve the same thing with any other language, now please kill yourself.
>>
>>62271070
>I still can't do those kinds of problems after 15 years of programming
Are you getting paid to program?
>>
ADT error handling > checked exceptions > directly returning errors > unchecked exceptions
Are we all in agreement?
>>
>>62271070
>15 years of programming
le i started when i was 3.5 yo man
>>
>>62271076
>the language shouldn't be preventing bugs because all bugs are intentional anyway
Right-o, friend-o.
>>62271097
Seems about right.
>>
>>62271104
Ur like a little baby. My father was a programmer. I have it in my genes. Basically I've been programming for 200 % of my life.
>>
>>62271104
I started when I was 12
>>
>>62271128
I'm sorry for your reading comprehension.
>>
>>62271070
it's mandatory homework for my uni. I am required to use for loops for each print statement, by having spaces go from 12 to 0 to 12, increasing/decreasing by 4, stars go from 2 to 26 and back to 2 again, increasing by 8 each time. And this all in 7 lines.

I know some of the basic retard mathematics I need to use, like the number of stars would be star=star-2/space
>>
>>62271095
Yeah
these problems test your spatial intelligence, not your programming ability
>>
>>62271132
perfect example of how some things that aren't genetic get inherited
at least you aren't a doctor with his father and grandfather both doctors or some shit

or cops, even worse
>>62271146
yes, yes you dream in code
>>
>>62271186
Ok, if for some reason you only count professional programming experience, that's still 10 years.
>>
New thread:

>>62271195
>>62271195
>>62271195
>>
>>62268430
>QTT

ask 50k$ for that day.
>>
>>62269071
>>62269157
It's UB you fucking idiot.
Fuck off.
>>
>>62271070
>>62271177
fucking hell
>>
>>62270567
>>62270504
> Ignoring an Error
That's what `unwrap` is for....
>>
>>62267639
Explain
Thread posts: 320
Thread images: 22


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