/dpt/ - Daily Programming Thread

What are you working on, Sup Forums?

Previous thread:

Other urls found in this thread:

cs.uoregon.edu/research/summerschool/summer16/curriculum.php
man.openbsd.org/cgi-bin/man.cgi/OpenBSD-current/man9/style.9?query=style
gnu.org/prep/standards/html_node/Formatting.html
ocaml.org/learn/companies.html
youtube.com/watch?v=YgHNtzxO0y8
pastebin.com/yzj3eX7d
pastebin.com/erkNA752
pastebin.com/WKFXNc10
twitter.com/AnonBabble

First for C++

Well, Sup Forums? Which is it?

finally, an on topic image

I've always used the one on the right.
It's less messy than the left one.

one on the right, the other is for pedos

What do pedos have to do with this

Left at work.
Right at home.

Real thread:

The real question is is there anything left that has nothing to do with pedos?

Both threads are equally terrible.

They use the left one. That's what they've got to do with this. Do you want to further the pedo agenda by using pedo braces?

left
like in linux kernel

Thinking about going to uni within the next year or so..
I liked Computer Science as a subject at school but I'm more aiming towards Software Development/Engineering as a career

Should I go for Comp Science or would S. Eng be more suitable for what I want to do?

A lot of people would say the exact same thing about the opposite.

A lot of universities make very little distinction between the two, I would research that first. Had a few friends take a CompSci course at a local uni and it was identical to the s.eng course until the final year, were they got a couple of different module choices

The difference between me and them though, is that they're wrong and I'm not.

I'll keep a close eye out.

Also slightly worried about Computer Science at Uni because I hear its full of maths, the hardest maths I've done with CS is Boolean algebra and various rules involving it, makes me wonder if I'll just get blitzed.

The hardest math you'll encounter in CS is Category Theory.

Well its usually fundamental maths, learning how to construct proofs, calculus, boolean algebra and the like. May be a bit tricky if you're not great with that kind of stuff going into it, but nothing that'll require a maths degree and a tutor to get over. Again, be sure to check out the S.Eng course at the same uni, if they are the same, then its likely that maths modules are a choice by the student.

Also, not strictly related to the above, but some unis will automatically enroll you into whatever computing and software engineering society is in your country if you finish the S.Eng course and pass, e.g. in Britain, some will give you free membership into BCS when you pass

Anyone tried Elm? Looks fun af desu

Heard of it but thats about it, whats its bag vs. other JS based languages/JS itself?

No you faggot.
>The other issue that always comes up in C styling is the placement of braces. Unlike the indent size, there are few technical reasons to choose one placement strategy over the other, but the preferred way, as shown to us by the prophets Kernighan and Ritchie, is to put the opening brace last on the line, and put the closing brace first, thusly:
if (x is true) {
we do y
}

Wrong. The hardest one is complexity theory and formal languages.

Left to define outermost scopes, right to define nested scopes.

How much do you value visual prettiness in the languages you use?

As for me, it's almost the only reason why I use F# over Ocaml.

I guess I couldn't say because I don't know category theory, but complexity theory and formal languages were not that difficult.

visual elegance usually correlates to the language not being a clusterfuck

Got it, thanks

Category theory is explained here in these public lectures cs.uoregon.edu/research/summerschool/summer16/curriculum.php

Lol no

>ocaml
>prettiness
user...

But OCaml is prettier than F# user.

Not really no

t. Reason dev

This. OpenBSD also does this:
man.openbsd.org/cgi-bin/man.cgi/OpenBSD-current/man9/style.9?query=style

if(condition){
{
// Statements
}
{
// Statements
}
}

the left one is only for functions...

Neither.

if (Condition)
{
Statements ();
}


See:
gnu.org/prep/standards/html_node/Formatting.html

redpill me on php

job Im applying to requires a simple function but in php, i know its easy and I can just copypaste but is it worth learning? should i just not bother n apply to other places?

It's trash.

