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

/dpt/ - Daily Programming Thread


Thread replies: 350
Thread images: 16

File: CPlusPlus.jpg (36KB, 433x455px) Image search: [Google] [Yandex] [Bing]
CPlusPlus.jpg
36KB, 433x455px
Don't be a cunt edition.

What are you working on /g/?
>>
systemd
>>
whoops. here's the old thread.
>>51843675
>>
average 2 ints edition
>>
School stuff. 2nd year of college in France.
Working on an algorithm that recommend game to people based on information i have in the database
>>
>tfw don't know how to learn C
>>
>>51848113
Just malloc everything and you'll be good to go
>>
>>51848106
This is what OP meant about don't be a cunt.
>>
Friendly reminder that you're not a programmer if you don't know C. Please go to /wdg/.
If you can't average 2 ints in C, you don't know C.
>>
>>51848119
How do I learn C? I have been trying to learn it but I'm frustrated by the simple problem of averaging two integers. It makes me think I'm a retard.
>>
File: 1429882928190.jpg (130KB, 383x472px) Image search: [Google] [Yandex] [Bing]
1429882928190.jpg
130KB, 383x472px
reposting from the late other thread

what's the fucking point of setters and getters if they pretty much do the same thing as just using a public variable

none of this encapsulation shit makes sense, at the end of the day you're still accessing the variable and its contents, you're just adding a layer of useless redundancy, anyone who wants to access it can still access it they just need to write a different line to get to it

the only reason I can think of for using getters and setter is if you're attributing or getting the values from a kind of data that you don't necessarily know how you'll get and what kind of data it will be and it needs to be manipulated before using or storing it (and I still don't see why you cant just use a method that converts that), and in a team project where you can't trust retards to do shit right

yet I'm reading and looking at stuff and literally everyone uses it everywhere even for mundane shit

please tell me what am I missing before I go insane
>>
File: beyond-fizzbuzz.jpg (33KB, 381x499px) Image search: [Google] [Yandex] [Bing]
beyond-fizzbuzz.jpg
33KB, 381x499px
>tfw started the "average 2 ints" meme
>tfw going strong on its own now
pic related: the original pic posted with the challenge
>>
>>51848121
Test program:
#include <stdio.h>

int main() {

unsigned char curravg = 0;
unsigned char incavg = 0;

for(unsigned i = 0;i< 256;i++) {
for(unsigned j = 0;j < 256;j++) {
printf("(%d, %d) -> %d = %d\n", i, j, (i>>1) + (j>>1) + (i & j & 1), curravg);
if(incavg) curravg++;
incavg = ~incavg & 1;
}
curravg = (i+1) >> 1;
incavg = (i+1)&2 >> 1;
}

return 0;
}


runner:
#!/bin/bash
gcc ./test.c -o ./test
./test > test.txt
cat test.txt | cut -d" " -f 4- | sort -u > srt.txt | wc -l


the runner should output 255 if my averager works right (and you named the source file test.c).
>>
>>51848054
learning java ee
>>
>>51848122

People are taught to use setters and getters for everything because schools all teach java and java faggots think it's applicable to every use case.
The only valid use for setter and getter is when you need to validate their input or do some other function before setting the value.

If you see setters and getters everywhere, it's the mark of the codemonkey who has no fucking idea what he's doing.
>>
>>51848173
undefined behavior
>>
>>51848192
where?
>>
>>51848170
what is the solution and why
we must know
>>
>>51848149
>makes me think I'm a retard
that's reality
>>
>>51848208
where you call printf with the wrong arguments
>>
File: what's the matter.png (117KB, 465x421px) Image search: [Google] [Yandex] [Bing]
what's the matter.png
117KB, 465x421px
avg 2 ints
double avg(int a, int b)
{
return (double) a / b;
}
>>
>>51848243
nice catch i totally missed that.
>>
https://benchmarksgame.alioth.debian.org/u64q/rust.html
>>
>>51848212
the solution involves branching to check which side of 0 the numbers are; all the solutions that don't involve branching are wrong (at least until now)
>>
>>51848162
I can understand a "get" if you'd like a variable to be read-only, or a "set" if there's some sort of overhead behind the scenes. Are either of these examples wrong?
>>
>>51848258
>>51848243
>>51848173
Also the thing should put out 256 ...
if your remove
> src.txt
>>
>>51848284
So you were actually so shit at C you didn't realize that was never necessary. Got it.
>>
Is it bad practice to use unsigned for everything that doesn't need to be negative?

>inb4 size_t
that's an unsigned long long on most systems.
>>
>>51848162
Say you have a date struct. If you try to set the day of the month to 34, that shouldn't be possible, so the setter sets it to the max for the month you're setting it to (like 29 for february, maybe).
>>
>>51848306
>that was never necessary
sure was
>>
>>51848301
Getters and setters allow providing a stable API regardless of what future changes might come to the underlying access code. That's why most well-established C libraries have getSomethingSomething, getSomethingSomethingEx, getSomethingSomethingEx2, etc. whereas you just need the get and set in sane languages.
>>
>>51848306
>I don't know what I'm talking about
>I only write CSS
anon, pls...
>>
>>51848252
Uh.... right. So you're saying the average of 4 and 0 is undefined?
>>
>>51848306
>thinks he can average 2 ints
this ain't memejs, fgt
>>
>>51848309
Just use int and size_t (for sizes of things). Don't complicate your life.
>>
I'm thinking of implementing either ext2 or FAT for my OS. Does anyone who has done OS programming or FS programming before have an opinion on either of these two?
>>
>>51848343
I like how it's so easy to track you across threads. At least you're easily filterable.
Filtered.
>>
>>51848345
undefined? it's obviously infinity
>>
>>51848369
0/10
>>
>>51848375
>this mad
>pretending
m8...
>>
>>51848375
>easy to track
>easily filterable
u2
>>
>>51848397
I don't get it.
>>
>>51848375
>pls, anon, stop raping me
>started php last month
>don't know this c stuff
>your big dick is really hurting me
REKT
E
K
T
>>
>>51848434
That's because you're retarded.
>>
>>51848301
>>51848317
>>51848184

For stuff like this I can understand, but then again (and this might be because of my inexperiene) it seems to me like these kinds of fuck ups can simply be avoided by proper design, something that's probably lost the larger the project and the more people working on it in which case it makes sense in those cases, but I see it literally everywhere which I don't understand

