[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
Images are sometimes not shown due to bandwidth/network limitations. Refreshing the page usually helps.

You are currently reading a thread in /g/ - Technology

Thread replies: 255
Thread images: 16
File: CPlusPlus.jpg (36 KB, 433x455) Image search: [Google]
CPlusPlus.jpg
36 KB, 433x455
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 (130 KB, 383x472) Image search: [Google]
1429882928190.jpg
130 KB, 383x472
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 (33 KB, 381x499) Image search: [Google]
beyond-fizzbuzz.jpg
33 KB, 381x499
>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
>>
File: stretchyface computer disposal.jpg (65 KB, 445x488) Image search: [Google]
stretchyface computer disposal.jpg
65 KB, 445x488
>>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 (117 KB, 465x421) Image search: [Google]
what's the matter.png
117 KB, 465x421
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 (25 KB, 460x238) Image search: [Google]
Shipping.png
25 KB, 460x238
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 (54 KB, 940x264) Image search: [Google]
C++1.jpg
54 KB, 940x264
>>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 (13 KB, 222x216) Image search: [Google]
1435613166906.jpg
13 KB, 222x216
>>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 (43 KB, 613x481) Image search: [Google]
mt-stupid.png
43 KB, 613x481
>>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 (138 KB, 566x528) Image search: [Google]
1436709932389.png
138 KB, 566x528
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 (14 KB, 634x322) Image search: [Google]
2015-12-14_00-49-40.png
14 KB, 634x322
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 (29 KB, 613x556) Image search: [Google]
1433698243654.png
29 KB, 613x556
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 (789 KB, 500x375) Image search: [Google]
huc1.gif
789 KB, 500x375
>>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 (91 KB, 1437x908) Image search: [Google]
1448388062479.jpg
91 KB, 1437x908
>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.
Thread replies: 255
Thread images: 16

banner
banner
[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.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com, send takedown notices to them.
This is a 4chan archive - all of the content originated from them. If you need IP information for a Poster - you need to contact them. This website shows only archived content.