/dpt/ - Daily Programming Thread

What are you working on, Sup Forums?

Previous thread:

Other urls found in this thread:

ocw.mit.edu/courses/electrical-engineering-and-computer-science/
ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-001-structure-and-interpretation-of-computer-programs-spring-2005/
gist.github.com/anonymous/e103d264cecf10e31e6dadfb1c398007
gnu.org/software/emacs/manual/html_node/ccmode/CC-Hooks.html
zerynth.com/blog/the-rise-of-python-for-embedded-systems/
laemeur.sdf.org/fonts/
compcert.inria.fr/
twitter.com/AnonBabble

First for anime is /dpt/ related

Rust

gay

>What are you working on, Sup Forums?
Just started learning C and did my first fizzbuzz. Please rate and don't be too harsh, please. I am open for good adivce though

??=include

int main()
??<
for(int i=1; i < 100; i++) ??<
if((i%5==0) ??' (i%3==0)&(i%5==0)) ??<
printf("FizzBuzz\n");
??> else if(i%3 == 0) ??<
printf("Fizz\n");
??> else if(i%5 == 0) ??<
printf("Buzz\n");
??> else ??<
printf("%d\n", i);
??>
??>

if(!(1 ??!??! 2) ??' 2)
printf("Hello world!\n");

return 0;
??>

first for idris is the best slow piece of garbage i've ever used

Rust is absolute garbage. It makes even the simplest tasks complicated as fuck. I really want to like it but it's just so annoying.

This might not be the most well-received question (and I understand entirely), but I guess it couldn't hurt to ask: Where should I go for online computer science programs? Or is there a non-biased site that grades universities?

I've gotten through the basics by myself just fine, and I know that what employers really want to see are your projects and independent drive, but I specifically need a bachelors degree in a field that I plan on working in.

Eighth for so are kawaii hijab-wearing cuties.

t. brainlet

ocw.mit.edu/courses/electrical-engineering-and-computer-science/

ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-001-structure-and-interpretation-of-computer-programs-spring-2005/

>trigraphs
Nice try user.

>What are you working on, Sup Forums?

Exploring the deepest, darkest corners of Racket.

xD epic cumback, btfo

i don't like nyan mode because the colors don't fit into any theme. besides nyan cat theme i guess.

What do you think about new features in C and/or its standard library with the following conditions:
> Already stood the test of time in either C++ or GNU C
> Are small, non-intrusive, design to make it easier on the programmer

For example, I think most of the programmers say that C99 is a better language than C89, only with some disagreeing on VLAs (which were made optional in C11, so I don't know how much is that relevant)

I personally, enjoy new C11 features like unnamed structures and unions, I'm yet to try out generic macros which I think are great, I love the , it's a pity glibc hasn't implemented it for 6 years already, I think it would be great to have it.

What would you think about the following feature:
> automatic type inference using auto

It wouldn't break the language, old code would continue compiling as it does today, it's already tested in C++, and they seem happy about it.

Or this:
> nested functions
Functions continue being an exception, because you can nest everything else except functions. AFAIK this has been done to simplify compiler creation, which, I think, is not *that* much relevant now, since CS has advanced a lot and there are less architectures to port stuff. It's already in GNU C. I personally used nested functions for encapsulation, that is, putting functions that clearly belongs to a bigger one and can't be used by other ones out of the translation unit namespace.

> Switch ranges.
I personally didn't find a need to use them, but GNU C has them, so maybe they're useful, I just put it here as an another example on non-intrusive extension.

I have the 1570.pdf C11 draft and I read it from time to time, and I see that this language is truly beautiful. I'm not saying we should try to turn it into C++, but I think small, slow, non-breaking, already-practiced, positive extensions could be made.

What do you think?

I need the piece of paper, specifically. I'm not at a loss for how to study. Really, it just needs to be someplace that won't be blacklisted as a diploma mill before I graduate, and the courses need to be online.

Thanks for the resources, though.

likewise

Look at your options and evaluate them:

>look at the curriculum: the more maths / theoretical cs the better
>read reviews
>look what people with that degree are doing today (linkedin)

>Exploring the deepest, darkest corners of Racket.
what did he mean by this?

Tomorrow i have a big exam that will change my life.

wish me luck, guys

Can't find a job? sent out 1000 applications? Expert programmer? Can you compile C to x86 in your head? Let me tell you a story that will make you lose faith in all since of justice. My coworker somehow got a job and is simply the dubest motherfucker I've ever met in my life. Here's some anecdotes about him

>4.0 gpa
>accepted into engineering school at our university (not a top school but still a demanding program)

>gets hired at internship at our company
>we work on a web app in Javascript mostly
>writes everything he does outside of the project folder and tests in an isolated environment and not in the actual web application
>if he needs to write a function to do something, he writes it in a separate file and runs that function by itself either from node or by dropping it into a blank html file
>he then pushes the code without actually testing it in our webapp
>surprise, it doesn't fucking work

>He needs to get some data, format it, and display it
>he can't figure out how to change the data in a polling loop. Just keeps making new divs every time he makes an ajax request
>I give him the following pseudo code:

// functions availabe
// create - create new div with info
// set green - turn div green
// set grey - turn div grey

//objects available
//dom = {} - object contains doms; old data
//agents = {} - object contains new data from XHR

for(var i in agents)
if(dom[i]) //if dom already exists, check for new data
if(dom[i].connected && !agents[i].connected) //if different, change accordingly
set green
else if(!dom[i].connected && agents[i].connected)
set grey
else //if dom doesn't exist, create new div
create

>he's been studying the white board for 20 fucking minutes
>finally says "is this a logic table?"

(cont'd ...)

anal exam?

>Can you compile C to x86 in your head?
B-but C is a legacy language and x86 a deprecated architecture, why would you even wanna learn that?

Good luck man

>we work in two week sprints
>each sprint, I divide up our labor
>I end up doing some of his side because he's taking so long and I finish mine in a couple days
>he complains and asks me not to do that
>I tell him "what do you want me to do, sit here and do nothing and wait for you to catch up?"
>"yes, I want to make sure the work is 50/50"
>I tell him "If you want the work to be 50/50, you need to start doing at least 50% of the work. In a real job, would you tell your boss that everybody has to stop and wait for you to finish?"
>no reply

unrelated to CS, but the other day he asked me if it's illegal to tip a waitress under 15% and if the restaurant can sue him

>we're working on bug fixes
>I get a bug to fix on 3 different platforms
>takes me a week to do the bug on all 3 platforms

>he gets a bug fix
>essentially "add a readonly attribute to these 5 or 6 tags
>it takes him 2 months to get done
>he never tests anything
>turns in this bug fix and it's still broken
>pull request is rejected
>he finishes, pushes it again
>still not done because he NEVER FUCKING TESTS ANYTHING
>finally after 3 attempts, his changes are "satisfactory"

Another story: our company had a get-together
with catering, some beers, etc. and he saw a piece of gouda cheese with some crackers and a cheese knife. He put it on his plate and walked away with it. Later I sit next to him and see the block of cheese with a chunk bitten out of it. He tells me "I don't really like this cake"

You can take this story one of two ways: Either be an optimist and say that if this fucking mongoloid can get a job, then so can I, or you can give up any hope that the universe has any kind of justice

>he saw a piece of gouda cheese with some crackers and a cheese knife. He put it on his plate and walked away with it. Later I sit next to him and see the block of cheese with a chunk bitten out of it. He tells me "I don't really like this cake"

Now that's pretty good

>My coworker somehow got a job and is simply the dubest motherfucker I've ever met in my life
Never fall for the meritocracy meme, user.

Capitalism DOES NOT reward excellence as they have brainwashed you to believe.

...

paternity test

Fastest way to add a list of integers

gist.github.com/anonymous/e103d264cecf10e31e6dadfb1c398007

How do I change my emacs.d to automatically turn on certain modes?

For example, I found the "electric-pair-mode" and "auto-complete-mode" pretty useful for C programming, but I don't want to have to reactivate them every time I open up Emacs.

Sorry for low-tier question.

Put it in your ~/.emacs

>automatic type inference using auto
C not being strongly typed, there could be ambiguous cases easily.

>nested functions
Standard C must be easily translatable to assembly. In most (if not all) assembly languages, there's no notion of second-order procedures, so having a second-order function does not translate very neatly to assembly. Of course, it's doable and permits to limit scope of function, but it does not fit with the mindset of C.

>switch ranges
Same thing there. Switch statements in C are basically a sequence of conditional jumps. Conditional jumps don't test ranges. And testing ranges is easily done without switch anyway.

There's a reason C why is very conservative. Keep the experimental gotchas for C++.

My bad... I meant emacs.d

I usually have to do
M-x electric-pair-mode
or something similar to turn it on. What does this (roughly) translate to in EmacsLisp?

Usually
(electric-pair-mode)
But you can ask the help of emacs. It will describe the function.

This worked! Thanks, man!

KYS

gnu.org/software/emacs/manual/html_node/ccmode/CC-Hooks.html

(add-hook 'c-mode-hook 'electric-pair-mode)

Fucking c++
#include

template
class fish {
public:

template
explicit fish(Args ...args) : array{std::forward(args)...} {}

std::array array;
};

int main(int argv, char** argc) {
//fish test{1, 2, 3}; // doesn't work and gives the compile error
fish test{size_t{1}, size_t{2}, size_t{3}}; // works
}

Error: C2397 conversion from 'int' to 'size_t' requires a narrowing conversion

why are you doing this to yourself?

do you want to go insane?

> have function written to run on input from a file
> uses fopen, fgetc, frewind, etc..
> want to run it on an std::string

fuck me

zerynth.com/blog/the-rise-of-python-for-embedded-systems/

Why aren't you learning Python, user?

Guys, how can I add helping highlights for python in Atom just like in IDLE? Like show which method or function does what. Can't find any package which does so, but, I guess, I am searching with wrong keywords.

Try open_memstream or fmemopen

That gives you a FILE*

Trying to implement a multi-dimensional array but the templates aren't doing what I want them to do.

W-who is th-that sperm succubus?

Fuck yes thank you user

font?

It's fucking easy with coq.
Axiom array : Type -> nat -> Type.
Check array.

Axiom mk_array :
forall (T : Type) (n : nat),
(forall i : nat, i < n -> T) -> array T n.
Check mk_array.

Fixpoint multi_array (T : Type) (dims : list nat) :=
match dims with
| nil => T
| cons dim dims => array (multi_array T dims) dim
end.
Check multi_array.

Definition test : multi_array Prop (cons 2 (cons 2 (cons 2 nil))) :=
mk_array _ 2
(fun i _ =>
mk_array _ 2 (fun j _ => mk_array _ 2 (fun k _ => i + j = k))).
Check test.
Maybe it's time to use a real language user.

This is fucking unreadable my friend. But does your array allow you to create an array of 3 x 5 x 6 x 2 of contiguous elements?

Everything is possible. So yes. The only difference, is that with coq you produce code with zero bugs.

laemeur.sdf.org/fonts/

>The only difference, is that with coq you produce code with zero bug
explain

how can code be free of bugs !?

you can't prove that

>unreadable
i hate C style codelets

>explain
Do you really understand the power of dependent type?
>how can code be free of bugs !?
When there is no bugs in it.
>you can't prove that
Were you sleeping during math class?

1 million years in mspaint.net

Every valid program is a proof of some logical statement.

But the program may also prove something else rather than what you actually wanted to prove. Bug-proof languages can't prevent this kind of problem, the difference between intent and result.

>Every valid program is a proof of some logical statement.
Yes.
>something else rather than what you actually wanted to prove
You have to explicit your theorem. If you don't know what to prove, no tools can help you.

>create esoteric programming language
>get triggered when coders point out the fact that it's unreadable

I’m currently exploring a bit the assembly language, and for some reason I keep getting segfaults when I try to call output functions such as printf, fwrite or fprintf.
Does anyone see what’s wrong in these lines?
.globl foo
foo:
subq $16, %rsp
movb $119, 9(%rsp)
leaq .L.str.1(%rip), %rdi
leaq 9(%rsp), %rsi
callq fopen@PLT
movq %rax, 8(%rsp)
xorq %rax, %rax
leaq .L.str.2(%rip), %rsi
movq 8(%rsp), %rdi
movl $0, %eax
callq fprintf@PLT
movq 8(%rsp), %rax
call fclose@PLT
addq $16, %rsp
movl $0, %eax
ret

.type .L.str,@object
.L.str:
.asciz "%d\n"
.size .L.str, 4
.L.str.1:
.asciz "test.txt"
.size .L.str.1, 8
.L.str.2:
.asciz "Hello World!\n"
.size .L.str.2, 14

>his language doesn't provide a function called S U C C

>esoteric

>when you can't even understand forall a b. (a -> b) because it doesn't involve some horrible hodgepodge of &, *, --, ++, for(;;), int and return

Fix yo' types nigga:
#include

template
class fish {
public:

template
explicit fish(Args&& ...args) : array{std::forward(args)...} {}
std::array array;
};

int main(int argv, char** argc) {
fish test_int{1, 2, 3};
fish test_size_t{size_t{1}, size_t{2}, size_t{3}};
}

i mean you are in the same vein as the person who thought

(float -> string) -> int

was less readable than

int(*)((const char*)(*float))

Dear god please use Intel syntax

...

>int(*)((const char*)(*float))
No it's
int (*) (cost char * (*) (float))
Nice triples.

The only thing in my post that needed fixing was the && in the constructor the std::array holds the dimensions not the type of data.

no

deleted because of satan triples


anyway the point is int (*) (cost char * (*) (float)) is still fucking ugly and hideous and nonsensical compared to (float -> string) -> int
also ignoring string/const char, even if you had

(float -> const (pointer char)) -> int
it's better

I agree, I am the one posting the Coq code for fun. But I just wanted to point out that you made a mistake.

Then are you not using the template parameter T at all? That is pretty misleading.

I don't think I did, what's wrong with putting const char * in parentheses? It looks slightly less ridiculous that way

Show me anything relevant written in your washed up toy language then, smartass.

oh i just checked
i had *float
i meant
(*)(float)
you're right

Yes I right. I did check your code with Coq.

Why are you so hostile to sanity?
Does it really offend you that C could easily have had better syntax?

So you have nothing to show for it?

Didn't think you did.

Start arguing any time buddy, you can't just stay mad in the knowledge that C made a mistake and could fix it any time

Coq/Agda > Idris > Haskell > Scala > *

>Scala

>C made a mistake
Not that guy but the syntax is very nice considering BCPL was what we had before.

All irrelevant meme languages.

Still waiting for that example of anything relevant written in your hobbyist esoteric language.

>Still waiting for that example of anything relevant written in your hobbyist esoteric language.
you're embarassing yourself

here we are, telling you C could be much better
and what are you saying? that C shouldn't have had a better function syntax "because the other languages that have it aren't as popular as C"?

>Still waiting for that example of anything relevant written in your hobbyist esoteric language.
The first proved C compiler:
compcert.inria.fr/
Ho strangely it's made by the same guy that made OCaml.

>defend a literal esoteric syntax as an "improvement"
>tell me I'm embarrassing myself
The irony is almost palpable.

Work on the parser continues

>esoteric
Have you never heard of a fucking arrow before?

So this is how big the rock C programmers are living under!

Struggling through K&R, but also kind of amazed just how versatile pointers are.

Speaking of pointers, I implemented the "strcat" function that joins two strings using pointers, but I keep getting "Bus Error" when I do
char* test1 ="This is a ";
char* test2 = "test";
strcat_ptr(test1, test2);

but not when I do it with arrays like this:
char test1[100] = "This is a ";
char test2[100] = "test";


Why can't I modify a pointer to a string literal? Is it because it's stored in static memory?

Another thing, is there a bug in my strcat_ptr function?
/*strcat_ptr : strcat, but with pointers */
void strcat_ptr(char* s, char* t)
{
while(*s++ != '\0')
; /*find end of s */
while((*s++ = *t++) != '\0')
; /*copy t */
*s = '\0'; /*end string */
}

It seems to not assign characters to *s once the first while loop finishes

>gets desperate
>names something irrelevant which nobody has ever heard of
kek

Can't make this shit up.

?

Install Pelles C.

You're not calling fopen with enough arguments.

foo:
pushq %rbp
movq %rsp, %rbp
subq $16, %rsp
leaq str(%rip), %rsi
leaq str1(%rip), %rdi
call fopen@PLT
movq %rax, -8(%rbp)
movq -8(%rbp), %rax
movq %rax, %rcx
movl $13, %edx
movl $1, %esi
leaq str2(%rip), %rdi
call fwrite@PLT
movq -8(%rbp), %rax
movq %rax, %rdi
call fclose@PLT
nop
leave
ret

I think he just moved the goalposts, user.

>>names something irrelevant which nobody has ever heard of
In few decades all C code in embed world will be compiled with that compiler. You're ignorant user.

Why are you writing the perser?

the what?

Unrecognized token: 'perser'

parser*