is it just a fucking overvalued and overpreached habit that people keep because it seemingly seems harmless? (and I say this because I can imagine a clusterfuck of gets and sets cluttering the code and fucking shit up the same way not using them would do anyways)
>>
char *c = (char) malloc(sizeof(char));
>>
>>51848436
That's not how you use greentext, anon-chan. Greentext is when you quote someone else than yourself!
>>
(a / 2) + (b / 2) + (a & b & 1);
>>
how to be productive programming
>1. echo "0.0.0.0 4chan.org" >> /etc/hosts
>2. ???
>3. profit
>>
>>51848457
Gee, thanks. Now let's try this again. What the hell is 0/10 have anything to do with an honest non-baiting question.
>>
>>51848475
>backpedaling
>damage control
umad?
>>
>>51848485
b8/8
>>
>>51848471
why
>>
>>51848476
doesnt work :^)))))))))))
i love average ints maymays
im bait 24/7 365/my life
dream in code one day youll figure how to do it
>>
>>51848476
ebin maymay but it doesn't compile
>>
>>51848491
Would you like me to show the source of the OS I am planning on using either fat or ext2 in? Would that suffice for your addled brain to understand that someone can actually have a question and not be a cunt around here?
>>
>>51848506
are you me?
>>
Rewriting the slowlaris kernel in scala
it's not slow enough
>>
>>51848520
>baiting this hard
sá Žmh tá Žbh fá Žam
>>
>>51848467
Sounds like you're actually sane and should avoid the circus of underachievers who program OOP.
>>
>>51848520
Not even trying anymore.
>>
File: Shipping.png (25KB, 460x238px) Image search: [Google] [Yandex] [Bing]
Shipping.png
25KB, 460x238px
Well shit
>>
>>51848520
implement LEAN instead of fat or ext2, it'll be simpler.
>>
>>51848467
What "proper design"? The only solution to these problems by definition is setters/getters. You are beyond inexperienced, you're also retarded.
>>
>>51848567
>cá Žucked by bjarne
>>
>>51848333
>That's why most well-established C libraries have getSomethingSomething, getSomethingSomethingEx, getSomethingSomethingEx2, etc.
That's literally just WinAPI, and it's Microsoft's fault for being so horrid at programming
>>
>>51848567
>C++
>>
>>51848589
It's literally any large library that has been around for more than a couple of years.
>>
>>51848567
why read books when there's documentation and stackexchange?
>>
>>51848589
Well, how does POSIX do it?
>>
>>51848602
Show me.
>>
learn C or C++?
>>
>>51848567

Are you new to programming?
>>
>>51848603
Because I find I learn better from books
>>
>>51848467
getters and setters are pretty much pointless
any getter/setter that does more than just get/set the value is considered weird, so the point of "encapsulating" things is lost
seriously, if you want proper encapsulation to avoid invariances caused by state use proper methods to operate on the state.
>>
>>51848630
Mostly
>>
>>51848567

wait $0.01?
>>
>>51848641
They put the real price in the shipping, was like 5 bucks
>>
>>51848611
Go is the best systems programming language. It's new and everyone loves it. C and C+ are outdated and unsafe.
>>
>>51848581
as in, if a number larger than 31 is getting into your calendar day data struct, you're already fucking up and getters and setters are a bandaid to your fuck up
>>
>>51848118
#include <stdlib.h>
#include <limits.h>
int main(void) {
for(int i = 0; i < INT_MAX; ++i) {
malloc(i);
}
}


Am I a programmer now?
>>
>>51848054
usb device stack
wow usb spec is fucking poorly written
keeps crashing my pdf reader too
>>
>>51848649

Still why did you get such an old edition?
>>
>>51848650
go isn't a real systems language.
>>
>>51848581
>The only solution to these problems by definition is setters/getters
Nope, refinement types (and dependent types in general) are better.
>>
>>51848662
Yup
Just do that for every program so that you can take full advantage of memory
>>
>>51848662
He said everything, you faggot! Why do you stop? Back to your html "programming"!
>>
>>51848553
>>51848548
Y'all are asshats.
>>
>>51848569
>It's common that you want to expose a field publically, but don't want it to be mutable publically
final
if you want to perform a copy, fine

> but you want to have a chance to sanitise any new values
this shouldn't be a setter, but a proper method with a descriptive name about what actually happens
>>
>>51848689
ok dad

#include <stdlib.h>
#include <limits.h>
int main(void) {
for(unsigned long long int i = 0; i < ULLONG_MAX; ++i) {
malloc(i);
}
return 0;
}

is this better?
>>
>>51848633
>>51848122
>what's the fucking point of setters and getters if they pretty much do the same thing as just using a public variable
It's common that you want to expose a field publically, but don't want it to be mutable publically. That's an obvious use case for getters.

It's also common that you want a public field to be settable publically, but you want to have a chance to sanitise any new values, or you want to run some code every time the value is set.

Honestly this is really obvious stuff. If you looks at how getters and setters are used in the standard libraries you'll notice this.
>>
>>51848691
>faking screenshots on /g/
are you this desperate?
>>
File: C++1.jpg (54KB, 940x264px) Image search: [Google] [Yandex] [Bing]
C++1.jpg
54KB, 940x264px
>>51848678
4th edition is 20 dollars
>>
>>51848576
Thanks I'll look into it.
>>
>>51848609
https://www.hdfgroup.org/HDF5/doc/RM/RM_H5D.html
your turn.
>>
>>51848698
Not really.
>>
>>51848698
#include <stdlib.h>
#include <limits.h>
int main(void)
{
int i = 10000;

for(; ;)
{
malloc(i);
}

return 0;
}


fixed
>>
>>51848685
>Nope, refinement types (and dependent types in general) are better.
Could you clarify that a bit (preferrably with a code example)? Doesn't seem like those would help at all. I am a novice in type theory.
>>
>>51848691
How good of a programmer you need to be to create an operating systems?
>>
>>51848654
Without a getter/setter to prevent a 31 to get into your data structure, the only way for your data structure to capture a value at runtime is telepathy, and BMI-based telepathy doesn't exist yet.
>>>/out/
>>
>>51848711

There's the 5th edition as well, no? But anyway, if you can't afford just pirate it. I'm sure they'll understand.
>>
>>51848703
see
>>51848697
also, if you want to perform a copy, i wouldn't call the method "getX" either
getters and setters are implied to be cheap, if they do anything else, you should not call them getters and setters anymore, but something else that makes the caller aware that it isn't essentially cheap
>>
>>51848707
Yeah I'm so desparate i'm also going to show a faked profile on neetcode with around 60 commits over the past three month's that I've purposefully made just to pretend i made an os.

http://neetco.de/ZenosCave/BamfOS
>>
>>51848735
Good enough to know how to average 2 ints in C.
>>
>>51848697
>final
then you can't mutate it internally. For example, the Count field of an ArrayList is good to have a setter for. It's a field that changes internally, and you want it to be publically accessible so the number of items is known publicly, but you don't want it editable publically.

>this shouldn't be a setter, but a proper method with a descriptive name about what actually happens
like "setMuhFeild(newVal)"?
>>
>>51848685
Neither can perform turing-complete compile-time operations. You're retarded.
>>
>>51848733
>>51848723

How about now?
#include <stdlib.h>
#include <limits.h>
int main(void) {
volatile unsigned long long int i = 0;
a:
malloc(i);
++i;
goto a;
}
>>
>>51848747
I'm sorry there's only ~50 commits. I lied. I truly regret baiting you.
>>
>>51848742
How am I supposed to pirate a physical book?
>>
>>51848735
Not even as good as you need to be to graduate college.
>>
>>51848735
I'm shit at it and I somehow managed to get this far.
>>
>>51848774

