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

File: dpt_flat.png (102KB, 1000x1071px) Image search: [Google]
dpt_flat.png
102KB, 1000x1071px
Old thread: >>58980706

What are you working on /g/?
>>
>>58986356
First for duct-tape programming.
>>
File: 1486590793476.jpg (40KB, 657x527px) Image search: [Google]
1486590793476.jpg
40KB, 657x527px
>>58986356
a game
>>
>>58986356
"The most powerful programming language is Lisp. If you don't know Lisp (or its variant, Scheme), you don't know what it means for a programming language to be powerful and elegant. Once you learn Lisp, you will see what is lacking in most other languages." -Richard Stallman
>>
File: 1481349139911.png (323KB, 600x617px) Image search: [Google]
1481349139911.png
323KB, 600x617px
Why is C++ OOP so bad?
>>
>>58986399
Because you don't understand it.
When you spend more than a week programming, it is actually pretty good.
>>
>>58986384
>>>/v/ you fucking frogchild java shitter virgin
>>
>>58986356
Realtime streaming of data to muh dashboards.
>>
>>58986399
It's alRAIIt.
>>
File: file.png (64KB, 1208x541px) Image search: [Google]
file.png
64KB, 1208x541px
maybe someone can help me. Im not that experienced with opengl.

I render some triangles in immediate mode. colour are just the normals, so nothing special.
on the left picture it looks all fine and dandy, but when I turn the camera parts of it get transparent/ disappear.
am I missing something? is that a problem with my geometry? disabling backface culling does not help. Im not sure what to make of it.
>>
File: fragments.png (22KB, 716x475px) Image search: [Google]
fragments.png
22KB, 716x475px
>>58986356
Currently working on an app for a project in university. It is basically done but I want to improve the homescreen right now.

I have all the fragments done but I would like to have a overview as a homescreen (for example instead of a full event-list I just want to display the 2 closest events)