>redpill
>>>/global/rules/2/
It's a web language. It's pretty widespread despite the suffering it puts people through. Are you applying for a web position? if so. Think a little.

How big is OCaml in the industry?
There's like zero written about it on the internet

It's not, except in finance.

Companies like Facebook and Mozilla use it. Several financial services too (LexiFi, Jane Street Capital come to mind).
ocaml.org/learn/companies.html although some of these are not actually from the companies, still I doubt they made shit up to promote their language.
It's not as big as in academy but there is definitely usage in several different industries.

This is shit, seriously.
I hope I never see any code like that

>php
It's trash.
I'm not shitposting.

is there a better way to do this or have i reached the pinnacle of celsius fahrenheit conversion?
#include
#include
#include
#include

void main(int argc, char **argv)
{
if (argc != 3){
fprintf(stderr, "tempconv: usage: tempconv [-c|-f] value");
exit(EXIT_FAILURE);
}

int c;
while ((c = getopt(argc, argv, "cf")) != -1) {
switch (c) {
case 'c':
printf("%.2f in celsius is %.2f\n", atof(argv[2]), (atof(argv[2])-32)/1.8);
break;
case 'f':
printf("%.2f in fahrenheit is %.2f\n", atof(argv[2]), (atof(argv[2])*1.8)+32);
break;
default:
fprintf(stderr, "tempconv: usage: tempconv [-c|-f] value");
exit(EXIT_FAILURE);
break;
}
}
exit(EXIT_SUCCESS);
}

port it to C++ and include some template templates

Since we are memeing hard, #include and use std types instead of int.

Use as many macros as possible, maybe use a union. Also, you could find a way to use the conditional operator.

Another option would be to do in OOP style

You're the kind of person to use redpill unironically so it's probably right up your alley

neither, because I only use well designed languages
agreed. even if you're not a fan of begin/end and let/in, you've got to admit the mix of C#-style and ML-style syntax doesn't work well (wtf is

>atof
Use strtof.

youtube.com/watch?v=YgHNtzxO0y8

ecks dee, very constructive post

#include

int main()
{

int tabs = 0,spaces = 0,new_lines = 0;
int input;
for(input = 0; getchar() != EOF; input++){
if(input == '\n'){
++new_lines;
}
if(input == '\t'){
++tabs;
}
if(input == ' '){
++spaces;
}
}

printf("The amount of spaces in the input was %d\n",spaces);
printf("The amount of tabs in the input was %d\n",tabs);
printf("The amount of new lines in the input was %d\n",new_lines);
}


I am reading through K&R and I am stuck on this. The loop won't normally terminate unless I do Ctrl+ D and that doesn't produce the correct numbers. Any idea?

Rate my fizzbuzz:
#.(loop for i from 1 to 100 do
(format t "~:[~:[~a~;Buzz~]~;Fizz~:[~;Buzz~]~]~%~@*" (zerop (mod i 3)) (zerop (mod i 5)) i))

autistic

>The loop won't normally terminate unless I do Ctrl+ D
That's expected behaviour.

>that doesn't produce the correct numbers
You must assign the result of your call to getchar to input.

What do you mean by assigning the result of getchar to input?

Just had a small revelation. I never realized visibility is a class property, not an object property, and that objects of the same class can access each others private objects. Well in Java at least.

Not in OCaml. OCaml is the only language that do oop the right way.

In C, assignment is an expression. That means you can assign getchar to input and still compare that to EOF.

But it can't solve the halting problem so it's trash

It should really be classed COP shouldn't it

What?

I see. I changed the for loop to while((input = getchar()) != EOF) and it worked as intended. Any idea why the for loop didn't work or could I have done for(input = 0; (input=getchar()) != EOF; input++)

nvm i stopped being retarded and just tried it out for myself. I guess getchar() just returns the value and not actually puts it into the variable so I can compare them. I must have missed that when reading

Right.
Doesn't the style on the left come from the times when people declared the parameters of the function outside of the parentheses, right after them?