Pirate an ebook.
>>
>>51848760
nice meme
int average = low + ((high - low) / 2);
>>
>>51848762
Don't bother, they have no idea what they're talking about since they never graduated from fizzbuzz programming.
>>
>>51848788
>call it a meme
>can't do it
are you this dumb?
>>
>>51848762
>then you can't mutate it internally
yeah, i guess there is atleast some point in using a getter but not a setter
>setMuhFeild(newVal)
again, if your method does something other than setting a field, call it something else
or do you call all your methods "setX"?
>>
>>51848779
So, it is mostly just implementing specs?
>>
>>51848734
Say you had a field that had to be constrained to the unsigned integers less than 100. That would actually be a pair, with the second value being a proof of that fact. However, the proof is "irrelevant", so it doesn't require any storage.
(x : uint, x < 100)

In order to set "x", you need to also provide the proof that it's less than 100. You can get this either from using a compile-time value or by doing a check, once (what the Java setter would ALWAYS have to do).

>>51848763
>dependent types can't perform turing-complete compile-time operations
Types don't "perform" anything, and moreover I don't see what this has to do with Java getters/setters.
>>
>>51848785
I can't hold an ebook, and an ebook takes up space on my monitor
>>
Pop quiz. How does this declaration differ between C and Java?

float array[10][20][30];
>>
>>51848790
>graduated from fizzbuzz
Nice accomplishments there, faggot!
>>
>>51848803
i'm not even going to argue with you. check mergesort implementations from anyone and that's exactly what you are going to find, weeb.
>>
>>51848790
the only languages that use getters/setters for almost everything are java/c#.
i guess every single other language is used for fizzbuzz only.
>>
>>51848825
In Java that declares a multidimensional array, while in C it just declares a pointer that's planned to take a massive amount of memory to store.
>>
>>51848810
>i guess there is atleast some point in using a getter
I'm halfway there so
>call it something else
Like what? All it does as for as external code is concerned is set the field. Any other code that runs in an implementation detail. Why would I call it something like "sanatiseAndSetX(val)" when external code doesn't need to know if I'm sanitizing anything or not. Public methods and fields should only describe what external code needs to know, not implementation details.
>>
>>51848823
use a tablet
>>
>>51848832
>called out on being a retard that can't average 2 ints
>talks about mergesort
/g/ everyone
>>
>>51848872
I'd rather have a book
>>
>>51848841
Every language except your precious C uses getters and setters extensively.
>>
I have just install Visual Studio 2015 to start learning C++

Wish me luck /dpt/
>>
>>51848844
>in C it just declares a pointer that's planned to take a massive amount of memory to store.
nope. it declares a 3 dimensional array of floats
>>
>>51848844
you're an idiot
>>51848825
it doesn't compile in java
>>
>>51848895
Good luck anon. God speed.

Installing VS atm funny enough
>>
I had a dream last night, /dpt/.

I dreamed that I woke up in my spotlessly clean apartment overlooking Lake Champlain. I made myself a cup of coffee with just the right amount of sugar, and gazed idly out my wall-sized window at the beautiful scenes of nature below.
And then I went and sat down at my marble-colored computer, pristine in its composition, with a perfectly configured Linux installation booting up at my command. And I, coffee cup in one hand and future in the other, started working on pet projects written in the Qt Framework on text editors with dark backgrounds.


Then I woke up and cried that this dream will never come true.

Help me, /g/. Help me make my dreams come true. Is it even possible to make money from sitting in your home programming anymore? Do I really have to go get a degree I can't afford in the hopes of being able to buy it all back later?
>>
>>51848825
I've wiped all knowledge of Java from my mind
>>
File: 1435613166906.jpg (13KB, 222x216px) Image search: [Google] [Yandex] [Bing]
1435613166906.jpg
13KB, 222x216px
>>51848054
my project finally works.
>>
>>51848734
>>51848822
Oh, and something else you could do with the dependent type approach is manipulate proofs (purely at compile time, of course) so that you don't have to do any redundant checks.

Like say you had a proof of (x < 50). You can then turn that into a proof that (x+50 < 100), or that (-x > -50), if you need it. So you could do a single check as soon as a value is input from a file or terminal or whatever and then just manipulate it along with the value itself, saving time.
>>
>>51848875
"mid = low + (high - low) / 2
Even though this is mathematically equivalent to the above, it is not susceptible to overflow. "
- http://rosettacode.org/wiki/Binary_search

ok kid, whatever you believe
>>
>>51848832
>check mergesort implementations
Those implementations don't implement a function that averages 2 ints.
>>
>>51848896
There's no such thing as arrays in C, anon, it's all just pointers represented slightly differently.

You failed your own quiz.
>>
>>51848844
I'd rather not call an array-of-arrays-of-arrays a "multidimensional array". It is technically a tree.

But you're right. The Java version declares triply nested arrays, while the C version declares a contiguous block of memory in row-major order.
>>
File: mt-stupid.png (43KB, 613x481px) Image search: [Google] [Yandex] [Bing]
mt-stupid.png
43KB, 613x481px
>>51848947
>There's no such thing as arrays in C
>>
>>51848944
not mergesort but binary search, sorry.
>>
>>51848822
I see. Thanks for the explanation.
>>
>>51848959
That's exactly spot-on, that's a classic mount stupid situation.
>>
>>51848942
>>51848960
binary search works with indices, you fucking faggot
we're talking ints here
pro tip: they can be negative, you inbred web monkey
>>
>>51848947
Guess there's no such thing as while loops either since those are just if and goto statements represented differently
>>
>>51848947
OP is a different anon. and arrays are more than pointers
>>
>>51848990
there's no such things as functions and types either
>>
>>51848990
There's no such thing as ifs, just arrays of instruction pointers.
>>
>>51848889
well, good luck finding that extensive use (especially to the degree that java and c# do it) in python, go, haskell, lisp, javascript or most other languages
>>
>>51848990
Actually If and Goto are both just syntactic sugar for JMP and JEQ.
>>
>>51849000
How can you have an array of instruction pointers if there aren't any arrays?
>>
>>51848982
ok kid. you have been defeated, just give up baiting.
>>
>>51848993
>arrays are more than pointers
>ints are more than floats
>functions are more than enums
>strings are more than keywords
>>
>>51849006
They all literally do, in particular lisp where it's absolutely everywhere, but they all do anyway. As expected, you know exactly nothing.
>>
>>51849010
If is just a null-terminated pointer pointer.
>>
>>51848982
>>binary search works with indices
not necessarily. std::binary_search gets iterators for example
>>
>>51849010
How can our loops be real if our i's aren't real?
>>
>>51849017
>got told
>damage control
REKT
E
K
T
>>
>>51848947
>There's no such thing as arrays in C
just....
                                                                                                                                                                                                                                      stop
>>
>>51849040
faggot in suicide watch :^)
continue calling damage control on me when you are the one doing it.
>>
>>51849032
>std::
not valid c
>>
File: 1436709932389.png (138KB, 566x528px) Image search: [Google] [Yandex] [Bing]
1436709932389.png
138KB, 566x528px
So i booted my raspi into ring 0 and tried to run a kernel i wrote for it but i'm pretty sure i just killed my board.