Basically pic related. Is there any way to do this without having to code (or rather copy) everything again ?
>>
>>58986414
Or maybe, you know, C++ is shit.
>>
>>58986431
it looks like something else is being rendered on top of it
>>
>>58986431
have you enabled the depth buffer?
>>
>>58986452
ok, here is a question: do I need to sort my geometry in distance from my camera`? that sounds tedious. cant the gpu do that?

>>58986467
I dont think so. I dont even know what that is. but I will look into it.
>>
Reposting
static int a(int 1, int2)
result = 1 + 2;
return result;

void b(int 1, int 2)
Console.WriteLine("Result is" +(1 +2));


Main
Console.Write(a(3,4));

b(3,4);
>>
>>58986431
>>58986480
https://learnopengl.com/#!Getting-started/Coordinate-Systems
Z-buffer section
>>
>>58986399
>Why is x country's communism so bad?
Hmm... I don't know...
>>
>>58986502
What the fucking fuck is that?
>>
>>58986395
Forth > Lisp
you can make forth behave like lisp and even perform better than it
>>
>>58986502
So, it looks like you're very new to programming, and you're also trying to learn C#.

Here's a free book to get you started:
http://www.robmiles.com/c-yellow-book/

There is a link to the PDF on the page, as well as code samples.

It will explain some of the things you're asking very thoroughly, so you don't shit up the thread with dumb questions and bad code.
>>
>>58986517
>you can make forth behave like lisp and even perform better than it
How?
>>
>>58986517
You can also make C behave like Lisp, given enough self-written libraries and an overuse of C-macros.
That doesn't make it worthwhile though.
>>
File: file.png (141KB, 1013x754px) Image search: [Google]
file.png
141KB, 1013x754px
>>58986505
ok, I activated it and it works. no more funny behaviour and no more transparency except this one part.

I do it like this
>clear buffer
>activate depth
>render my stuff
>deactivate depth

strange
>>
>>58986601
>strange
That's a funny way to spell "OpenGL".
>>
Is there something like AP/AOP? (Anime oriented programming)
>>
>>58986601
Activating depth testing should be done once tho, not in every frame.
What should be done in every frame is clearing the depth buffer
glClear(GL_DEPTH_BUFFER_BIT);
>>
>>58986356
                 ORG   $B000
DIVIDEND FCB 000
DIVISOR FCB 025

ORG $B010
QUOTIENT RMB 1
REMAINDER RMB 1

ORG $C000
CLR QUOTIENT
CLR REMAINDER
IF LDAA DIVISOR
CMPA #0
BNE ENDIF
THEN
LDAA #255
STAA QUOTIENT
STAA REMAINDER
DONE BRA DONE
ENDIF
LDAA DIVIDEND
WHILE CMPA DIVISOR
BLO ENDWLE
INC QUOTIENT
SUBA DIVISOR
BRA WHILE
STAA REMAINDER
DONE1 BRA DONE1
ENDWLE
>>
>>58986659
I think I found the problem. the geometry needs more than 1 (in this small case 2) draw call to render. and I dont think the gpu will keep track of depth over multiple calls. or am I wrong?
>>
>>58986567
But you can't you fucking retard.
>>
File: 1482952574417.png (491KB, 650x698px) Image search: [Google]
1482952574417.png
491KB, 650x698px
>>58986681
no need for this language anon
>>
>>58986696
>no need for this language
Do you mean C or Lisp you fucking faggot?
>>
>>58986676
I retract this statement. now without enabling/disabling every frame it works. at least it looks like it
>>
>>58986676
>geometry
Is this a geometry thread or a programming thread? Fuck off.
>>
>>58986676
>>58986709
the depth is stored in the depth buffer
>>
File: 1486982881338.jpg (55KB, 648x1040px) Image search: [Google]
1486982881338.jpg
55KB, 648x1040px
>>58986737
>Is this a geometry thread or a programming thread?
>>
>>58986737
>being retarded
Is this an autism thread or programming thread?
>>
>>58986752
What is this post supposed to mean?
>>58986759
I'm not the retard here since I'm not posting unrelated geometry stuff.
>>
>>58986771
it means you are a fucking retard
>>
>>58986777
But I'm not discussing unrelated stuff here. How does that make me a retard?
>>
File: 1479464061520.gif (2MB, 520x289px) Image search: [Google]
1479464061520.gif
2MB, 520x289px
>>58986737
>>
>>58986771
By that logic fizzbuzz is not related to programming because it's printing stuff to console, not programming.
Now fuck off already.
>>
>>58986800
void methods aren't programming
>>
>>58986794
I don't quite get what this is supposed to mean.
>>58986800
I don't know what kind of fizzbuzz you're talking about, but my fizzbuzz doesn't do IO. So it's definitely related.
>>
>>58986785
yes
>>
>>58986828
Excuse me?
>>
>>58986815
It means you have the reading comprehension skills of a hamster and reflexively posted "DURR IZ DIS A GEE OH MET TREE THREAD OR A PROGRAMMING THREAD U FAGET" like the amerilard you are when the post you responded to is clearly working with OpenGL if you actually bothered to see what the context of it was.
>>
>>58986814
this

for this reason i always modify void functions to return something useful, e.g. the time, the room temperature, train prices, etc
>>
File: qualitybait.png (532KB, 1597x1600px) Image search: [Google]
qualitybait.png
532KB, 1597x1600px
>>58986737
>>
>>58986841
>It means you have the reading comprehension skills of a hamster
A hamster cannot have reading skills, you idiot.
>"DURR IZ DIS A GEE OH MET TREE THREAD OR A PROGRAMMING THREAD U FAGET"
What is this shit? Do you need help or something?
>like the amerilard you are
What are you even on about? I'm an Aussie.
>when the post you responded to is clearly working with OpenGL
Why did he ask about fucking geometry then? He didn't ask about OpenGL.
>>
>>58986737
Geometry is Mathematics
Programming is Mathematics
Therefore, geometry is programming.
>>
File: 1486842465423.jpg (14KB, 147x252px) Image search: [Google]
1486842465423.jpg
14KB, 147x252px
>>58986875
>Why did he ask about fucking geometry then? He didn't ask about OpenGL.
the state of dpt, ladies and gentlewomen
>>
>>58986875
>I was merely pretending!
>>
>>58986880
Should have paid more attention in class.
>>58986882
DPT isn't a state. Fuck off with your leftist bullshit.
>>58986884
I don't see how this relates to my post.
>>
>>58986880
>Programming is Mathematics
This is incorrect, as a standalone statement.

Mathematics can be utilized in the pursuit of programming, but programming is not a subset of mathematics.

Geometry IS a subset of mathematics, in contrast.
>>
>>58986888
>>58986892
>what is Curry-Howard correspondence
>>
>>58986892
>applied mathematics is somehow not a subset of mathematics
incorrect.
>>
>>58986916
Programming is not merely applied mathematics.
>>
>>58986888
>DPT isn't a state.
this
/dpt/ is pure and immutable
>>
File: pascal2.png (129KB, 1064x846px) Image search: [Google]
pascal2.png
129KB, 1064x846px
Okay two days late but I finally finished my pascal's triangle generator. turns out I forgot to subtract ONE single bit. hnnnggg.
Anyway here it is, calculates and prints up to 65536 rows of the triangle while using less than 256kB of memory. No recursion, and without storing the previous rows.

Code >>>http://pastebin.com/UX4LaiC6

please rate, like, subscribe, etc.
>>
>>58986936
>please rate, like, subscribe, etc.
huh? what the hell is that supposed to mean? is this some new meme or what?
>>
>>58986950
downvoted
>>
>get offered Java traineeship
>costs me 7000 euro if i quit
>no experience with programming whatsoever
>bluff my way into the course because i "can't motivate myself at home and this will earn me quickest"
>get 2 week crash course on fundamentals
>information overload
>practice every day from morning till evening
>just starting to grasp the concepts
>just barely understand order of execution
>OCA exam in 3 days

I really fucked myself in the ass
>>
What is the biggest (single precision) normalized float when using the IEEE 754 standard?

Wikipedia and the notes of a classmate claim it is
(1−2^(−24)) × 2^128

But if I understood correctly, it should be
(2−2^(−24)) × 2^128

Am I doing it wrong?
It's 1+mantissa * 2^(exponent-127)
>>
>>58986979
Who are you quoting? I want to read the full list.
>>
John Carmack is a nigger thief who contributed nothing of value to computers. Name one important achievement of his, you can't.
>>
>>58987010
DOOM?
>>
>>58987017
Meme game
>>
>>58987023
you're a meme
>>
>>58987031
I wish
>>
>>58986979
Wait, so it's free if you pass and costs $7k if you fail?
>>
>>58987010
float Q_rsqrt( float number )
{
long i;
float x2, y;
const float threehalfs = 1.5F;

x2 = number * 0.5F;
y = number;
i = * ( long * ) &y; // evil floating point bit level hacking
i = 0x5f3759df - ( i >> 1 ); // what the fuck?
y = * ( float * ) &i;
y = y * ( threehalfs - ( x2 * y * y ) ); // 1st iteration
// y = y * ( threehalfs - ( x2 * y * y ) ); // 2nd iteration, this can be removed

return y;
}
>>
>>58987056
Meme algorithm never once used outside of quake 3.
>>
>>58987056
Carmack didn't write that.
>>
>>58987043
No i have to work for a partner company for one year to 'earn them their money back'
>>
>>58987023
>>58987031
>>58987065
Return to your shitty "website".
>>
>>58987077
That sounds like slavery.
>>
>>58987056
Not Carmack but some FX guy
>>
>>58987092
It is, but there's fuck else to do and i have debts up my ass
In the meantime i hope to create some apps
>>
>>58987081
>Defending a nigger
You have to go back
>>
File: 1365275590897.png (125KB, 256x256px) Image search: [Google]
1365275590897.png
125KB, 256x256px
>>58986982
Surely most CS students should be able to solve this?
I'm not one.
>>
>>58987113
I'm not defending you. Now back to your subreddit.
>>
>>58987130
>Carmack is a good boy, he dindu nuffin
Fuck off nigger
>>
File: benchmarks.png (217KB, 1698x944px) Image search: [Google]
benchmarks.png
217KB, 1698x944px
Discuss
>>
>>58987140
Where did I claim this, you fucking retard? Deport yourself back to your subreddit.
>>
Does anyone know a website where I can practise running time calculations? I have a test next week and can't find any useful sources.
>>
>>58987141
Are we supposed to discuss how the myriad of factors and optimizations likely missing from this data renders the chart to be useless?

Doesn't look too far off, though.

>Haskell
>>
>>58987149
You're defending carmack right now Jamal. He's a dumb nigger that deserves to rot in jail or worse. Carmack never contributed anything of value, he's a nobody and a psychopath
>>
File: 1434982245064.jpg (752KB, 3283x2188px) Image search: [Google]
1434982245064.jpg
752KB, 3283x2188px
I need some C++ OOP help, anons.

I have two classes: Manager and Specialist.
Manager creates and stores some Specialists, calls their methods.
Specialists also need to call some methods of the Manager.
To do that, I have to store a pointer to the Manager in all Specialists, which requires me to do one of two things: either forward declare Manager class, or include the Manager header.
The first one obviously doesn't work, because you can't call methods of a forward-declared class. The second one also doesn't work, because it can't compile due to circular includes (even though I have the #ifndef things in every header file).

What exactly am I doing wrong? Is my design completely wrong?
pls help.
>>
>>58986508
maybe because communism doesn't work
>>
What language fits this?

>I don't know enough about the subject, but I'd like it to be multi paradigm (oo and functional), have strong support for meta programming, and have it be both compiled and interpreted

>plus maybe rust style memory management

>cause I wouldn't want a garbage collector
>>
>>58987010
>>58987023
>>58987041
>>58987065
>>58987113
>>58987140
calm the fuck down Romero
>>
>>58987174
>He's a dumb nigger that deserves to rot in jail or worse. Carmack never contributed anything of value, he's a nobody and a psychopath
Where did I disagree with this, you literal plebbitor?
>>
>>58987187
Yes, but more importantly it's based on blatantly false premises. Much like POO.
>>
>>58987267
The fact you're arguing with me shows you're a literal nigger just like carmack.
>>
>>58987286
I didn't argue with you. I called you a plebbitor (which you are) for posting plebbit tier posts.
>>
>>58987301
>Nigger hates memes on a meme website
Stupid nigger jamal, you have to go back.
>>
>>58987311
You sound like an animal, are you sure you aren't a nigger yourself?
>>
File: 1486321063977.png (582KB, 1000x897px) Image search: [Google]
1486321063977.png
582KB, 1000x897px
>>58987284
>Yes, but more importantly it's based on blatantly false premises.
This is true.
Also communists need to be thrown out of helicopters desu.
>>
>>58987326
I'm not a retard like you, basketball american.
>>
>>58987186
The problem is that you're using OOP
>>
>>58987192
OCaml?
>>
>>58987340
>Ancap thinks he'll be spared in day of the rope
>>
>>58987340
>Also communists need to be thrown out of helicopters desu.
Expand this to just leftists in general.
>>
>>58987357
Is that a question?
>>
>>58987367
>national socialists think there's going to be a day of the rope
Why?
Nobody supports you people.

>>58987372
>Expand this to just leftists in general.
True.
>>
>>58986542
By extending the compiler to read sexp and at compile time. You can pretty much build any language using forth as the base to get an interactive version.
So you could have something like this:
: sloop sexp[ (let loop ((i 0)) (if (= 10 i) i (loop (+ i 1)))) ;

where sexp[ starts the lisp reduction mode and reads until ; The reduction stage just looks up the procedure in a lisp dictionary and transforms it into valid forth after it's reached primitives

>>58986567
yes but not in the same way as with forth you get to compiler compiling lisp interactively along forth
>>
>>58987387
Whites are waking up and bring redpilled.
>>
>>58987382
Yes?
>>
>>58987357
Has garbage collection.

>>58987192
Wait until Blow publishes his meme.
>>
>>58987346
You're welcome to suggest an alternative that will work for a relatively sizeable and complicated project. It's not like I'm a big fan of OOP, but I'm pretty sure there aren't many options aside from it.
>>
>>58987192
Forth
>>
>>58987424
>You're welcome to suggest an alternative
Literally anything which is not OOP.
>but I'm pretty sure there aren't many options aside from it.
You may not be a "fan" of it but you certainly spout the typical OOP fag delusions.
>>
>>58987450
What's the best book? I think I'll learn it after lisp.
>>
>>58987481
Starting forth is great for a beginner tutorial and jonesforth is the next step (literate forth source in asm and forth).
>>
>>58987458
You haven't said anything of value yet as well.
You either try to help, or go shitpost somewhere else.
>>
>>58987497
>You haven't said anything of value yet as well.
Read my first sentence then. Or has POO degraded your ability to comprehend even basic English?
>>
File: 1394063593526.png (154KB, 330x327px) Image search: [Google]
1394063593526.png
154KB, 330x327px
>>58986982
>>58987123
 (2−2^(−23))×2^127
>>
Hey guys, what's the go-to online resource for learning Haskmeme these days? Still Learn you a Haskmeme or is there something new?
>>
>>58987192
Garbage Collection is only ever really necessary in highly concurrent / multicore problem domains anyway fuck Nixon end the war
>>
>>58987529
G-grandpa?
>>
>>58987507
My whole project is heavily OOP. My whole programming life is OOP. If I was to rewrite it in C, I'd still be handwriting my own bad implementation of OOP.
So please, tell me what options I have, because googling programming paradigms isn't something that will set me on the right path right now.
>>
>>58987528
I never liked Learn You A Haskell, hate that overly cutesy bullshit.
I cut my teeth on Real World Haskell and now I'm earning 5 figures per decade making me one of the top 10% most paid Haskell programmers.
>>
File: 1459487588767.jpg (78KB, 340x314px) Image search: [Google]
1459487588767.jpg
78KB, 340x314px
>>58987559
>I'm earning 5 figures per decade making me one of the top 10% most paid Haskell programmers.
>>
>>58987559
I didn't know you could earn money from writing memeskell fizzbuzz
>>
char* A= new char[1]
unsigned char a = 11;
A[0] = a;
ofstream X(path, ios::binary);
X.write(A, 1);
X.close();


why does A[0] change if i load the file i just created
>>
>>58987571
Those figures could be in base 16, bro
>>
>>58987554
But it will.... learn scheme and you'll see why oop sucks and learn a heck load more about oop since you make your own in scheme
>>
>>58987554
>My whole project is heavily OOP.
So?
>My whole programming life is OOP.
That's your own fault. I'm sure you realize that.
>If I was to rewrite it in C, I'd still be handwriting my own bad implementation of OOP.
So you are incapable of thinking in a different way? I think it might be a little too late to fix you at this point.
>So please, tell me what options I have
Anything which allows for procedural code. which is a lot of languages, sepples included.
>>
Can someone tell me how do I get this almost SQL code to work? I wan't to know the percentage from my Total I'm paying in Taxes.

SELECT
sum(t.value) AS ValueTotal,
sum(t.tax) AS TaxTotal,
sum((100*TaxTotal)/ValueTotal) AS TaxPerc --Here is what I don't know what to do
FROM
tbl_t t
>>
>>58987614
You can't re-use those.

SUM((100 * SUM(t.tax)) / SUM(t.value)) AS TaxPerc
>>
>>58987494
Starting Forth is a solid text for getting the hang of things, and the last few chapters start to hint at what Forth's real timeless aspects are
Thinking Forth is something truly special. I've read it through three times now, and every time I've come away with something new to think on.
>>
File: 1463511282169.png (500KB, 897x897px) Image search: [Google]
1463511282169.png
500KB, 897x897px
>>58987614
>paying taxes
>>
>>58987645
Hey Anom, ty for your answer but it's still not working.
>>
>>58987690
What do you mean by "not working"?
>>
File: hostname.png (3KB, 453x61px) Image search: [Google]
hostname.png
3KB, 453x61px
Just winapi my shit up senpai
>>
>>58987705
I get this error:
Server: Msg 130, Level 15, 
Cannot perform an aggregate function on an expression containing an aggregate or a subquery.
>>
>>58987424
FP
>>
>>58987528
the wikibook
>>
>>58987743
>just make it functional, bro, it's a silver bullet and won't cause any maintainability issues
>>
>>58987614
>>58987690
Not pretty, but could just wrap it in another SELECT:

SELECT ValueTotal, TaxTotal, (100*TaxTotal)/ValueTotal AS TaxPerc
FROM --your query
>>
>>58987673
Well sadly I have to pay some of them.
>>
>>58987758
FP is more maintainable than OOP
>>
Is it possible to write an OS in a functional language?
How do people get anything done without inline asm?
>>
>>58987758
He is a retard. FP doesn't necessarily mean non-OOP.
Anything procedural is fine and is by definition easier to maintain than POO garbage.
>>58987769
>imperative is more maintainable than procedural
Huh?
>>
>>58987790
>He is a retard. FP doesn't necessarily mean non-OOP.
OOP doesn't function
>>
>>58987790
Are you trying to tell me that I'm allowed to use functional programming combined with procedural programming with some object-oriented elements?
>>
>>58987827
That's illegal in my country.
>>
>>58987816
Yes, in that sense it's definitely true.
>>58987827
>Are you trying to tell me that I'm allowed to use functional programming combined with procedural programming
This doesn't make sense. Function programming can either be procedural or object-oriented.
You're allowed to use anything procedural. It being functional or imperative is entirely up to you.
>Are you trying to tell me that I'm allowed to use POO
No. It should be avoided at all costs.
>>
>>58987844
You can program in a procedural manner while also utilizing OO design patterns.
>>
>>58987874
OO design patterns are all about shoehorning inheritance into every problem

You wouldn't use OO design patterns if you weren't doing OOP, because you could simply use natural and obvious solutions
>>
>professor is so shit at explaining things I learned much more by listening to some random indian on youtube
>>
>>58987762
That's what I'm supposed to do?
SELECT ValueTotal, TaxTotal, (100*TaxTotal)/ValueTotal AS TaxPerc
FROM (SELECT sum(t.value) AS ValueTotal, sum(t.tax) AS TaxTotal FROM tbl_t t)
>>
>>58987874
Anything using garbage is not clean anymore. Sure, you can pollute everything with your bullshit, but why even escape it in the first place then?
>OO """"design patterns""""
Reddit might be a more appropriate place for you.
>>
>>58986414
>C++ it is actually pretty good
lmao this fucking retard
>>
>>58987879
What is OOP?
>>
>>58987929
Something which hasn't been tried yet.
>>
>>58987929
Object oriented programming
>>
>>58987923
RAII is the best though
>>
>>58987940
>>58987960
How does it differ from other programming styles?

It's mutually exclusive to functional and procedural programming?

What are some examples of how you'd tackle the same issue with these paradigms?
>>
Recommend a Java textbook for someone who already has some experience with the language.
>>
>>58987971
If you were dealing with something that corresponds very closely to real world objects, e.g. the physical elements of a simulation, you might use OOP.

For everything else, FP or Procedural.
>>
>>58987996
isbn 978-0321958327
>>
>>58987996
https://www.amazon.com/dp/3867877920
>>
>>58988022
>you might use OOP
No, don't listen to this anon.
>>
File: 1485288496464.png (7KB, 224x225px) Image search: [Google]
1485288496464.png
7KB, 224x225px
>>58988026
>>58988030
s-stop it you guys
>>
>>58988045
To be fair, in that case you are literally programming objects, so a language which already has those built in (probably written in an actually good language like OCaml) would be useful
>>
>>58987192
F#
who cares about GC, this isn't the 2000s anymore
>>
>>58987971
>It's mutually exclusive to functional and procedural programming?
OOP and procedural are mutually exclusive. FP can be either of those two things.
>>58988022
>For everything else, FP or Procedural
You do realize that this basically says "procedural FP or procedural imperative", right?
>you might use OOP
How can someone type this and not think that he's retarded?
>>
>>58987528
haskellbook
http://haskellbook.com/
>>
>>58988064
I'm sorry, but you must be confused, redditor.

Never ever recommend usage of objects or OOP here.
>>
OOP is like lego blocks

it isn't really programming
>>
>>58988118
>OOP is like lego blocks
Except lego blocks are actually good.
>>
>>58987719
sounds like visual studio being shitty to me
>>
>>58988135
not when you step on them
>>
>i can't do it so it's not really -meme

you're just mad because you can't oop you fucking scrubs
>>
Doing systems programming, I like to use RAII to modify global state, eg.
class disable_interrupts
{
static std::atomic<int> n { };
disable_interrupts() { asm("cli"); ++n; }
~disable_interrupts() { if(--n == 0) asm("sti"); }
}

void f()
{
disable_interrupts please { };
do_things();
}

Is this considered good practice? Any better ways to do the same thing?
>>
>>58988160
>OOP
deprecated
http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.99.8567&rep=rep1&type=pdf
>>
>>58987528
why would you want to learn haskell aside from the novelty factor?

I'm asking as a guy that knows a tiny bit of haskell.
>>
>>58988178
state monad
>>
>>58988203
it's a great language
>>
>>58988160
>that plebbit usage of "meme"
Remove yourself from this thread.
>>58988190
This assumes there was a point in time in which it wasn't "deprecated" and that's wrong. It was always garbage and will always remain as such.
>>
>>58988203
Because the abstractions available allows for cleaner and error free code
>>
>>58987887
that's pretty much my compsci major in a nutshell

I do feel like I'm dumber than everyone else in my classes though
>>
>>58988178
>class
>Is this considered good practice?
No.
>>
>>58988205
a free monad might be better

>>58988178
in C++ it's as good as it gets, at least until lambda syntax becomes not-obnoxious


no_interrupt([&](){ ... });
>>
>>58983400
why are you using 2 terminals to compile and run, instead of 1 terminal with "g++ $flags $target.cpp && ./$target"
why would you manually position 2 terminals instead of using tmux or something
why don't you set up makefiles so you aren't repeatedly doing the same thing
>>
>>58988226
Same. I just tell myself that I'm just better at other things so that I don't lie awake every night wondering if I'm not secretly retarded and wasting years of my life on something I enjoy but suck at.
>>
>>58988220
>complaining about wrong usage of meme -meme

you're just mad because you can't meme
>>
>>58988256
don't worry man

it only gets worse
>>
>>58988260
Remove yourself from this thread.
>>
>>58988256
This is normal.

These feelings go away once you get a job and become good at what you do.
>>
>>58988294
>Rememe yourself from this thread.
>>
>>58988241
>lambda
You mean like this?
template<typename F>
void disable_interrupts(F&& f)
{
static std::atomic<int> n { };
asm("cli"); ++n;
f();
if(--n == 0) asm("sti");
}

void g()
{
disable_interrupts([&]()
{
do_things();
});
}

Or maybe a hybrid:
class disable_interrupts
{
static std::atomic<int> n { };
disable_interrupts() { asm("cli"); ++n; }
~disable_interrupts() { if(--n == 0) asm("sti"); }
}

template<typename T, typename F>
auto do_with(T&&, F&& f) { return f(); }

void g()
{
do_with(disable_interrupts { }, [&]()
{
do_things();
});
}
>>
>>58988420
the first
>>
should I learn Rust?
>>
>>58988512
No
>>
>>58988512
only if you want to learn a domain-specific language with concepts that don't carry over to other languages because they're pointlessly restrictive and stupid

someone here is actually calling rust a 'retard filter' because it makes programming more difficult
>>
>>58988512
Yes
>>
>>58988512
Give it a couple of weekends, get an idea of how it does things different, then shelf it for at least 9 more months.
>>
>>58988420
what happens when do_things throws in the first?
>>
>>58988512
are you too stupid to decide for yourself? just try it and make your own judgement.
>>
>>58988512
Maybe
>>
>>58988512
Can you repeat the question?
>>
>>58988512
99% sure you won't learn Rust
>>
>>58988637
should I learn Rust?
>>
>>58988589
Good point. You'd have to wrap f() in a try block there and duplicate the last line in the catch before rethrowing.
I guess RAII is the way to go then? Sure seems like the nicest option here.
>>
>>58988712
Yes
>>
>>58988712
Give it a couple of weekends, get an idea of how it does things different, then shelf it for at least 9 more months.
>>
>Python's find() returns the index of an input word's first character
Do I have to use regex to differentiate between two words that start with "b" or can I do that with find()? All of the SO answers seem to be jerking off about how good find() is but I'm not seeing it for my needs.
>>
>>58988712
Maybe
>>
>>58988836
>Python's
stopped reading right there.
>>
>>58988836
You'd have to pass the start argument of the last found pos to offset find() call if you want to find subsequent indice.

>>58988719
Yep, that's also the reason why things like std::lock_guard exist in the standard, they use the RAII to make prevent exceptions from creating dead locks and such.
>>
>>58988712
No.
>>
>>58988888
Welp.
>>
>>58988712
Can you repeat the question?
>>
>>58988836
>needs
Stopped reading here
>>
>>58988888

checked
>>
>>58988836
why don't you test it and find out
>>
>>58988886
Eeesh. Thanks.
>>
>>58988888
rust unequivocally BTFO'd
>>
>>58988886
>indice
gesundheit
>>
File: 1341619539905.jpg (107KB, 613x533px) Image search: [Google]
1341619539905.jpg
107KB, 613x533px
>2017
>Needing the preprocessor to make constants, because you're type system is [spoiler] awful [/spoiler]
>>
>>58988932
ich sprache deutsche nicht
>>
>>58988946
You have to go back.
>>
// Clean up the streams.
reader.Close();
dataStream.Close();
response.Close();
>>
>>58988963
If each of those implemented the Closable interface then you could dynamically abstract bean close them all with ease
>>
>>58988994
>Closable
IDisposable


And they do. The author of that tidbit is just retarded.
>>
i only have one more bug in program that i'm aware of
>>
>>58986356
>What are you working on /g/?
building a library to run a hd44780 display with 3 wires and a 74hc595 shift register on a attiny13.
Maybe later moving up to attiny85, because muh 8 megaherz.

pic related. bottom left is just a shift-in register for testing purposes
>>
>>58989032
>that i'm aware of
>>
>>58988241
Theyre not going to change the lambda syntax just cause you don't like it.
>>
What would combining Haskell's typeclass and HKT's and OCaml's objects and row polymorphism look like?
>>
>>58989082
>objects
stopped reading right there.
>>
could you guys program if you had like 6 people around you talking? unfortunately my desk isn't in a very good location for programmng
>>
File: IMG_0111.jpg (446KB, 2500x1667px) Image search: [Google]
IMG_0111.jpg
446KB, 2500x1667px
>>58989035
nice, forgot pic.
>>
>>58989067
i would like to be able to "overload {}" so that you can do this

myFunction(3, "hello") {

}
>>
>>58989090
Are you too dumb to realize that both headphones and earplugs exist?
>>
>>58989067
>>58989097
or even if
{}

just automatically passed a lambda
>>
>>58989097
So add even more ways to do the exact same thing?
There'd be no point. And lambdas already come with zero overhead if the type is templated.
If you want pretty syntax go use Ruby. C++ is not about making things pretty
>>
File: 412365134123.png (88KB, 652x765px) Image search: [Google]
412365134123.png
88KB, 652x765px
how do i do number 4? c++
>>
>>58989125
>C++ is not about making things pretty
that much is obvious
if i wanted pretty syntax i'd use haskell
>i do
>>
>>58989132
int plater = (rand() % 2) ? 1 : 2;
>>
/g/ents, what's considered the best approach to configure and build depending subprojects?

> Consider the following
> Project A depending on dep1 and dep2
> all 3 projects have their own git repo
> Add deps as submodules into A's repo
> Someone checks out A
> make A (now runs configure and make on subprojects)
>>
>>58989125
>C++ is not about making things pretty
What is it good for then?
>It's not readable/pretty
>Bloated to all hell
>All the useful libraries are wrapped into other (better) languages
???
>>
File: 1487182103894.jpg (11KB, 480x360px) Image search: [Google]
1487182103894.jpg
11KB, 480x360px
>>58989268
>What is it good for then?
Absolutely nothing
>>
>>58989268
Something something game development.
>>
>>58989268
>What is it good for then?

Knowing C++ or Haskell, you can feel smug about calling people with jobs "code monkeys".
>>
>>58989132
>>58989156

I would do it like this instead:

int plater = (rand() & 1) ? 2 : 1;

Same thing, but no modulo. The compiler probably optimizes it away anyway, so it probably doesn't matter.
>>
>>58989352
or you know...
int player = rand() & 1;
>>
>>58989329
I think that falls into #3, but c++ is just ubiquitous for that for some reason.
>>
>>58989342
>Knowing C++
this by definition makes you a code monkey though
>>
noob here, working on SICP, how does one think recursively?

(define (A x y)
(cond ((= y 0) 0)
((= x 0) (* 2 y))
((= y 1) 2)
(else (A (- x 1) (A x (- y 1))))))


I mean, Jeez. After one level of trying to think through this procedure, my brain starts hurting.
>>
>>58989364
that would be (rand() & 1) + 1

not as readable as (rand() & 1) ? 2 : 1 imo
>>
>>58989490
Your opinion is frankly, retarded.
>>
>>58989502
fuck off retard. the second one conveys the intent (a bit) more clearly. it's a clear cut selection between two possible outcomes. the first one is just a math expression.
>>

char* global = new char[50000000];
void foo(){
char* temp = global;
global = NULL;
global = new char[bigger];
//put temp and some other data into new global
delete[] temp;
}


why would my program crash at delete[] temp
>>
>>58989532
is this what they're teaching you in class?
lmao
>>
>>58989542
kill yourself stupid arrogant kid
>>
>>58989532
The best is (rand() % 2) + 1. Anyone who can't read that is in highschool.
>>
>>58989467
try it on paper
>>
>>58989565
not an argument.
>>
File: money wayward.jpg (120KB, 392x445px) Image search: [Google]
money wayward.jpg
120KB, 392x445px
>>58989544
i'm not the one paying 50k to learn C++
>>
>>58989570
this. I don't think there is a better way to understand recursion.
>>
this thread is cancer. i only came here to post a new thread with a derp pepe slapping an anime girl with a fly swatter to trigger you spergs
>>
>>58986356
Any good resource link for the explanation of MVC? I have just begin with Ruby on Rails.
>>
>>58989156
>>58989352
>>58989364
>>58989502
>>58989565
>>58989542

You're all retards.

std::mt19937 gen((std::random_device())());
std::uniform_int_distribution<int> dist(1, 2);

int first_player = dist(gen);
>>
>>58989620
So concise
>>
>>58989650
So not archaic
>>
>>58989575
How's this. One is generic that gets used ad nausium all over the place to get numbers in a specified range. All you need to give it is a range and a starting value. The other (yours) is only useful for one case.
>>
>>58989619
https://youtu.be/wV9tcIQTqsE
>>
>>58989687
you can do e.g. (rand() % 3) ? 2 : 1 if you want a 2/3 chance. fucking retard.
>>
>>58989687
and if you want different ranges you would make a function for it, not hard-code (rand() % 2) + 1 etc everywhere
>>
>>58989132
plz dont argue over my seatwork. tnx for the answers
>>
>>58989752
>>58989730
Retarded for not using <random>
>>
>>58989132
>pop one or two balloons (1 balloon left)
>>
Please don't use srand()/rand() in real C++ software.
>>
anyway i'm not going to waste my time on this asinine shit thread. not today at least. i'm closing this tab so no need for the (You)s

>>58989773
the debate was which of (rand() & 1) + 1 or (rand() & 1) ? 2 : 1 was more readable for selecting between 1 and 2 randomly
>>
>>58989540
Because you're not using shared_ptrs like a good boy.
>>
>>58989792
this. only tolerable for babby's first learning exercises
>>
>>58989793
This debate is invalid in the context of C++
>>
>rusts solution for handling multiple connections concurrently is 'spawn a thread per connection'

how the fuck does anyone take this language seriously
>>
I have a stupid question:
What is the difference between:
if (x=5)
and
if (x==5)
?
>>
>>58989831
Like a full thread? Or a coroutine?
>>
>>58989835
What language?
>>
>>58989835
>>58989848
I releaized I forgot to mention language.
C
>>
>>58989835
Single = is assignment, while two is testing equality.
>>
>>58989730
Nice ad hominem, sperg. Anyway, that's not relevant to the problem statement.
>>
>>58989835
>make x equal to 5; if 5 is nonzero, then
>if x is equal to 5, then
>>
>>58989863
>>58989872
Ah so x=5 would enter the if?
>>
>>58989853
A single = will assign and then return what you assigned to, e.g. (x = 5) sets x to 5 and returns x

== will compare for equality (what you want)
>>
>>58989847
they dont even have coroutines built into the language
>>
I am a programming noob in the grand scheme of things. I have learned c++ and did some small trivial projects in it. Now I'm starting to learn web programming (html, css, js so far). Is it normal that I absolutely hate it? It's boring as fuck
>>
>>58990001
I feel you, after I am doing some webshit work I crave to go back to writing some C (right now writing a network application) and doing some assembly (ARM 64 bit) webdev is just too repetitive and dull
>>
>>58990001
yes
>>
>>58990001
Learn how to use OpenGL with C++ and make a game
>>
>>58990001
>>58990032
>>58990055
>>58990078
>seriously discussing that garbage here
>>>/r/eddit
>>
File: 1487069710482.png (340KB, 640x720px) Image search: [Google]
1487069710482.png
340KB, 640x720px
Hey anons. I'm having a strange problem while learning python.

I have an two instances of a "box" class, and each box instance has a list that has references to other box instances.

So first on box_a I add a reference to box_b, and then on box_b I add a reference to box_a. But when I check the references inside box_a, it shows [box_b, box_a]. What am I doing wrong? Why did adding a box_a reference to box_b also add a box_a reference to box_a?
>>
>>58990119
Sorry, we'll be sure to only talk about manly SQL crap from now on boss.
>>
>>58990119
>why do you speak programming on a programming thread
why do you feel the need to make yourself look stupid?
>>58990144
you're not wearing enough cute girl clothes
>>
>>58990144
class Box:
def __init__(self, name):
self.boxes = []
self.name = name

def add_box(self, b):
self.boxes.append(b)

def get_boxes(self):
return self.boxes

def __repr__(self):
return self.name

boxA = Box('a')
boxB = Box('b')
boxA.add_box(boxB)
boxB.add_box(boxA)

print(boxA.boxes)
print(boxB.boxes)

werks for me
>>
>>58987192
common lisp since it allows for optimization through meta object protocols
also, clos is god tier
>>
>>58989467
use debugger faggot
>>
File: mid_DSC07236_rot.jpg (258KB, 675x900px) Image search: [Google]
mid_DSC07236_rot.jpg
258KB, 675x900px
>>58986508
>le "gommunism is bad mmmmkay" meem
Stop.
>>
File: bernie.jpg (280KB, 1180x842px) Image search: [Google]
bernie.jpg
280KB, 1180x842px
>>58990355
>>
>>58990355
>le
>meem
>communism isn't garbage
Deport yourself back to your home.
>>>/r/ibbit
>>
>>58990460
>muh communism bogeyman
>muh reddit bogeyman
Just stop posting already, anon.
>>
File: bc6.jpg (30KB, 500x375px) Image search: [Google]
bc6.jpg
30KB, 500x375px
Can we have a thread without anime picture now, please?
>>
>>58990268
I think I figured it out after looking at your code. I was declaring the lists inside the class but out of __init__, so it was treating it as a global class variable.

This is stupid. Thanks anon.
>>
>>58990522
No. You're on an anime website.
>>
New thread:
>>58990531
>>58990531
>>58990531
>>
>>58990516
>muh
>communism isn't garbage
You just confirmed my suspicion that you are straight from reddit and I don't want reddit stink nearby. Fuck off.
>>
>>58989502
ITT: snot-nosed brats who think cond * (foo - bar) + bar is more readable than cond ? foo : bar

this general is such contrarian literally trolling/retarded cancer
Thread posts: 313
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.