[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: 30
File: 1463968263335.jpg (381 KB, 1325x1264) Image search: [Google]
1463968263335.jpg
381 KB, 1325x1264
Previous thread: >>54750726

What are you working on, /g/?
>>
File: fsharp code quotation.png (3 KB, 278x41) Image search: [Google]
fsharp code quotation.png
3 KB, 278x41
Reminder that you can literally average 2 ints in F#
>>
I want to reanimate Dennis Ritchie and show him how all the people who promote C on here are crossdressers.

He'd probably go sprinting back to the casket.
>>
>>54761147
>you can add and divide
good to know
>>
>>54761147
What the fuck is that syntax?

>>54761160
>he doesn't know that Ritchie crossdressed
Nobody reads the jargon file any more
>>
>>54761042
>Copy and pasting is a sin when you could have factored.

What did he mean by this?
>>
>>54761147

Time for reminding: Scheme is capable of averaging TWO (2) values.

(define (avg a b) (/ (+ a b) 2))
>>
>>54757455
Real Thread
>>
>>54761190
he means refactoring it into a function and maybe a loop

but it's fine to have it "unrolled" like that, it's only a small amount of code
>>
File: 1463543953364.png (11 KB, 500x500) Image search: [Google]
1463543953364.png
11 KB, 500x500
>>54761196
(define (avg . a) (/ (apply + a) (length a)))

I shiggy diggy
>>
File: beautiful_mind_board.png (5 KB, 441x441) Image search: [Google]
beautiful_mind_board.png
5 KB, 441x441
Alright! Tonight's the night, for C++. I have experience with some interpreted languages and in fact took a C++ class in uni many years ago.

So please link me to any resources you think are spectacular on: GCC/binutils toolchain, make and gdb.
>>
>Before Bjarne Stroustrup settled the question by designing C++, there was a humorous debate over whether C's successor should be named ā€˜Dā€™ or ā€˜Pā€™.
why P?
>>
>>54761216
how would I write it like that?
>>
>>54761217
>variadic function.

shig

(define (avg lst) (/ (apply + lst) (length lst)))
>>
http://www.stroustrup.com/pronounciation.wav
>>
What should I call my RSS reader?
>>
>>54761367
>>54761333
>>
So since transitioning I think I'm a better C programmer, but I also can't really get hard anymore. Fair trade off?
>>
>>54761369
What?
>>
>>54761367
Obsolete
>>
>>54761367
Posterboy
>>
>>54761373
Yeah
>>
>>54761380
>>54761379
>>
>>54761379
Bjarne Stroustrup
>>
>>54761291
instead of

        if((SensorValue[buttonN] != buttonPrevN) && SensorValue[buttonN] != 0)
{
boolN = !boolN;
}
buttonPrevN = SensorValue[buttonN];


you could have it for example like

void update(const unsigned int n)
{
if((SensorValue[button[n]] != buttonPrev[n]) && SensorValue[button[n]] != 0)
{
b[n] = !b[n];
}
buttonPrev[n] = SensorValue[button[n]];

}


and call it in a loop

but it's completely unnecessary
>>
>>54761393
thx anon. Was really starting to question my decision there
>>
>>54761373
No
It's based to get your penis inside a vagina without a condom
Nice and wet, and she can control her muscles to massage it while inside with practice
>>
>>54761373
Yeah just use viagra and a cock ring.

>>54761319
What's wrong with variadic functions? Do you hate +?
>>
>>54761408
just [n]?
wouldn't you have to update n to 1-8 every loop?
>>
>>54761468
>What's wrong with variadic functions?

If something's taking a variable number of arguments, it should just take a list instead.
>>
>>54761482
How would variadic classix like "printf" work then?
>>
>>54761124
AYY
>>
>>54761124
I want to make a game. Should I learn vulkan or opengl. Or just cop out and use unreal engine and hope they do it for me.
>>
>>54761493

C is a different story, which also doesn't have lists.
>>
>>54761493
dependent types
>>
>>54761482
I'd like to minimize the number of superfluous parentheses. I'd also like to minimize situations which would justify the unreadable quaziquote.

You do realize that
(lambda (a b) (+ a b))

is essentially a pattern matched version of
(lambda args (+ (car args) (cadr args)))

right?
>>
>>54761502
Vulkan is for low level engines
You want OpenGL still
>>
>>54761476
n would be 0 to 7
>>
>>54761502
if you just want a run of the mill first-person shooter or something while putting as little effort into it as possible go with unreal engine, but even then you should know how to program shaders, otherwise learn opengl
>>
WHY THE FUCK DO PEOPLE STILL USE POSTSCRIPT
>>
>>54761373

Becoming a better C programmer happens naturally over time as you gain more experience. Your transition may be correlated with becoming a better C programmer, but you have no evidence to suggest a causal link. Meanwhile, you have likely deteriorated your ability to produce an important hormone associated with attention, memory, and spatial intelligence -- testosterone.

That said, as long as you haven't chopped your dick off yet, this should be reversible.
>>
>>54761517
>I'd like to minimize the number of superfluous parentheses.

It doesn't really bother me. I love parens now.
>>
>>54761493
The form of the Scheme version of printf, format, would go from
(format "(~a, ~a)" x y)

to tripnigger's retarded form of
(format "(~a, ~a)" `(,x ,y))
>>
>>54761537
fuck you mean

aren't you supposed to add
n = n+1
if (n >= 7)
{
n = 1
}

?
>>
>>54761482
>it should just take a list instead
But what if the type of each argument could be different for each call?
Nobody wants to pass an array of void * to printf.
>>
>>54761573
Yeah parentheses are nice and all but you should use them well. African children could have cast spells with those wasted parentheses. Out of curiosity do you redefine + and - and all the other standard variadic procedures in your verbosier form?
>>
Speaking of variadics though, Go's variadic append function is a goofy one isn't it?

Type sig
func Append(slice []int, items ...int) []int


Usage
countables := []int{0, 1}

// Add one item
countables = Append(countables, 2)

// Add multiple items
countables = Append(countables, 3, 4, 5)

// Add another array's contents
more_countables := []int{6, 7, 8}
countables = Append(countables, more_countables...) // the ... is necessary to "expand" the array into variadic format or something
>>
>>54761585
i mean

while(true) {
for(int n = 0; n < 8; ++n)
{
update(n);
}
}


and then button etc are 8-length arrays
>>
>>54761367
Josephine
>>
>>54761601
>Out of curiosity do you redefine + and - and all the other standard variadic procedures in your verbosier form?

If it's already there, no. If I'm writing something, it'll probably take a list.

>>54761578
>tripnigger's retarded form


Very rude, 2bh.
>>
>>54761573
legitimately considering making a syntax where whitespace controls priority
e.g.
5 + 3/2 =
5 + 3 / 2 =
5 + 3/2 =
5 + (3/2)
>>
>>54761626

Why not? It'd be fun.
>>
>>54761569
What if I get a surgical vagina and then start taking testosterone?
>>
I realize I'm probably asking too much but can someone give me a serious idea for a programming project that looks good on a job application and shouldn't take more than a week to do?
>>
>>54761647
>why not
Never said I wouldn't
I brought this up during a trip to /sci/
Someone asked one of those fucking vague operator precedence questions and I just said "_, based on the spacing"
>>
>>54761608
Probably to do with the simple type system
>>
>>54761652
you'd just be a dude with an inverted dick
>>
>>54761652

That would be retarded.
>>
>>54761608
What happens when you do that 3 dots assigned to a variable
Or print it
>>
>>54761682
also known as a woman

haven't you ever wondered why women accuse men of thinking with their dicks?
it's because women don't have dicks
>>
>>54760855
>>54760873
>>54760886

Alright, one more question. I know this is extremely easy, but I cannot get the stupid number to pass from the server to the player. I tested it, and I know it's being sent from the server, but for some reason the player can't pick it up. I tried using the same code that I'm using to get the x and y values from the server, but it always comes back blank. The server runs in a separate .exe so I can't just call a function or anything.
Once again, the code is: http://hastebin.com/xemicekoku
>>
>>54761698
Are you crazy? Are you out of your mind!?
>>
>>54761608
C++'s variadics set the standard IMO
(for non-dependent languages)
>>
>>54761663
>one of those fucking vague operator precedence questions

Really the gift that keeps on giving.
>>
>>54761686
but what if I start programming in Python?
>>
>>54761713
They went too far with Variadic Templates
>>
>>54761727
No they didn't. Variadics are beautiful.
>>
>>54761623
Let me help you out then. I wrote this macro just for you. <3:
(define-syntax retardify
(syntax-rules ()
((_ op args) (apply op args))
((_ op indv ... args) (apply op (append (list indv ...) args)))))

Usage examples:
(retardify + '(1 2 3)) ;=> 6
(retardify format "(~a, ~a)" '(1 2)) ;=> "(1, 2)"
(define (new-format string vars) (retardify format string vars))
>>
>>54761742

You are wonderful. God bless.
>>
>>54761702
        int offset = 0;
do {
offset = SDLNet_TCP_Recv(connection, (char*)data+(offset), 1400);
if (offset <= 0){
cout << "OFFSET ERROR: " << SDLNet_GetError() << endl;
return;
}
}
while (data[strlen(data)-1] != '\n');


This piece of code looks as if it could be the source of some trouble if the data buffer isn't guaranteed to be zeroed before it's run.
Are you certain your data buffer is totally zeroed before you run this piece of code?
>>
>>54761813
That gets called every frame. The buffer is obviously empty the first time, but I don't know about after that. Should I clear it at the end? Or would it be better to just use a local variable? data is actually a member variable.
>>
>>54761850
Yes you should zero that fella when you're done with it.

You only need to zero the bytes that are written upon, so creating and zeroing an entire fresh buffer on the stack is probably slower for no benefit.

>>54761772
Andy remember if anyone questions your use of a "useless syntactic-sugar" macro that creates extra data needing to be garbage collected, remember to scream at them:
>PREMATURE OPTIMIZATION
>REEEEEEEEEE
>>
>>54761911
>remember to scream at them:
>>PREMATURE OPTIMIZATION
>>REEEEEEEEEE

I already do that. I never use free in my C code because the operating system will take care of it when the process ends.

Anything else would be premature optimization.
>>
>>54761911
Cool, I just called memset on it at the end of the function.
Still though, the seed isn't getting through for some reason. This is how I'm sending it from the server:
int seed = 1000;
sscanf(data, "3 %d", seed);
for (int k = 0; k < sockets.size(); k++){
cout << "SENDING DATA TO NETWORK" << endl;
SDLNet_TCP_Send(sockets[k], data, strlen(data)+1);
}


And I'm certain that it's going through because it writes "SENDING DATA TO NETWORK", and then I use the same process as before to get the seed from the server, but it always returns null.
Fuck me, man, this is so confusing.
>>
>>54760643
>http://meta.stackexchange.com/questions/271080/the-mit-license-clarity-on-using-code-on-stack-overflow-and-stack-exchange
most code on stackoverflow is trivial so what's even the deal, you can't copyright "hurr durr", same goes for any trivial piece of code
>>
>>54762052
>sscanf
I think you mean
>sprintf
int seed = 1000;
memset(data, 0, sizeof(data));
sprintf(data, "3 %d", seed);
printf("%s\n",data) // => "3 1000
>>
>>54762066
This. Unless someone posts an entire project in his response it would be de minimis.
>>
File: 1463853296462.png (339 KB, 1128x1445) Image search: [Google]
1463853296462.png
339 KB, 1128x1445
I'm trying to build my own wearable device.

it includes a skin conductance monitor, uses galvanic skin response.

I had a PCB printed based on a circuit schematic I found in a research paper for the sensor.

I'm trying to make sense of the signal I'm getting however.

Skin conductance isn't as intuitive to read the signal as say pulse rate.

I've written a Java program to simply plot the trace of the signal over time (the sensor PCB outputs to the analog inputs of an arduino).

So now I'm trying to write a program to plot the power spectrum estimation for my signal. I need to write a Java function to compute DFT first then I can calculate the power spectrum.

My assumption is the frequencies mos represented in the power spectrum will constitute the signal data and the rest likely noise.

Next I'm going to try and add a function that constitutes a digital filter to my program, so as to filter my signal data based on the frequencies I desire according to results of power spectrum estimation.

Then I could plot the filtered data set to the screen.

I'm wondering what other peoples' opinion on what I'm trying to accomplish is. I'm not an expert in signal analysis and I wanna know if the digital filtering tool I'm trying to build into my device makes sense, or will actually help me eliminate noise in my skin conductance data.

Also if anyone can point me to a reference for programming digital filters, that'd be especially helpful.

Any advice for me would be appreciated!!
>>
>>54762235
fuck off rajeev
>>
File: 1462134236704.png (905 KB, 1000x652) Image search: [Google]
1462134236704.png
905 KB, 1000x652
I just graduated with a degree in Software Engineering like 5 months ago, haven't applied for a job yet, and I am weak programmer.


What are the odds I get a decent job in the near future? ( end of summer/beginning of fall)

Be honest, I'm scared.


Advantages:

Im white.

I graduated from a very well respected university in my state.

I am asthetically pleasing to look at and I am a great bullshitter

Disadvantages:

I'm lazy

When I did code, at best it was sloppy and I usually played the game of copy the best kid's code, ( I am okay at reading and understanding how code works because of this though )

I have a serious amount of life panic that has basically made it so I didn't even apply yet for a job.

2.5 GPA ( i had a mental wall issue that forced me to keep dropping and retaking classes for a while )

28 years old


Okay boys, be honest with me, in today's market, can I realistically expect to be able to even get a 50k offer starting job with these stats?
>>
>>54762347
No, probably not.
>>
>>54762389

FUCK i really fucked it all up...

Okay well, I am just gonna keep working out and try to make it through OCS and become a commissioned officer in the army.
>>
>>54762347
>the look of that man's face
>the look on the dog's face
>>
>>54762235
>that name
>that image
>>>/get/
>>>/out/

>>54762403
If you do go into the army as an officer and manage an honorable discharge it should be easy to get a job when you leave.

Also brotip navy > army.
>>
>>54762438
>the look on the baby's face
>>
>>54761290
cd and cp are terminal commands
>>
>>54762052
>>54762081
I FUCKING DID IT
IT WORKS
FUUUUUUUUUUUUUUUUUCK YEEEEESSSSS
Thanks, /g/. I love you all. I'll be sure to drop a few hundred grand in each of your Paypals once I become a billionaire.
>>
>>54761124
>We cannot continue down this road.
Is there really that much poo in it?
>>
File: chinese pedophile cartoons.jpg (114 KB, 1280x720) Image search: [Google]
chinese pedophile cartoons.jpg
114 KB, 1280x720
I went to a presentation by a guy who works at Microsoft he's a Senior Program Manager and on his linkedin it says "Helping to create a modern, safer C++." He does something with dev for Visual Studio.

He was saying lower level languages are unnecessarily difficult, hence more error prone. He thinks everyone should learn with Java or C#, because it 1) gets you programming faster and 2) makes you a better program (I don't know what his support was for this). He went on to say, though, that learning lower level languages isn't useless because of legacy software, which he claimed there is a lot of money for jobs in maintaining that older stuff.

He was also going over good programming practices, and one of them was to NOT use pointers, because they can become too confusing. He also said he throws any resume away that has "fluent in C/C++". He said, "C and C++ are DIFFERENT languages."

Anyways, what do you guys think of this? Are low level languages for dinosaurs and engineers? Is starting on something like Java really good idea? I don't think so, I did, and pointers in C++ are annoying me.
>>
>>54761502
LibGDX is a great library don't listen to shitposters who say otherwise
>>
>scriptsafe now requires to be able to read and change all data on websites you visit
dropped?
>>
>>54763184
I think starting with C++ is a good idea, because it's very generic. It's easy to go from C++ to another language.
>>
>>54761160
I'm not a cross dresser.
>>
>>54763226

So you aren't a C user?
>>
>>54761147
That's disgusting.
>>
>>54763220
I agree. C++ seems like a good happy medium.
>>
File: well fuck.jpg (43 KB, 400x400) Image search: [Google]
well fuck.jpg
43 KB, 400x400
>>54763062
Sure does suck SDL_Net doesn't support IPv6.
>>
Does anyone use a surface pro for programming?

I'm thinking of grabbing an i7/iris surface pro 4, but want to be able to unity dev on it. Is this unrealistic?
>>
>>54763201
what's the alternative?
>>
>>54763184
>lower level languages are unnecessarily difficult
When Java bites you in the ass the reason why is arcane. When C has errors it is usually more clear why. He sounds like an incompetent Java weenie who doesn't know Java that well.

>pointers can be too confusing
If you don't understand pointers you don't understand CS. Pointers show up in the highest fucking level languages like LISP and they sure as hell show up in Java.

>fluent in C/C++". He said, "C and C++ are DIFFERENT languages.
He's an asshole. That's true but I can see of some people who know both putting down C/C++ for conciseness. His loss.

In the end he sounds like the sort of awful manager who hates C and C++ because he doesn't understand them. If someone like him throws away your resume, that's a blessing because he is almost certainly a micromanaging clueless cunt.


>>54763264
>happy medium
There is no such thing. Use the right tool for the job. C++ is an overcomplicated overengineered mess with no niche.
>>
>>54763237
I'm a C programmer, probably better than everyone else here at it too, and I can tell you, I'm not a cross dresser.
I think you're getting confused with the Haskell and functional memers, they are the cross dressers, you stupid fucking cancerous tripfag, kill yourself.
>>
>>54763297
>There is no such thing. Use the right tool for the job. C++ is an overcomplicated overengineered mess with no niche.

I meant for educational purposes, as far as teaching someone how to learn programming. I think C++ sits nicely between something like Java and C.
>>
>>54762235
https://www.nayuki.io/page/how-to-implement-the-discrete-fourier-transform
I think you should do more research on what frequencies you're looking for; I'm not sure what you're trying to do will work.Also you might be better off asking /sci/.
>>
>>54763339
Better languages to teach with:
>C
>Java
>Scheme
>Python
>MIPS Assembly
Any of these are more suitable for teaching a first language.
>>
>>54761124
>We cannot continue down this road.
Yeah because it's full of shit.
>>
File: 20160317_193145.jpg (412 KB, 600x747) Image search: [Google]
20160317_193145.jpg
412 KB, 600x747
>>54762893
m8 dont u spred bs

Lang #0 was called BCPL
then someone made a lang called B because of it and there was never an A (schoolkids be like :-<)
Then C was lang #2
And there it is your proof that D is uninformed dogshit
>>
I've been trapped in the world of the parser monad
>>
File: sicp.jpg (280 KB, 700x849) Image search: [Google]
sicp.jpg
280 KB, 700x849
>>54763668
I've got the perfect cure for monad hell
>>
>>54763342

thanks!

I just need to figure out how to approach programming a digital filter next.
>>
>>54763199
>LibGDX is a great library
not really. all the implementation details are hidden from you except you still have to do all the programming work
>>
#define MAX 15

volatile Sprite aliens[MAX];

int main (void) {

//lots of shit that works

SetUpAll();
//some time later
DrawAlien();
}

void SetUpAll () {

SetUpAlien(aliens[0]);
//other shit here that works
}

void SetUpAlien (Sprite *sprite){
//contents usually work
}

void DrawAlien () {

for (int i = 0; i < MAX_ALIEN; i++) {
draw_sprite(aliens[i]);
}
}

//timer that will later operate on aliens[i]
ISR(TIMER1_OVF_vect) {

for(int i = 0; i < MAX_ALIEN; i++){
//do this to each individual sprite
}
}


Prior to this I had aliens[] in a structure, but ISR cannot operate on the contents of a structure, because it can't be passed the structure.

This is the rough contents of what a sprite is, it's not a struct or anything else.
void init_sprite(Sprite* sprite, float x, float y, unsigned char width, unsigned char height, unsigned char* bitmap ) {
// Apply supplied values
sprite->x = x;
sprite->y = y;
sprite->width = width;
sprite->height = height;
sprite->bitmap = bitmap; // This is only a SHALLOW copy!!!
}

void draw_sprite(Sprite* sprite ) {}


incompatible type for argument 1 of 'SetUpAlien'/'DrawAlien'

My main motivator for moving the sprites out of a global struct (at least I think it's global because it's at the top of the single .c) is because of my wanting the ISR to operate on the contents within.

This shit's sending me in circles.
>>
Hey /g/uys, I'm reading C Primer Plus, and was wondering if somebody could recommend a better source for learning file I/O, I just don't feel like I'm understanding how he lays it out.
>>
>>54763668
>monad
Fuck off functional cancer.
>>
I stumbled upon a great paper today that seems to have solved all of my problems. It provides a simple approach for modeling fixpoint data types with entirely type-based termination and productivity checking.
www2.tcs.ifi.lmu.de/~abel/fics12.pdf

For example, if you had the classic data type for natural numbers and a function to double its input:
data Nat : Set where
zero : Nat
succ : Nat -> Nat

double : Nat -> Nat
double zero = zero
double (succ m) = succ (succ (double m))


You can elaborate size annotations:
data Nat : Size -> Set where
zero : Nat i
succ : (j < i) -> Nat j -> Nat i

double : (i : Size) -> Nat i -> Nat #
double _ zero = zero
double _ (succ j m) = succ # (succ # (double j m))


And desugar into a theory without data types:
Nat : Size -> Set
Nat i = (t : Bool) * case t of
false => Unit
true => (j < i) * Nat j

zero : (i : Size) -> Nat i
zero _ = false , unit

succ : (i : Size) -> Nat i -> Nat $i
succ i m = true , i , m

double : (i : Size) -> Nat i -> Nat #
double _ (false , unit) = zero #
double _ (true , j , m) = succ # (succ # (double j m))


Basically, all termination/productivity checking is done by making sure recursive calls are on smaller size arguments. This works for both ordinary recursion (shown here), corecursion, and a mix of both.

The last two steps would be done in reverse order (with desugaring adding holes for the elaborator to fill), really, but this is for sake of illustration. If either elaboration or subsequent type checking fails, the machine isn't sure that your program is total.

Also, because the `Size` type doesn't have an eliminator, like `Set`, it can be erased entirely from the run time.
>>
true thread >>54757455
>>
>>54764104
Fuck off pleb and learn something other than adding integers
>>
>>54764180
kill yourself fag
>>
>>54764195
Kill yourself retard, learn something other than recursive Fibonacci.
>>
File: ;_;.png (750 KB, 854x853) Image search: [Google]
;_;.png
750 KB, 854x853
So, I have some letters like this that is the the 'session key' or something like it, for a website.
ttle6qsdcogwl18as882in9w2nr4i6
baytiragiankh9pooimpt3lr7osbfj
6gk5fe66honfedvyjyozis0zldaf5u
is785z75wygu3txa47yv6qpfdoyvhw

This is the only thing you need to know to get into someone's session.
There are 30 thousand average users.
How long will it take to find a key someone is using?
I know there are a lot of factors that go into this but, what do you guys thing? I don't know anything about this kind of math.


[spoiler]why duplicate threads with pure cancer, oh god[/spoiler]
>>
>>54764376
If only you saw the beauty of monads
>>
>>54763220

>C++
>Very generic
Actually it does a number of things that are incredibly fucking weird that are not done by other languages. It's one of the few languages that can boast that it has grammar that is literally undecidable. RAII, while fairly useful in its ability to deterministically manage resources (and not just memory resources), is not particularly common among programming languages. Most languages use garbage collection, rather than scope based resource management, or like C, provide no automatic management of resources/memory. It also allows for multiple inheritance, which most object oriented languages stray away from, and even implements it in some parts of its standard library (the iostream class inherits both the istream and ostream classes).

While it might be true that it's easy to go from C++ to other languages, it's not exactly generic as a language... unless of course you're talking about its excellent support for generics. In which case, yes, it has the best damn generics around. Not always easy to work with though.
>>
>>54764388
there is nothing beautiful about monads, there is nothing amazing about them, stop being so smug
>>
>>54764396
anon what languages do you use other than scratch
>>
>>54764426
>feeding the troll
>>
File: [tilting increases].png (27 KB, 500x500) Image search: [Google]
[tilting increases].png
27 KB, 500x500
>>54764426
keep having a false sense of superiority delusional fag, you're not smart for being into FP, it's not hard or anything, in fact you're stupid for falling for the meme and for not recognizing how shit FP is
>>
>>54764452
keep worshiping fucking monads fucking idiot
>>
>>54764454
didn't say it was smart
>>
>>54764468
Oi stop feeding him you retard.
>>
File: OP.jpg (691 KB, 1024x820) Image search: [Google]
OP.jpg
691 KB, 1024x820
>>54762347
You're literally fucked.
>>
>>54763937
Can I please get an answer instead of you all making the thread cancer?
>>
>>54762347
>Advantages: I'm white
I thought you said you were looking for a job?
>>
>>54762347
he looks like he could be part black though idk
>>
>>54763937
file I/O is reading/writing files
>>
>>54762347
>What are the odds I get a decent job in the near future?
none if you dont start searching
fuck sake man, get off your ass
shit wont magically work itself out, just start somewhere and see it as a learning experience
>>
Does anyone have a good guide on understanding dereferencing pointers in C++?

I have a project where I'm constructing a Doubly Linked List, and the nodes are implemented as
 
//snippet from PushBack()
last_->next_ = LinkNew;


using a pointer dereference/access to set the next node in the list. What has to be implemented however is the point/link to the previous node to set as its own new Link. I just have no fucking clue how to do this and am racking my brains trying to figure it out.

Any help is appreciated as I'm incredibly retarded when it comes to structures/thinking of addresses.
>>
>>54761626
Nah, polish prefix sytax is superior.
I know, I'm polish.
>>
>>54764505
You shouldn't act entitled. We aren't obligated to respond to you.

Besides you should probably be more clear in your issues, e.g. post lines of code you don't understand.
>>
>>54764522
Oh yeah thanks, I totally meant I didn't get what it meant, not that I wasn't understanding how to make it work. Great job.
>>
>>54764554
last_->last_?
>>
>>54764554
Post full code.
>>
>>54764558
I'm not acting entitled, but responding to me is far more productive than the last like, 10 posts before I asked for a response,
>>
>mandate was scrapped because citizens refused to change their diapers for several weeks.

You can't make this shit up.
>>
>>54761124
>What are you working on, /g/?
Since the other thread is dead, I'll post here too.

Just finished my Brainfuck compiler for Mac OS X. It's pretty simple now, and doesn't really support any options (like EOF behaviour, cell width, array size, OOB behaviour, adding ASCII offset for some programs that assumes that etc).

It's also not very optimised, right now every cell increment/decrement will do load + incr/decr + store, which is very inefficient. I should probably chain them together and only store when I move the array pointer.

Also, only tested with some programs, so might discover some weird stuff.
>>
>>54764576
You absolutely are acting entitled. You're justifying it now with some bullshit ideas about "productivity." This thread isn't some company meeting. There's no such thing as productivity here.
>>
>>54764560
what is it that you have trouble with? the syntax? just RTFM dude
>>
>>54764601
You forgot the link again:
https://github.com/enfiskutensykkel/bf-compiler
Out of curiosity why are you compiling directly to machine code? Why not compile to assembly and then call ld?
>>
>>54764638
>ld
oops I meant yasm and then ld of course.
>>
>>54764638
>You forgot the link again:
Yeah, it's early in the morning... Thanks anon.

>Out of curiosity why are you compiling directly to machine code? Why not compile to assembly and then call ld?
Well, I wanted to build the Mach-O executables myself (because it's fun) and I didn't really want to write an assembler, most of all because it would be severely limited in terms of instructions supported.

I have a project with a friend further down the pipe where we will try to implement a simplified C-esque language, where we will probably add more steps (parser, tokeniser, compiler, assembler, linker) and support PE and ELF in addition to Mach-O. But for now, this was really just a proof of concept.
>>
>>54764624
>I'd rather be cancerous than helpful
God your parents must be proud.

>>54764636
I was asking if someone had another source for it, people learn in different ways, and I just didn't feel like Stephen Prata did a very good job on that chapter specifically for me. Most of the rest of the book I've just gotten immediately, but the file I/O chapter left me scratching my head.
>>
When I do this
select * from foo f
join bar b
on f.dicks = b.dicks
where f.type = 'faggot';

In which order do the "where" and "join" get applied? I would hope the "where" goes first, since that would be more efficient, right?
>>
>>54764682
"Where" can sometimes be implicit joins.
>>
>>54764563

Eh I shouldn't of even posted the segment. It would be more like last_ -> LinkNew; and then track it that way.

>>54764575

It's a lot of code. I don't particularly think it would help to just post part of the function either. I just really need to learn up the pointer management better.

At this point I don't particularly want to post much as it's a project, but I'm at a pretty big dead end in understanding it.
>>
>>54764675
>how do i google
>>
>>54764672
I suppose writing an assembler is tall order which is why I'd use one that already exists.

How did you come up with the machine code for the executables without using an assembler?

>>54764695
A doubly linked list shouldn't be terribly long. Here's just my implementation of the list struct and the cons (append new node to front) operation:
typedef struct node { void * val; node * next; node * prev; } node;
node * cons(void * val, node * rest) {
node * rtn = malloc(sizeof(node));
rtn->val = val;
rtn->next = rest;
rtn->prev = NULL;
rest->prev = rtn;
return rtn;
}


Pointers are just places where addresses are written down. Dereferencing them is the computer going to the address to pull out the data.
>>
>>54764766
>I suppose writing an assembler is tall order which is why I'd use one that already exists.
But the fun thing is to do as much as possible yourself :)

>How did you come up with the machine code for the executables without using an assembler?
I compiled some snippets with llvm-as (aka used assembly files as input to clang) and looked at the object files.

I also have the Intel manuals lying around, so I looked some stuff up there. But mostly, I took the shortcut approach (using clang and then looking at the object code).
>>
>>54764382
You're looking at x^y possible combinations. Assuming that your key there is what you've given, 31 * 4 = 124 characters, and chosen from A-Z | 0 - 9 = 36 characters, you're looking at 36^124 = 9.58 * 10^192 possible keys. It'd take a long time to brute force. More feasible to try to intercept the session key over the wire.
>>
>class B inherits from class A
>class A has a virtual function that takes an object of class B as an argument

Should I just have a big list of undefined classes at the top of my program in this case? This happens quite frequently in my code, another example is class World has a vector of Objects, but class Object has a pointer to it's World.
Is putting this at the top of the file a shit design indicator?
class A;
class B;
class Object;
class World;
//now define all classes
>>
>>54764766

It's about 800 lines of code in the implementation file. The harness is about 2000 (basically just the display and calls for the implementation). The headers about 230.

It has a lot of implementations, functions, and operators, and has three different list you can add together etc. It's annoyingly large. But as far as handling the prev_ next_ it's only in places that explicitly moves the Link or adds a new one.

Also it's using the container class List instead of struct.
>>
Hello, I need to do string distance on a database in order to have some kind of search engine for a project. Any idea on how to avoid running a distance alg for every single entry in the database?
I have been searching for an alg that gives me a value to save in the table in order to make an index of on but the only ones i've found are overly complex stuff.
>>
>>54764143
So... it's an encoding of primitive recursive functions?
>>
File: 20160424_234425.png (703 KB, 1079x1594) Image search: [Google]
20160424_234425.png
703 KB, 1079x1594
>>54764766
DEATH TO HE WHO WASTES ENORMOUS MEMORY BY SHEEVA!
>>
Just started learning C as my first language
it's alot of fun
i think i'm retarded though
>>
File: vomit.jpg (113 KB, 740x740) Image search: [Google]
vomit.jpg
113 KB, 740x740
>>54764869
>It's about 800 lines of code in the implementation file.
>The headers about 230.
>Also it's using the container class List instead of struct.
>The headers about 230.
>The headers about 230.
Jesus Christ.

I'd purge that and rewrite a sane one with structs, maybe templated if you wanna C++ up that bitch.
>>
>>54764949

It is templated.

Like I said, it just has a shit ton on implementation, plus all iterators are const and non const. Also since it's a project it has quite a few comments just to tell what a lot of things are.

It's not a terribly written code, I'm just too retarded/novice to figure out the proper pointer implementation, so It's me trying to figure out how to implement prev_ into this doubly properly so when I iterate backwards or print the list backwards it will do it properly.
>>
File: gkis.webm (2 MB, 889x500) Image search: [Google]
gkis.webm
2 MB, 889x500
/dpt/-chan, dai suki~

Ask your much beloved programming literate anything (IAMA).

>>54763184
He's right.

>>54761160
>He'd probably go sprinting back to the casket.
He never had a wife and died alone from aids.
>>
>>54763184
>He said, "C and C++ are DIFFERENT languages."
It's true.

C is a barebone portable assembly

C++ is a modern multi-paradigm language
>>
>>54764908
Not at all. C is a hard first language, because you're learning both general programming idioms/logic and low-level specifics at the same time. Not to mention C itself has plenty of quirks and oddities.

The good news is that learning it equips you to learn almost anything else, so I assure you it will be rewarding. Good on you, anon!
>>
>>54763184
There are exceptions to everything (you definitely need C++ for gamedev, for example) but that all sounds like good general advice to me.
>>
>>54765152
>(you definitely need C++ for gamedev, for example)
unity3d
>>
>>54765185
Sorry, should have clarified. I'm well aware you can make a game with anything ever, including GUI tools like Game Maker.

I meant if one is interested in going into "real"/pro/high-performance gamedev.
>>
>>54765214
That's wrong though. C++ is the industry standard for high performance gamedev and for good reason, but it doesn't mean you have to use it to make "real" game engines.

As someone who does gamedev, good object inheritance game engine designs in C++ can be redone in C with struct composition and function pointers. Any competent C++ programmer should be able to rewrite his codebase in C and imagine what it would look like with struct composition, otherwise you'll end up making crappy code with overused inheritance not knowing what the real benefit of C++ really is.
>>
>>54765283
if you're doing if statements/switches on enums you're a fucking joke dude
>>
>>54763184
he's right but Java and C# are basically low level compared to Haskell, Ocaml, F#, etc

learn those instead
>>
File: Random.jpg (102 KB, 600x586) Image search: [Google]
Random.jpg
102 KB, 600x586
I want to learn C++ but every book is either 3500 pages long or tutorials are low quality Pajeet ones.

Java has countless high quality books, the official Java tutorials as well and good video tutorials on YouTube. Same with Python because it's a beginner language and other languages like C# because they're managed by a large company that actually documents things.

This is why I lean towards Java and Python. I want to learn some theory and apply it so I can learn more and repeat. I don't want to read 500 pages before getting to the part where we write the hello world program.

Please tell me how to learn C++, /g/.
>>
>>54765846
I know what you mean, but I never need to do a switch of an "object type" enum in my runtime environment, I fully understand base class virtual functions should not need to figure out the type of other objects.

Why make such an assumption?
>>
>>54765923
The C++ programming language (latest edition)
then
Modern effective C++ by meyers
>>
>>54765930
cool

>Why make such an assumption?
you should see some of the smug C weenies in these threads
>>
>>54765923
>Please tell me how to learn C++, /g/.
learn java and then RTFM
>>
Retard here.
In a loop is it faster to
int iter = 4*i;
arr[i] = x;
arr[i+1] = y;
arr[i+2] = z;
arr[i+3] = w;

or
arr[i*4] = x;
arr[i*4+1] = y;
arr[i*4+2] = z;
arr[i*4+3] = w;
>>
>>54766647
I feel like the compiler can optimize them to be the same. But what you should do is make your loop declaration like this:

for (int i = 0; i < whatever; i += 4)
if you're going to jump 4 steps all the time anyway.

Btw I'm assuming it's a typo in the first one that you're using i instead of iter in the brackets.
>>
>>54766647
the compiler can optimize it at least if you're using C/C++

you could increment by 4 like >>54766672 said if it works with your code, this way you don't need a multiplication/bitshift

and use unsigned ints
>>
>>54766672
I just did a benchmark with time.h
doing the "int iter = 4*i" is actually a little slower surprisingly.
test1.c = 0.136519
test2.c = 0.143630

Ran the tests multiple times, those are the approximate rounded values.
I ran your test and it was pretty much equal to test1.c, a little faster even but can't really tell with time.h.
>>
>>54766780
It's not that surprising. Assume a dumb compiler:

First (assuming i is in a register, pseudoassembly):
mult i 4
mov i iter
mov iter i
mov x arr(i, sizeof(arr))
mov y arr(i, sizeof(arr), 1)
mov z arr(i, sizeof(arr), 2)
mov w arr(i, sizeof(arr), 3)

Second (same conditions);
mult i 4
mov x arr(i, sizeof(arr))
mov y arr(i, sizeof(arr), 1)
mov z arr(i, sizeof(arr), 2)
mov w arr(i, sizeof(arr), 3)

Basically, the computation is trivial (1 mult 1 add), x86 (and others, I presume) have opcodes for iterating over arrays very fast and in the first one you have to go back to main memory fetch the iter
>>
>>54766780
If you really want to dig deeper into it you can pass the -S flag to Clang/GCC and get the assembly output, but it is a bit masturbatory since it's unlikely this stuff will have any noticeable performance impact in a real program compared to other stuff.
>>
>>54763298
>they are the cross dressers, you stupid fucking cancerous tripfag, kill yourself.

Your anger betrays you. You cannot deny being a crossdresser.
>>
How do I compose a list of all elements of another list which are less than x? Haskell

fibs = 1 : 2 : zipWith (+) fibs (tail fibs)
list = [x | x <- fibs, x < 4000000]

This kinda works but it keeps checking numbers after they have reached over 4 million, so I would think I want to stop when that reaches false for the first time, not sure how to do that. Of course I could use take, but I would rather make more general functions.

Thanks anons.
>>
>>54767231
>How do I compose a list of all elements of another list which are less than x? Haskell

Isn't that just a filter with the function being element < x? Unless I'm misunderstanding
>>
>>54767327
Yes, but because it's an infinite list, I need it to terminate checking elements as soon as one is > 4000000, otherwise it will keep infinitely checking
>>
>>54767231
Might need some pattern matching

takeUnder x [] = []
takeUnder x (f:fs)
| f < x = f : takeUnder x fs
| otherwise = []
>>
File: 1372292340198.png (306 KB, 975x1045) Image search: [Google]
1372292340198.png
306 KB, 975x1045
>>54767363
That's great, thank you.
Still getting used to thinking functionally, just doing project euler again to try and learn it
>>
>there are two parallel /dpts/
help

also how do I stop being autistic and accept writing hacks instead of "doing the right thing"?
>>
Having to delete shit from a database (derby).
I have table A with not null references to table B.
I need to delete some rows in B and then the rows containing the references in A.
Can i use a transaction to make sure it doesn't whine about references?
>>
>>54767516
Why not simply delete from A and then B? If it's only A referencing B then there shouldn't be a problem (B doesn't even "know" that A exists if that's the case).
>>
>>54767624
Because i have to decide wich ones to remove based on the rows in A.
Anyway as of now i am removing A and then having a NOT IN on a field in B so i am sure this doesnt fuck up due to references getting whiny.
>>
>>54767493
do it right from the start or else you might get fucked over later on
>>
File: 1449743431209.jpg (168 KB, 1210x603) Image search: [Google]
1449743431209.jpg
168 KB, 1210x603
>>54767493

Everybody writes hacks, though.
>>
>>54767779
C# pajeets != everyone
>>
>>54767830
>C# pajeets

k sperg lmao
>>
>>54767835
but seriously, not everyone writes hacks
>>
>>54767493

Work on projects where doing things right, even if it takes longer, is the smarter choice.
>>
I decided learning a Lisp dialect would be a good idea since all of you guys seem to think it's great. I picked up Racket and this thing seems unnecessarily complicated. Why would someone use it? Can someone give me a use case for Racket?
>>
>>54768713
I'm using it for drawing Mandelbrot images right now. Doing anything in Lisp langs is more or less just a preference, I guess. I enjoy it.
>>
>>54768746
If it's just a preference, why does it have such a high reputation?
>>
>>54767231
couldn't you use takewhile? something like this (f# here)
let kek x y = y |> Seq.takeWhile(fun i -> i < x)
>>
>>54761124
#include <stdio.h>

int main(){

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

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

return 0;

}


How much is d?
>>
>>54768886
++c increases and then returns so 156 *??*. Might have miscalculated it ;-;
>>
>>54768792
It's just a lot simpler. There's no special syntax rules, it's all composed functions. I find it a lot more readable and easy to program in compared to something like Python.

>>54768841
He could have, I wrote him that does something similar here >>54767363 but it doesn't accept a comparison function.
>>
>>54768841
Yes, that was cleaner, thanks.

fibs = 1 : 2 : zipWith (+) fibs (tail fibs)

sumevenfibs = sum [x | x <- takeWhile (<4000000) fibs, even x]
>>
>>54768886
UB
>>
>>54769003
Why?
>>
>>54769025
multiple mutations without 'breakpoints' in between

my terminology is probably off but i hope you get the idea
>>
>>54768886
139, but,

test.c: In function ā€˜mainā€™:
test.c:6:65: warning: operation on ā€˜cā€™ may be undefined [-Wsequence-point]
d = ++c + ++c + ++c + ++c + ++c + ++c + ++c + ++c + ++c + ++c + ++c + ++c;
^~~


Lots more errors like this but it complains it's spam if I post them all
>>
>>54769025
>>54769148
basically it's so that the compiler can reorder operands to optimize it better
>>
>>54769148
>'breakpoints'
>my terminology is probably off
>>54769158
>-Wsequence-point
yeah sequence point was the word i was looking for
>>
File: sa.webm (3 MB, 720x405) Image search: [Google]
sa.webm
3 MB, 720x405
>>54765072
>tfw there still no question +6 hours after

Our community has reached a new low ( ;ļ¹;)

>>54768886
Undefined.
>>
for example the compiler is allowed to split it into

++c + ++c + ++c + ++c + ++c + ++c


and

++c + ++c + ++c + ++c + ++c + ++c


and sum those, but if you do those two individually the result is too low compared to if you do the whole thing from left to right
>>
>>54769222
What's your favourite language anon, and why?
>>
File: 1429039187363.jpg (58 KB, 778x720) Image search: [Google]
1429039187363.jpg
58 KB, 778x720
>tfw I wasted a lot of time trying to wrap my head around higher-order unification when all I need is first-order unification
>>
int square(int num) {
return num/2;
}

Assembly output:
square(int):
pushq %rbp
movq %rsp, %rbp
movl %edi, -4(%rbp)
movl -4(%rbp), %eax
movl %eax, %edx
shrl $31, %edx
addl %edx, %eax
sarl %eax
popq %rbp
ret


same code written another way
int square(int num) {
return num*0.5;
}


Assembly output:
square(int):
pushq %rbp
movq %rsp, %rbp
movl %edi, -4(%rbp)
pxor %xmm0, %xmm0
cvtsi2sd -4(%rbp), %xmm0
movsd .LC0(%rip), %xmm1
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
popq %rbp
ret
.LC0:
.long 0
.long 1071644672
>>
>>54769759
Those functions are not the same though.
>>
>>54769759
>integer division is different than floating point multiplication

wow
>>
>>54769775
why on earth would this surprise you
>>
>>54769771
they are though

a/2 = a*0.5
>>
>>54769790
not in most programming languages
in most C like programming languages (1/2) is 0, not 0.5
>>
>>54769790
Nope.

Multiplying by a floating-point number and then truncating to an int is a different operation than integer division.

It would be ridiculous for the compiler to try to butt in on that kind of thing, ESPECIALLY in a language like C where it could matter.
>>
>I wrote A but meant B
>A and B are kinda similar so the compiler should have fixed it for me!
>>
>>54769811
>>54769809
i meant mathematically

a/2 = a*0.5 = a* (1/2) = a /2

sorry for the confusion
>>
>>54769832
Mathematically, yes. In the context of a computer with separate integer and floating-point operations, no.
>>
>>54769832
yes we know that
>>
>>54769842
>>54769841
8====D ( ):
>>
>>54761124
>Hydrabad
>>
>>54763199
>>54763790
I did their tutorial and I'm considering making a game using it. I picked it since it seems like the easiest way to do Android, iOS, and web at the same time.

I haven't started yet, because I'm currently learning Box2D, but are there any major disadvantages?
>>
It's my first time messing with Swing in Java.
I can't wrap my head around it.
I want a little window that has a button with a word on it and a text field. I want the text field to fill with the word on the button after the button is clicked.
How do I do this?
I already have the visual class, just don't know how to connect them.
>>
factors n = [x | x <- [1..ceiling $ fromIntegral n/2], n `mod` x == 0] ++ [n]


Can this be done in one? I know adding to the end of a list is inefficient, so can I tell somehow in the list comprehension I want the last item to be n?
>>
>>54769975
for a very basic 2d game with box2d physics like a simple flappy bird or angry birds clone (or any game like that) it could be ok i guess but i'd really recommend getting familiar with graphics programming and do platform-specific input processing instead of just winging it with libgdx. don't expect more than 100-1000 downloads, just look at any libgdx game, most of them are very simple and have few downloads
>>
>>54770045
divisibleBy :: (Integral a) => a -> a -> Bool
divisibleBy x y = mod x y == 0

isPrime :: (Integral a) => a -> Bool
isPrime x = or $ map (divisibleBy x) [2..(x-1)]
>>
I finally got my file manager up and running. It works like a champ.
Now I'm being autistic and nit pick on variable naming and white space.
>>
>>54770072
post source
>>
>>54770101
https://github.com/baspalmer/matcha
>>
>>54770053
Yeah, this is gonna be fairly simple, like an endless runner type game.

What are the advantages to platform specific input processing?
>>
File: error.png (99 KB, 1540x821) Image search: [Google]
error.png
99 KB, 1540x821
>>54763062
>>54763277
So I found a fork of SDL_Net called SDL_sixnet that does support IPv6. I tried installing it, but it's giving me some errors. It says there's a conflict at these two lines, but I don't see any issues. Can someone point out what's up?
>>
>>54770175
You are trying to call do_something before you declare it. You need to add a function prototype before
>>
>>54770184
Shit, you're right. Can't believe I missed that.
I hope there weren't any other files I was supposed to download.
>>
I'm trying to use an OpenGL shader.

The example I am following is the one linked to on the lwjgl wiki for shaders.

The shader loads, but it uses GLbegin() and GLend(), which is deprecated

what is the new way to do it?
>>
why cant C compilers allow variable names with dashes in them like: smooth-dicks rather than smooth_dicks.

its one less keystroke which adds up.
>>
>>54770274
int a;
int b;
int a-b;
a-b = a-b;
>>
>>54770274
Let me just subtract smooth-dicks from rough-dicks.
smooth-dicks-rough-dicks
>>
>>54770274
because - is an operator
>>
>>54770293
easy, inforce longest string match for a variable name. a semantical issue at best.

>>54770299
it can be both, other langs do it.

>>54770294
tanks to you
>>
>>54770316
>>54770274
it's absolutely disgusting and would lead to longer compile times
>>
>>54770240
If the tutorial is using glBegin and glEnd it's teaching immediate mode graphics, which aren't used anywhere today (those two functions don't even exist in OpenGL 4.0+). The entire tutorial is deprecated, not just those two functions.
>>
>>54770346
personal opinion.

and longer compile times? lol, do you compile on a 90s machine? the logic for this isnt even hard and is resolvable by semantic phase
>>
>>54770316
What languages do it?
>>
File: 1458713864961.jpg (152 KB, 768x1024) Image search: [Google]
1458713864961.jpg
152 KB, 768x1024
>semantic whitespace
>>
>>54770365
kys

C is never gonna allow fucking dashes in identifiers anyway so what are you even trying argue
>>
>>54770395
1 + 3/2
1 + 3/ 3/2
1 - 3 - 1
1 - 3-1
Thread replies: 255
Thread images: 30

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.