it won't boot anymore, i don't even. I think i accidentally overwrote some memory i wasn't supposed to.
>>
>>51848054
Thread safe resizable hash map and solution to the prisoners hats problem

[spoiler]In Java[/spoiler]
>>
>>51848467
Put it this way. You will have genetically fucked up indivduals that will use your code in their own programs. If you give them access to the internal working of your software, they can fuck up the assumptions you have made about the data that is in your modules.

For example, say you write a game engine for a FPS games. Some /v/ tard comes along and says "I want to make gamz!" They see your awesome and easy game library that you have published online for free and start to use it.

Now say you have abstracted 3D vectors in your engine, but have the internal data public to use for that inbred /v/ tard. They, being retarded, will start fucking with that internal data, which renders any assumptions you can make about the internal data in your 3D vectors *useless* because it will have been tampered with by external modules, that may break the assumptions you originally place upon it. An example might be that you have a class that outputs the vector for the motion of a bullet. If that vector would be tampered with before it renders, you can bet your shit that the /v/ tard is going to be coming your way, spamming retarded shit like "Ur fukin engine suks m8!!!1! fix ur shit!" Now this wasn't really your fault (provided the engine implementation was actually correct obviously), it was theirs because they didn't understand how it works.

tl;dr - Setters and Getters provide a clean interface to avoid tampering of internal data, so that you can be sure that any fuck ups lie within that module, and makes your life easier. It also allows you to abstract some details for you, so that when you go to use whatever module you have, you don't need to worry so much about the smaller details.
>>
>>51849066
>Thread safe
>Java

*yawn*
>>
>tfw no idea what to program
>>
>>51848107
Hey I am doing a visualisation recommendations based on Amazon shopping patterns, we should team up.

>>51849080
This is don't be a cunt edition.
>>
>>51849049
>I don't know the difference between signed and unsigned numbers
just say so, csscá Žuck; signed are the ones that can be negative; I'll dumb it down more: the negative ones have a small dash in front of them
>>
I gave up with programming C++

Seriously, fuck this, my brain can't process this.
>>
File: 2015-12-14_00-49-40.png (14KB, 634x322px) Image search: [Google] [Yandex] [Bing]
2015-12-14_00-49-40.png
14KB, 634x322px
gonna use this object for some analytics in the future
>>
>>51849087
It was supposed to be, but like everything else here, it was ruined.
>>
>>51849094
>no one talks about difference about unsigned/signed
>>I don't know the difference between signed and unsigned numbers
calling damage control :^)
>>
>>51848942
HTML cá Žucks actually believe this!
>>
>>51848982
It should work regardless of sign. If you replace "high" and "low" with x and y, you still get
(x + y) / 2
= (2x - x + y) / 2
= x + (y - x) / 2

Notice this doesn't require the signs of x or y to be anything particular
>>
>>51849134
>confronted with proof
>still continues to attempt baiting
:^)
>>
>>51849129
>doesn't know ints are signed
>thinks unsigned average applies to signed numbers
hahahahaha
backpedaling in 3... 2... 1...
>>
C allows for conditional compilation based on macro constants. Various compilers add macro constants to include information about the target platform, but this is not part of the C standard, and not included in any standard headers. Other information may not included as a macro constant, such as whether or not a system uses 1's compliment, 2's compliment, or some other means of representing signed integers. In C++, this could be calculated using a constant expression; however, the results of constant expressions cannot be used to determine conditional compilation using the #ifdef blocks. Instead, one would need to feed that value into a template, resulting in an even uglier mess.

Would not an ideal systems programming language, whose purpose is for systems programming and nothing else (so we don't need to bother making it "functional" or whatever else is hip these days), have a wholly unified macro system, that would enable easy conditional compilation based on the results of constant expressions, and with any factor that could lead to "undefined behavior" defined as a constant by the language?
>>
>>51849150
>'ints are signed'

holy shit
how is one person this retarded
>>
Anyone ever play with HFT Algos?

I want to get into it, seems like a good hobby (I like programming and I like making money) but how much of groundwork do I need to do in Finance to understand how to start?

Is it just bollinger bands and away I go? Or should I be learning a lot more than that?
>>
>>51849151
You more or less just described how preprocessing works in .NET languages. The problem is that operating systems built around .NET are kinda shitcrap so there's not much future there.
>>
>>51849166
>doesn't know int is signed
the classic, unfortunately not rare, /g/ tard
>>
>>51849150
>>51849147
>>
>>51849151
>so we don't need to bother making it "functional" or whatever else is hip these days
Pure functional with a strong, expressive type system (dependent, linear) is ideal for systems programming, though. And with a dependently typed language, you basically don't need a macro system since you can run arbitrary code at compile time.
>>
>>51849188
int main() {
unsigned int i = -1;
return i;
}


friendly reminder that you're an idiot
>>
>>51849205
>using the word unsigned
>int is not enough
gee, I wonder why...
>>
>>51849198
>And with a dependently typed language, you basically don't need a macro system since you can run arbitrary code at compile time.
*and the code can "show up" in the types.
>>
>>51849198
>>51849182
kernel written in F# when
>>
>>51849166
friendo, 'int' is the same of 'signed int'
>>
>>51849219
>Pure functional with a strong, expressive type system (dependent, linear)
>F#
>>
>>51849182

The problem is that .NET languages aren't systems programming languages.

>>51849198

>Pure functional
>Systems programming
Systems programming by its own nature requires a fuckload of explicit mutating of state.
>>
>>51849205
Are you trying to prove that 2's complement still works in modern computers?

Or are you just dumb and didn't know two's complement and its properties?
>>
>>51849230
still a better systems language than Go
>>
I haven't coded in a long time. Looking into doing some Linux programming, but don't know how to GUI. Am I looking at qt things now or is there something I can get going quicker.

I don't think going back to JFormDesinger would be the thing to do.
>>
>>51849142
>It should work
It doesn't work for the same reason (x + y) / 2 doesn't work: overflow.
>>
>>51849234
That's why I mentioned linear types: they admit mutation and side effects in general in pure functions. They just have to be quantified (made explicit, as you said) by type.
>>
Working on a computer vision assignment with OpenCV.
Last assignment was 3D voxel reconstruction from multiple videos. This one builds on that with clustering and labeling different persons in the videos and then tracking them.

Pretty neat stuff.
>>
>>51849252
ok, overflow it. :^)
"Even though this is mathematically equivalent to the above, it is not susceptible to overflow. "
>>
>>51849237
just dumb
>>
>>51849250
Qt is damn fine and the most programmer-friendly framework out there.
Your other options are GTK+ which is a clusterfuck, GTK# which is bloated and slow, and Tcl/Tk which is really nice if you don't want to program in a Clike language.
>>
>>51849252
Sorry, you're right.
>>
>>51849234
>>51849256
Mutation of memory pointed to, at least. Variables are still immutable, as they should be.
>>
>>51849270
>Tcl/Tk

I spent a year working the postgresql (8.2 if I recall) code so this might be my ticket.