On that point, do you use
if (condition)
statement;
or
if (condition) statement;
for one line statements?

Neither. You must use:

(condition) && statement;

I started preferring the first, then ended up adopting the second as most code I see uses it

not really that nitpicky to give a shit, i just try to write good programs.

Meh, I can't help it, OCaml uses all the keywords/conventions I hate the most, in a subjective way, I mean.

I really would start learning OCaml (have read a little about it), but the ugliness is putting me off

Second. Also, I insert a space after the left bracket like:
if ( something) statement;
Makes it more readable, especially when they are nested. When there are more than 4 levels of parentheses I use some creative things like one additional space for each outer level of nesting. Which happens a lot in my code, because I like when one instruction line does one logically compact thing.

What's the fastest way to out yourself as a pajeet?

>programming is 95% memorizing your libraries

Doing the needful

You posted this already. Again.

>DRY - Don't Repeat Yourself

When has that ever stopped anybody?

I just wish for serious discussions.

I asked a genuine question.

Yea I prefer that one as well it's just that code gets more exceeding margin

I don't have a good solution for that unfortunately, but it's not that big of a deal for me.

Is there C library that provides interface to native mobile stuff like gps, bluetooth and stuff for android and ios?

any particular advantages over atof?

No, the difference is that the one on the right is part of code guidelines in most companies.

Ha i was looking into this and found
>The way, I'd handle your problem is on the organizational side (as this is company internal stuff): You basically say to the user: "Switch on GPS and you, user, get access to your emails" (well, as an example) Give something and you will get something back :-)
>I'm holding your information hostage until you tell me where you are
Fucking psychos. Anyway the NDK has rather limited OS interacting going on. It wouldn't surprise me if you couldn't do it from the NDK.
>Native mobile stuff
Rereading perhaps I'm not interpreting you correctly. You're saying you just want a library that allows for cross platform access to GPS and such?
So lazy..

What are good atom plugins for:
HTML5,
CSS3,
Python,
C/C++,
Markdown?

Are there any other atom packages that are must have or good to have?

I missed JavaScript and all the other frameworks (jQuery, React, etc.).

Employed Haskell programmer reporting in

who did you have to sleep with?
>inb4 ur mom
>inb4 Satan

there's no need to lie on the internet, animu shit

this

>the crazy things Sup Forums does at home

I'm trying to learn C by porting really simple things I did in python during uni labs but I'm just totally stuck on this for some reason.

Malloc is returning null and causing a segmentation fault but I don't understand why. Obviously my code is going to be absolutely retarded because I just don't know C at all but it would be nice if someone could help me figure it out.

How it's supposed to work is you enter sentences, it splits the sentences into words and stores all the possible options for each position in the sentence. Then it generates a sentence by going through the store and picking a random word from the available choices for each position.

pastebin.com/yzj3eX7d
pastebin.com/erkNA752
pastebin.com/WKFXNc10

Who gives a shit?

(if condition
if-true-form
if-false-form)

Your problems are coming from the 'else' section of addJoke.
strlen(getData(jokeStore, count-1)) + strlen(word) + 1;
You need to to be +2, like you have is the previous section, for the null terminator AND the ":" you're inserting into the string.
strcat(freshString, joke);
You're writing the entire joke to the new string here, discarding the old one, and writing way past the end of the buffer.
I think it needs to be
char *old = getData(jokeStore, count-1);
int size = strlen(old) + strlen(word) + 2;
...
strcat(freshString, old);

Another strange thing I've noticed is that you're allocating a head on the list when it's made, but you never use it.
Your program leaks memory like a sieve.

I also have another bit of advice:
You have a lot of consecutive calls to strcat and all of that. I would really recommend using sprintf instead.
freshString[0] = '\0';
strcat(freshString, old);
strcat(freshString, ":");
strcat(freshString, word);
can become
sprintf(freshString, "%s:%s", old, word);
It's just a lot cleaner and harder to fuck in, in my opinion.

>fuck in
fuck up*