Thanks.
>>
>>51849234
How would you average two ints in C, ruby
>>
>>51849270
from what I've seen of Qt (which isn't much) I don't really like the fact that literally everything is a qSomething.
Seems like a massive pain to integrate it into an existing project.
>>
>>51849292
>>51849252
samefag
>>
>>51849264
INT_MAX and -1, you fucking donkey
you need it dumbed down:
low + (high - low) / 2 == -1 + (INT_MAX - (-1)) / 2 == -1 + (INT_MAX + 1) / 2
INT_MAX + 1 is the overflow, subhuman filth
>>
>>51849304
Well yeah you really can't 'integrate' Qt into anything.
The entire point of why Qt is so yummy is because it completely replaces the C++ standard libraries with the Qt Framework libraries, for thousands of reasons that require a case-by-case examination to really understand why, but overall it means that the code is in general safer and easier to write.
>>
>>51849295
>Variables are still immutable, as they should be.
I hate this bullshit. Immutability is great, but sometimes problems are much easier to solve with a small bit of mutation then when forcing everything to be pure. Especially when performance is a consideration.

Immutability should be encouraged, but mutation is useful sometimes.
>>
>>51849324
It's too bad I don't have a tripcode for you. If that was really samefagging then I would say that it wasn't me, unless you want to say that it was samefagging from the very beginning
>>
>>51849325
Actually anything greater than or equal to (INT_MAX / 2 + 1) will overflow it.
>>
File: 1433698243654.png (29KB, 613x556px) Image search: [Google] [Yandex] [Bing]
1433698243654.png
29KB, 613x556px
Do you guys even find programming fun?

After 5 years of school and now work programming feels like a complete dreadful activity in my day.
>>
>>51849352
Yeah but I don't work as a programmer so that's probably why.

Also I only program in F# and Haskell so idk.
>>
>>51849337
I'm talking about variables in a purely mathematical sense.

If you wanted to do something like in C where a variable is defined to be a bit of memory on the stack, you use alloca, and then you can mutate that memory.
>>
>>51849352
I do
feels good 1st year of CS
>>
(srs) how to I go from some noob that just took one c++ class to someone who can actually do some useful programming? where do I start? do I learn another language?
>>
>>51849352
It's not my job, so I program whatever I want, in what I want, using what I want, how I want. So yeah.
>>
>>51849352
school is just tedious work and work can be a tedious as well or fun depending on the job.

You need to find a fun side project otherwise youw ill continue to hate it.
>>
Serious question:

How good do you have to be at math to program well?

I'm not retarded, I just never took Maths further than 16 in education.
>>
>>51849337
>>51849373
Like, if you look at something like LLVM, it requires SSA for variables, which means no mutation. That's what allows it to do a good job of register allocation and reuse. If you want a "variable", as in a piece of memory that is mutable, you use alloca.
>>
>>51849352
Yeah, might help that my job is working with my favorite language (Java). If you're made to work in a language you don't like, you're gonna have a bad time.
>>
Why won't this work?

#include <iostream>
#include <windows.h>

int main()
{
using namespace std;

HKEY hkey;
DWORD key_type = REG_SZ;
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, TEXT("\\HARDWARE\\DESCRIPTION\\System\\BIOS\\CentralProcessor\\0"), 0, KEY_QUERY_VALUE, &hkey) == ERROR_SUCCESS)
{
cout << RegQueryValueEx(hkey, TEXT("ProcessorNameString"), NULL, &key_type, NULL, NULL) << endl;
MessageBox(NULL, "Successful", "Success!", MB_OK);
}
else
{
MessageBox(NULL, "Cannot open the registry.", "Error", MB_OK);
}

RegCloseKey(hkey);


return 0;
}
>>
>>51849373
>I'm talking about variables in a purely mathematical sense.
i can see that, which is dumb for a general purpose language.

>If you wanted to do something like in C where a variable is defined to be a bit of memory on the stack, you use alloca, and then you can mutate that memory.
Or just use a typed mutable variable which is way more convenient.
>>
>>51849415
>>51849376
>>51849373
>>51849365
>>51849352
>Hating programming
How is this possible
you picked this profession, moralitykeks
>>
>>51849433
>tfw there are no common lisp jobs around my area
>>
>>51849437
I wasn't aware that convenience was more important than performance and safety in a systems language.
>>
>>51848942
>>51849325
rekt hard!
>>
>>51849439
start liking X
love doing X
X starts getting annoying/boring because of Y
eventually you hate X because of Y

I used to love sports until it got competitive then i hated it because people were so serious. Fortunately I simply quit doing them.

The same can't easily be said for someone who did it was a profession and now hates it.
>>
>>51848735
you don't have to be good
just autistic
>>
File: huc1.gif (789KB, 500x375px) Image search: [Google] [Yandex] [Bing]
huc1.gif
789KB, 500x375px
>>51849433
>favorite language (Java)
>>
/g/ pls

Best place to learn Java to program apps for android from?

I want to make an app that injects terminal autism into the blood stream. Then I'll learn about iKek and make apps for those faggots.
>>
>>51849459
>I wasn't aware that convenience
it doesn't affect performance or safety at all. Infact it improves it by making it safer and easier to do mutation when it is useful.
>>
>>51849264
You got BTFO pretty mercilessly, anon. How are you gonna save face after this >>51849325?
>>
>>51849491
$20/hr internship in Java at a major tech company. The "java a shit" meme needs to die
>>
>>51849494
Don't bother with Java, use C#. there's way to get it to work on androids.
>>
>>51849435
I would think you need to connect to the registry somehow first. Windows (strangely, although correctly) treats the registry as a file. You might have to tell it what registry it is connecting to.

This is coming from no windows C programming experience.
>>
>>51849352
Imperative/job programming? Fuck no. Functional programming? Fuck yes. I went into research because I didn't like "job programming", dodging the bullet.
>>
>>51849509
>i get paid a lot, so the language must be good
You must think Cobal is fucking amazing,

I don't doubt the market demand for Java programmers.
>>
>>51849494
Join the official Android Dev IRC channel.
It's on the Freenode network, channel name is #android-dev
I idle there quite a bit, tell me what name you'll be using and I'll look for you if you want some pointers.
>>
>>51849508
i got btfo mercilessly
please teach me how to average 2 int my friend
>>
>>51849509
>>51849433
POO
IN
LOO
>$20/hr
Must feel like royalty if your previous home was on a DESIGNATED SHITTING STREET.
>>
>>51849518
>I would think you need to connect to the registry somehow first

But I did.

I try to open the registry first.

When I check to see what error code it gives me it's:
ERROR_BAD_PATHNAME

161 (0xA1)

The specified path is invalid.


What do?
>>
>>51849439
CS is to programming what math is to calculators.
>>
>>51849538
I'm American and white, bro
>>
>Java
>>
>>51849521
research seems like such a drag though.

>ho you gotta write papers and get published
>ho you gotta get funding
>ho you need papers for more funding
>>
>>51849506
>it doesn't affect performance or safety at all.
I said here >>51849426 that immutable variables allow the compiler to do better optimization. You certainly lose safety from allowing mutation of variables, since once a variable becomes mutable the compiler can't use it in static verification (proofs dependent on that variable are invalidated).
>>
>>51849551
>INDIA
>IS
>WHITE!
>>
>>51849546
check UAC. You will probably have to run this code as admin.

inb4 replies about windoze
>>
>>51849535
I'll use BenisBoy, thanks anon, will be on in a few (helping senpai with something)

>>51849515
I've never programmed before, are you sure it won't be too difficult to find resources for programming and uploading an app to the store in C#?
>>
>>51849565
But it's F U N if it's in an interesting area like ML. If you're stuck and forced into investigating one model within one framework until you find something without being allowed to explore on your own (such as some master's students are stuck with) it will suck, but otherwise it's a lot of fun and extremely interesting.
>>
File: 1448388062479.jpg (91KB, 1437x908px) Image search: [Google] [Yandex] [Bing]
1448388062479.jpg
91KB, 1437x908px
>there are people in this thread right now that have jobs and wageslave
>>
>>51849567
I'm not talking about immutable variable, i'm talking about as an alternative to directly allocation and manipulating memory on the stack. How well do you think compilers optimise that shit? In this case mutable variables are better.
>>
>>51849577
Just use Java. It will be easier to get started. You also have to pay to use C# for Android dev.
>>
>>51849302

Well, since the topic of discussion seems to be a concern about integer overflow, I would take advantage of a mathematical property:

(x+y)/2 = (x/2) + (y/2)

By dividing both sides by two first (and the compiler will optimize this to a bitshift), we avoid an overflow. The only problem this leaves us is we'd be off by 1 if both sides are odd (i.e. (3/2) + (3/2) = 2). This is easily solvable by simply adding a few modulo 2 operations (again, optimized by the compiler).

int avg(int x, int y)
{
return (x/2) + (y/2) + (((x%2) + (y%2)) / 2);
}


But that's just how I'd solve it intuitively. I think I liked that solution from a couple threads back involving bitwise and/xor.
>>
>>51849576
>check UAC. You will probably have to run this code as admin.

I did. Still won't work.

smdh

I'm trying to make a meme that will check the user's cpu against a list and if it's contained in the list it will le mine memecoins
>>
>>51849536
I'm afraid you aren't capable of understanding anyway if you thought subtraction can't overflow. You didn't even know why the method used in binary search doesn't apply to the average of two ints: you didn't know that ints are signed while array indices are unsigned.
How can you be explained something like averaging 2 ints when you don't grasp basic C concepts?
Maybe you should just give up now and be just a web developer.
>>
>>51849594
Well, if this fits your definition of "mutable variable" then I agree with you. But it's the same thing as simply shadowing an immutable variable, since you aren't making any assumptions about how it's stored.
let x = 10
let x = x + 20 // different variable
>>
>>51849337
>>51849594

In a language with immutable variables, you can still pretend you have mutation, and just recurse with a new value for your "new state", and if it's a simple enough case, it'll have similar performance. This provides better safety than simply using mutable variables, since it will be obvious in the type, e.g. the function will have to have the state as an input, and include the new state in its outputs. Admittedly though, I have had bugs from passing in the wrong state to the recursion, but this was partially because of bad naming ("s" for old state, "s'" for new state).

If you do need mutation (e.g. because it would be unacceptably slow to emulate it), and you want the result to be usable in otherwise pure computations, Haskell (for example) has ST, which is a sort of trapdoor lets you create mutable variables that work in a particular context. But once you go back up to pure code, you can't use those cells anymore. This has the effect of making the computation observably pure, and has equivalent semantics to if you had just faked state.

The downside of this is that converting to the mutable representation (and converting back too, for complicated-enough structures) will be O(n). So it might not be worth it if your immutable a-bit-less-efficient solution would still be sub-O(n).

If you are working in the IO portion of your code, then you can use IORef or another mutable cell type, because it doesn't matter if you can use it from pure code.

In Haskell, I would never explicitly allocate something as a pointer, unless I needed to pass something to C code.

Rust will give you mutable variables if you absolutely want them, though, if the linear types really aren't good enough for what you're doing
>>
>>51849621
>Well, if this fits your definition of "mutable variable" then I agree with you.
How the fuck is that a mutable variable? Do you understand what the term means?
>>
>>51849620
i prefer not to, thanks for the suggestion.
>>
>>51849616
Ruby can you help me out here with winapi shit senpai?

>>51849435
>>51849546
>>
>>51849616
>how I'd solve it intuitively
It would be wrong: doesn't work for -1 and 2 for example.
>involving bitwise and/xor
Most likely also wrong: bitwise operations don't mix well with negative numbers.
>>
>>51849644
It's not. But simply talking about reassignment is the same as creating a new immutable variable and shadowing. If you're talking about writing over the backing storage of a variable, that's something different entirely, and should be done by explicitly referring to stack space.
>>
>>51849607
Figured, thanks. Looking to make simple games at first that I can go back and add content to/remove certain things, streamline, etc.

>>51849535
[19:28] == #android-dev Cannot join channel (+r) - you need to be identified with services

Now what. Sorry anon, I'm JUST- a kouhai when it comes to this. Senpai pls.
>>
>>51849645
Time to flip burgers then.
>>
>>51849669
>weeb words

leave, this is not the place for you
>>
>>51849666
>If you're talking about writing over the backing storage of a variable, that's something different entirely
No, that's exactly what mutation is. Hiding variables by creating new variables with the same name certainly fucking isn't mutation.

How do you create a publically visible field in an object that changes over time, and represent that somehow without changing the actual value of the variable?
>>
>>51849715
>shitposting unironically
>doesn't know /g/ filters
>thinks /g/ is not for weebs
>>>/b/
Suicide is always an option anon :^)
>>
>>51849709
This seems very familiar from some threads ago, but clarifying: it is nice to being called out on my bullshit because now I want to actually learn C. well, inb4 "save face"
>>
>>51849718
That's not a variable, that's a field. And it's done either by mutating the object's storage if you allocated the object in memory, or by creating a new version of the immutable object (which of course, can be optimized to use the original storage if you don't need it again).

You need to learn the difference between "variable" and "memory".
>>
>>51849616
>the compiler will optimize this to a bitshift
It can't. Division of signed numbers will most likely have different semantics in C than in your platform's machine language.
>>
>>51849663

I have never dicked around with the registry before, but I'll see what I can do. What sorts of errors/return codes are you getting?

>>51849664

Fuck, you're right. I'll have to think a little on this.
>>
Is there like a good intermediate C programming book or something?
>>
What kind of interesting stuff can be done with C++ aside from over-complicated math problems?
>>
>>51849766
>I have never dicked around with the registry before, but I'll see what I can do. What sorts of errors/return codes are you getting?

The one in post i linked.

161, aka filepath invalid
>>
>>51849749

>it can't
Find the div instruction

avg:
.seh_endprologue
movl %ecx, %eax
movl %edx, %r9d
shrl $31, %eax
shrl $31, %r9d
leal (%rcx,%rax), %r8d
andl $1, %r8d
subl %eax, %r8d
movl %r8d, %eax
leal (%rdx,%r9), %r8d
addl %r9d, %edx
sarl %edx
andl $1, %r8d
subl %r9d, %r8d
addl %eax, %r8d
movl %r8d, %eax
shrl $31, %eax
addl %r8d, %eax
sarl %eax
movl %eax, %r8d
movl %ecx, %eax
shrl $31, %eax
addl %eax, %ecx
sarl %ecx
addl %ecx, %edx
leal (%r8,%rdx), %eax
ret
.seh_endproc
>>
>>51849787
>AT&T
I need my eyes, ya know?
>>
>>51849771
>What kind of interesting stuff can be done with C++ aside from over-complicated math problems?

Silent bitcoin miner, botnet, aimbot for fps games, crypter
>>
>>51849766
>>51849784
Also getting errorcode 2(file not found) when I remove the \\ from the beginning of key path.
>>
>>51849771
AI for different board games, like Checkers, Chess, Hex and Go etc.
>>
>>51849770
I looked for one for so long anon, with no luck. People recommend books that are either "tips and tricks" kinds of books that either a) have really obvious tips and tricks (i.e. Expert C, orange with the blue fish) or b) have really stupid illogical tips (i.e. 21st Century C)

Your best bet is to just embark on a big project in C. You'll learn more than you could from those books.

One better book is Data Structures, Algorithms, and Software Principles in C. Books like those teach you, of course, data structures and algorithms, which are appropriate if you just finished your first introductory C book.
>>
What kind of monitor do you guys program on?
>>
>>51849718
>>51849748
And besides, encapsulation is unnecessary when you have refinement/dependent types. With the latter, you don't have to hide implementation details in order to prevent the user from putting an object in an invalid state, and so an object simply becomes a simple data type (structure/union).
>>
>>51849849
my based rMBP screen
>>
>>51849840
That shit's usually done in python (with bindings to C libraries) because this speeds up development time significantly without impacting runtime much.
M O N T E
O
N
T
E

C A R L O
A
R
L
O

T R E E
R
E
E

S E A R C H
E
A
R
C
H
>>
>>51849787
You said "a bitshift", not "shitload of instructions of which some are bitshifts". All I said is that it can't do it with one bitshift.
>>
Which programming book should I get for learning C? I have almost no experience with anything else.
>>
>>51849872
C Programming: A Modern Approach
>>
>>51849858
That would only be true if dependent types included unresolvable types, which is not the case, therefore you're full of shit, as usual from one of you fizzbuzz "master" programmers.
>>
>>51849881
>That would only be true if dependent types included some term I just made up out of thin air
Nice one mate.
>>
>>51849577
Im the anon offering to help, you planning on connecting any time soon?
>>
>>51849866
That is completely incorrect. All the top Hex and Go bots (i.e. those that use UCT and RAVE) are in C++ or C.
>>
>>51849871
>backpedaling this hard
>>
>>51849898
>reading comprehension
>>
>>51849895
0/10
>>
>>51849784

After peering around in my own registry, I think perhaps you don't need the "BIOS" part.
>>
>>51849616
>dividing both sides by two first (and the compiler will optimize this to a bitshift)
can't be done
>>
>>51849914
Are you for real? If you are so sure you can provide counterexamples, can't you?
>>
>>51849920
>After peering around in my own registry, I think perhaps you don't need the "BIOS" part.

Oh shit yeah I was looking at another path and mixed it up by accident.

It opens the key but still doesn't work tbqh. Why won't it output the value to console?
only outputs 0
>>
>>51849718
Represent all state changes as functions that take a state and return a new state along with whatever result value you wanted. This is the approach taken in Haskell, and in simple cases you can just use a function like that raw.

For more complicated cases there is State, which will plumb around the state for you. But the important thing is that it is fairly painless, and you can't make the mistake of mixing it with code that's not supposed to have mutation (without it being a compile error).

>>51849858
You still might want to hide data so the user doesn't rely on details that might change (and thus force you to increase major version more often, if you are using semantic versioning). Also, if you have a complex data structure (finger trees? immutable efficient catenable queues? maybe even simple red-black trees), it could be very painful to encode all the invariants and create proof objects for all of them, when the structures themselves may already be twisty to implement.

And also, if your structure includes any components that are only usually interacted with in input/output (anything there isn't a real semantics for), then the properties you want might not be expressible at all.
>>
>>51849616
>will optimize this to a bitshift
>a bitshift
>>51849787
>50 lines of instructions
>a bitshift
m8...
>>
>>51848284
>the solution involves branching to check which side of 0 the numbers are
There is more than one solution though. Here is a solution that DOESN'T rely upon "undefined behavior". The resulting assembly is shit.
int avg(int a, int b)
{
if ((a < 0 && b > 0) || (a > 0 && b < 0))
return (a+b)/2;
else
return a/2 + b/2 + (a%2 + b%2)/2;
}

Yeah I know I could simply to bitwise shit, but that "implementation defined". C kiddies are such keks.
>>
>>51849891
Already there m8, registered as BenisBoy, waiting for ya.
>>
>>51849996
>solution involves branching
>shows solution with branching
no shit
>>
>>51849880
Thanks. Hope I'll get less ignorant about this language soon.
>>
>>51849961
>Represent all state changes as functions that take a state and return a new state along with whatever result value you wanted.
And that's appropriate for a systems language? Why not just have the mutable variable? It's the same thing in the end. Making complicated work arounds for doing things that are easy most most other languages is why Haskell leaves such a bad taste in so many people's mouths. I understand this makes things *safer* in haskell, but the real world benefits of making it slightly less likely to get a bug related to state in a specific area of code is hardly worth making it *SO* painful to do anything with mutation.
>>
>>51849961
Yes, I should have said specifically "encapsulation at the object level", because I was still thinking in terms of the argument that getters/setters with logic to preserve invariants are not appropriate for a systems language. Encapsulation using modules is still incredibly useful.
>>
>>51850024
It's pretty simple as far as languages go. I'd recommend checking out Understand and Using C Pointers as well when you get to learning about pointers
>>
What can I use haskell for that I can't use C for? What can I do more easily in haskell than I can in C?
>>
>>51849866

Chess is NP-Hard. Why would you do that in anything other than C or C++?

>>51849871

Well then Mr. Pedant, you're right. It's two bitshifts and an add. Still not that fucking big compared to an actual div instruction, the point I was trying to make.

div2:
.seh_endprologue
movl %ecx, %eax
shrl $31, %eax
addl %ecx, %eax
sarl %eax
ret
.seh_endproc
>>
>>51850029
I think you're missing the point.

If you want to have a bit of memory than you can modify, allocate it. Let the variables remain immutable and retain the better register usage and ability to be used in dependent types.

>>51850046
>What can I use haskell for that I can't use C for?
Nothing. They're both Turing-complete.

>What can I do more easily in haskell than I can in C?
Most things. Haskell is especially good for writing parsers, compilers, etc.
>>
>>51850072
How's the OS going?
>>
>>51850072
>Chess is NP-Hard.
A bit more than that bud. In fact it is EXPTIME.
>>
>>51850072
>Mr. Pedant
When I'm right I'm a pedant? I was telling you 1) your solution is incorrect; 2) signed division by 2 is not as cheap as unsigned one. Both of which are true. No need to get defensive.
>>
NEW THREAD

>>51850125
>>
>>51850089
>If you want to have a bit of memory than you can modify, allocate it.
but WHHHHYY?? You keep saying this, but why is this better than having a mutable variable? Directly allocating memory isn't type safe, so how it this better than a mutable variable? If a language you used supported mutable variables, would you still allocate and alter memory directly instead of using them?
>>
>>51850138
>Directly allocating memory isn't type safe
Sure it can be. With dependent and linear types you can have pointer capabilities, which prevent issues like using memory after it's been freed or read/write hazards across multiple threads.
>>
>>51848567
>purchasing a dated edition
You should watch cppcon 2015 and you'll understand why that's a terrible idea
>>
>>51850172
Isn't it still going to give me structure with which to learn C++ and programming in general?
>>
>>51848650
C++11 and greater is type safe though if you know how to write modern sepples. Exciting things are happening in the sepples world
>>
>>51850189
Buying language books for rapidly depreciated language standards is a bad idea.

Why do you think the original book on C is still published and bought today?
>>
>>51850094

Well, I just started winter break, so I haven't gotten back around to it. That said, I've had quite a bit of perspective change thanks to my OS internals class. I'm debating upon whether I want to keep developing a 32-bit OS for the old-ass computer I've got sitting in my living room, or try for a 64-bit OS and run it in QEMU...

>>51850111

You're not a pedant for informing me my solution is incorrect.
You're a pedant for jumping at my usage of "a" bitshift when the point was that it's not going to be nearly as expensive as an actual div instruction.

[whydontallboardshavespoilertags]We're all pedants when we're right[/whydontallboardshavespoilertags]
>>
>>51850138
A toy exaple to prove that it is trival to use mutable variables in haskell:
a :: IORef Int 
a = unsafePerformIO (newIORef 2)

-- prints:
-- 2
-- 5
ioRefTest :: IO ()
ioRefTest = do
a1 <- readIORef a
print a1
writeIORef a 5
a2 <- readIORef a
print a2

IOref Int can be loosely read "a pointer to an int," and we are can create them with newIORef and mutate the value with writeIORef. People dont often use them because its not needed.
>>
>>51850296
ruby please help with the registry thing

;-;
>>
>>51850285
But I apparently need to learn C++ for designing games
>>
>>51850017
This is the closest I've gotten to branchless code. Even though the if does nothing there is still a branch technically with the assignment to r. And yes, it works correctly.
int avg3(int a, int b)
{
int r;
if ((r = (a/2+b/2+(a%2+b%2)/2)*(!((a^b)>>(INT_BITS-1)))) || (r = ((a+b)/2)));
return r;
}
>>
>>51850296
>jumping at my usage of "a" bitshift
don't fucking backpedal; we all know you wanted to say the div gets turned into one shift
>>
>>51849954

The value you are outputting to console is a return value of ERROR_SUCCESS.

Have you considered reading the documentation of the functions you are using?

https://msdn.microsoft.com/en-us/library/windows/desktop/ms724911%28v=vs.85%29.aspx
>>
>>51850072
>Chess is NP-Hard. Why would you do that in anything other than C or C++?
Because GPUs are better than CPUs, mong.
>>
>>51850362
It's actually impossible to implement branchless code for this because if not branchless it has to evaluate the (a+b)/2 line even when it results in undefined behavior.
>>
>>51850320
You can write them in C.
>>
>>51850362
>>51850407
Actually had an idea. Multiple the a or b by (a+b)/2 in the second expression. Because if it fails 0*a+b will never signed overflow. Branchless, but ungodly ugly average of two ints. Code in a few.
>>
>>51850362

You do realize that the entire reason why AArch64 no longer supports predicated instructions is because nobody gives a fuck about branch misprediction anymore, right?
>>
>>51850460
>nobody gives a fuck about branch misprediction anymore
they should
>>
I'm pretty newish to programming, only taken 3~ or so classes. I'm sort of interested in web development and I'm about to try and learn JavaScript. But you guys all seem to hate web dev, why? Is it "too easy"? Is it not "real" programming? How come?
>>
>>51850460
branch misses sucks for x86 (compared to RISC arches), and in this use is valid because the input numbers can be anything and unless you are doing multiple calls in a row with successive numbers the branch prediction will fail 50% of the time.

>>51850458
I fucked up the wording. I meant multiply a or b in the second expression by the test for if a ^ b were positive. Here we are at a finished product.
int avg3(int a, int b)
{
int t = (unsigned)(a^b)>>(INT_BITS-1);
return ((a/2+b/2+(a%2+b%2)/2)*(!t)) | (t*(((t*a)+b)/2));
}

Funny shit is GCC compiles this to a conditional, lol. The exact same as the conditional version I wrote. I guess I'll give up now.
>>
>>51850419
Aren't they different languages?
>>
>>51850542
Web dev has a serious problem with fads. JS is pretty bad as well.
>>
>>51850716
>JS is pretty bad as well.
Yeah, I've got that feeling from others. How come? What would be a better alternative?
>>
>>51850189
C++ gets a bad name because people don't know how to write modern c++. I'd recommend learning C first and then learn modern C++ when this https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md becomes more mature
>>
>>51850698
>Aren't they different languages?
They are but C++ takes a lot from C, and C is simple enough to learn necessary concepts. After learning C you can either continue with C or learn more advanced concepts of C++.
>>
>>51851125
But most game companies use C++ for some reason
>>
>>51851070
For webdev there is nothing else, maybe compile to JS languages like typescript or coffeescript. the rest are memes.
>>
File: Black_Duck_Dec_2015.png (110KB, 1074x865px) Image search: [Google] [Yandex] [Bing]
Black_Duck_Dec_2015.png
110KB, 1074x865px
>>51850285
>rapidly depreciated language
I have the impression that you seem to be denegrating C++ and promoting C with this statement. However you have you're facts exactly backwards--it's C whose use is dropping like a rock (at least in the open-source world). C++ is enjoying rather vigorous growth (again in open-source) atm.

t. Black Rock:
https://www.blackducksoftware.com/resources/data/changes-in-language-use
>>
>>51851407
>t. Black Duck*
>>
>>51851140
Point is it's easier to jump into C then move to c++ than jumping straight into c++ and being overwhelmed.

You're not gonna be making gigantic game engines in a matter of months anon.
>>
>>51851140
We use it because
A) It runs really fast when done well (faster than any other language in many cases).
B) It has good, lightweight (or frree) abstraction facilities that let us use it for reasonably quick turnarounds on large projects.

Scripting plays a big role with a lot of shops as well. EG, C#.
>>
>>51851508
Yeah, but a bigger issue for a beginner who plans to move into C++ eventually is simple:

No one who starts with C first ever learns to write good C++.
Thread replies: 350
Thread images: 16
[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y / ] [Home]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
If a post contains illegal content, please click on its [Report] button and follow the instructions.
This is a 4chan archive - all of the content originated from them. If you need information for a Poster - you need to contact them.
This website shows only archived content and is not affiliated with 4chan in any way.
If you like this website please support us by donating with Bitcoin at 1XVgDnu36zCj97gLdeSwHMdiJaBkqhtMK