[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

/dpt/ - Daily Programming Thread

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 348
Thread images: 32

File: 1452547354514.jpg (31KB, 309x400px) Image search: [Google]
1452547354514.jpg
31KB, 309x400px
previous thread >>52488565

What are you working on /g/?
>>
First for Java
>>
Second for Java
>>
Third for Java
>>
>>52491552
Fourth for MMIX
>>
>>52491567
Fifth for Java
>>
Reminder: ocaml is the only solution.
>>
>>52491610
>literally Lisp without parens
>>
>>52491552
Thank you for not posting an a/pol/ image.
>>
File: dennis-ritchie.jpg (94KB, 1225x630px) Image search: [Google]
dennis-ritchie.jpg
94KB, 1225x630px
>>52491640
I probably will next time though anon, just to stay balanced.
>>
>There are people in this thread who are learning Javascript instead of PHP
>>
>>52491634
>I have no idea what lisp is
>>
>>52491715
>there are people in this itt thread who fell for the php meme
>>
>>52491715
Terrible b8 m8
>>
How ugly do you think this is? It ain't pretty but it works.

result = ( result = cmath::atan2(y, x)) < 0.0 ? result + 2.0*PI : result
>>
>>52491728
If Javascript is so good, then why it is not?

#rekt
>>
>>52491759
Not nearly as ugly as this.

snprintf(fs,(sizeof(gets(s))+20),"./string %s",s);
>>
RIP Clover
>>
>>52491640
dennis ritchie is a neo nazi
>>
let reset () = Printf.printf "\027[0m";;

let bold () = Printf.printf "\027[1m";;

let red () = Printf.printf "\027[31m";;

let green () = Printf.printf "\027[32m";;

let nl () = Printf.printf "\n";;

let motto () = Printf.printf "OCaml Master Race!";;

let rulez () = Printf.printf "FP rulez!";;

let future () = Printf.printf "You will realize that I'm truth!";;

let texts = [
bold;
red; motto; nl;
green; rulez; nl;
reset;
future; nl;
]
;;

let main () = List.iter (fun f -> f ()) texts;;

let () = main ();;
>>
>>52491915
ocaml i'm an f#
bros?
>>
Goddammit I'm sick of all these fucking segfaults, and gdb's completely useless tracebacks.
Why is this code breaking?

int sendString()
{
malloc(100);
char *s;
printf("enter string to send: ");
unsigned buflen;
scanf("%s%n",s,&buflen);
char fs[buflen + 20];
strcat(fs,"./haskell_string ");
strcat(fs,s);
system(fs);
return 0;
}


As you can see I've applied a lot of duct tape to this code but it still segfaults.
Right now it's segfaulting on the strcat but I can't seem to write this in any way to have it actually work. I tried snprintf and that didn't segfault, but it didn't actually do anything either (it was just appending null characters to the string).
>>
>>52491915
What is the deal with OCaml? Anything you can do with it you can do better with C++ so what is the point anyway?
>>
Reading this
http://blog.llvm.org/2011/05/what-every-c-programmer-should-know.html
>>
>>52491931
If it means anything here's the full file.
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int sendString()
{
malloc(100);
char *s; //Will hold string from user
//char *fs; //Will hold formatted command
printf("Enter string to send: ");
//scanf("%s",s); //Get string from user
//snprintf(fs,(scanf("%s",s) + 20),"./haskell_string %s",s); //format command with string
//char fs[sizeof(gets(s)) + 20];
unsigned buflen;
scanf("%s%n",s,&buflen);
char fs[buflen + 20];
//sprintf(fs,"./haskell_string %s",s);
strcat(fs,"./haskell_string ");
strcat(fs,s);
system(fs); //send string
return 0;
}

int writeString(char *string)
{
printf("%s\n",string);
return 0;
}

int main(int argc, char **argv)
{
if(!argv[1])
{ //No string sent to program
sendString();
}
else
{ //String sent to program
writeString(argv[1]);
}
return 0;
}
>>
https://www.youtube.com/watch?v=4rJEBs_Nnaw
>>
>>52491933
>C++
>better than ocaml
>>
>>52491933
>Anything you can do with it you can do better with C++
except that's not true
>>
>>52491924
no bros with traitors
>>
>>52491987
fine, go make friends with haskell

they're such nice and respectable non-cultist people
>>
>>52491987
F# is friends with ocaml tho. There's even an ocaml type provider for F# letting you use all those ocaml binaries from F#.
>>
>haskell
>non-cultist

You almost had me there.
>>
>>52492002
Oh come on, even an effsharper has to realize that this code is beautiful:
import System.Process
import System.Environment
import Text.Printf

main = do
args <- fmap unwords getArgs
case args of
_ -> do
s <- getLine
let fs = printf "./string %s" s
callCommand fs
>>
>>52492044
fuck does that do?
>>
>>52491761
Because atheists are better than Xbox
captcha: harhar Laugh
>>
>>52491728
>in this in this thread thread
>>
>>52492066
-Takes all the command line arguments passed to the program and turns them into a single string
-if the resulting string is empty, it then takes a line of input from the user and sends it as the command line argument to the 'string' program located in the executable's directory

I'm setting it up right now so there's two programs written in two different languages that do the same thing: print a string if given one, and send a string to the other program if not.
>>
>>52492100
>my mfw face when you responded
>>
>>52492100
ITT:
>Only two types of ppl:
>ppl who are in this thread
>ppl who aren't
>>
>>52492044
Niggas try to pretend to write shit like this and say its ok but when in fact its not ok.

There is a reason tha languages who use parentheses { } are good: Because they are more organized.

Identation languages need to die.
>>
>>52492133
>Only two types of ppl
>ppl who exist
>ppl who don't
>>
>>52492181
>10 types of ppl
>ppl who know binary
>ppl who don't xD
>>
>>52492161
Whitespace is syntactic sugar in Haskell, just like Lua.
In fact the compiler gets rid of the indentation itself. You can manually write without relevant whitespace if you really want to:
main = do {
args <- fmap unwords getArgs;
case args of [
_ -> do {
putStrLn("Enter string to send: ");
s <- getLine;
let fs = printf("./string %s",s);
callCommand(fs);
}
]
}
>>
>>52492161
>Because they are more organized.
Actually for Sepples it's deeper than that. The '}' is arguably the single most important language construct, because in C++ it affords you deterministic resource management.

>>52492181
ITT:
>only two types of ppl
>those who believe they're's only two types of ppl
>those who don't
>>
File: 1394691046880.gif (6KB, 381x178px) Image search: [Google]
1394691046880.gif
6KB, 381x178px
>>52492044
>two lines for printing to screen
>>
>>52492213
>Actually for Sepples it's deeper than that. The '}' is arguably the single most important language construct, because in C++ it affords you deterministic resource management.

Care to explain, anon?
>>
>>52492245
Just learn about RAII anon.

Simple idea.
>pretty huge positive implications.
>>
>>52492224
I'm pretty sure can you directly pipe it, like:
main = do
callCommand <- printf "./string %s", getLine

not entirely sure on the syntax, though.
That being said, this is doing way more than printing to the screen.
>>
>>52492213
ITT:
>only two types of ppl
>those who use "there's" correctly
>those who don't
>>
>>52492044
open System.Diagnostics

[<EntryPoint>]
let main args =
args |> Array.fold (+) "" |>
function
| _ ->
let s = System.Console.ReadLine()
let fs = "./string " + s
printf "%s" fs
Process.Start("cmd", fs).ExitCode


>>52492161
F#:
#indent off

>>52492245
Ignore him, he's bullshitting you.
>>
>>52492263
>ITT:
>>only two types of ppl
>>those who use "they're's" correctly
>>those who don't
ftfy
:D
>>
>>52492260
I am sincerely interested.
What does it do?
>>
>>52492266
*replace _ with ""
>>
>>52492044
Why is ocaml so verbose?

open System
open System.Diagnostics

[<EntryPoint>]
open System
let main(args) =
match (args |> String.concat "") with
| "" -> Process.Start("cmd", Console.readLine() |> sprintf "./string %s")
>>
>>52492285
See >>52492119
It's running an external program with the command line args specified by the user via stdin.

>>52492266
F# is nice, but it just isn't as clean has Haskell. I think if I ever had to make real software I'd use F# (I've played around with it using WPF and C# wrappers, but nothing serious), but Haskell looks better when complete.
>>
>>52492280
>>ITT:
>>>only two types of ppl
>>>me
>>>this guy
>>
>>52492200
I fucking hate this joke so much. Start the count at zero ffs.
>>
>>52492335
Ok
>>
>>52492303
I got you senpai
open System.Diagnostics
[<EntryPoint>]
let main = (String.concat "") >> function
| "" -> Process.Start("cmd", System.Console.ReadLine() |> sprintf "./string %s").ExitCode
>>
>>52491953
it means you're baiting too hard
>>
>>52492365
nice, i was thinking of doing that. But I often think turn functions into functional compositions like that makes things a lot hard to read for normies, so i try to resist the urge.
>>
>>52492415
normies ruin everything :(
>>
It is possible to write C++ programs to be functional as Haskell's?

If so, how?
>>
>>52492213
>they're's

that's impressive
>>
>>52492454
Yes

Very awkwardly
>>
>>52492365
This code is very feminine.
>>
>>52492433
true : (. But that's honestly my favourite thing about F#. You can still write nice code that even normies can read and find appealing.

I'm also hesitant to use functional composition like that because it makes my functions much less flexible. I'll often find I want to add an extra argument later or some shit and need to unwind all the composition stuff.

Sometimes it's sexy as fuck though
>>
Could someone point me to a good SDL tutorial which uses C
>>
>>52491715
i can't run PHP in a browser, silly anon
>>
>>52492476
38% of F# programmers are females, fact.

https://codebase.org/the_great_fsharp_survay_2015
>>
>>52492454
using C++11 lambdas can come pretty close. but that's just one tool in C++'s bag of paradigm tricks anon. if functional is you're goal, you should probably go with a pure FP language, not a multi-paradigm one.

>>52492468
no you're impressive anon
>>
>>52492044
import System.Process
import System.Environment

main = do
args <- getArgs
when null args $ callProcess "./string" args
>>
>>52492531
>if functional is you're goal, you should probably go with a pure FP language, not a multi-paradigm one.
Worst programming advise I've ever read. The only FP languages worth your time are multi paradigm ones.
>>
>>52492513
That's why F# programs looks so gay.
>>
>>52492544
>chkd
glad to expand you're event horizons then anon.
>>
>>52492539
>null
lol
>>
>>52492552
Because it's based on a god damn camel
>>
>>52492563
>on the internet no one knows you're a supermassive black hole.
>no one
>>
>>52492595
S-steve?
>>
>>52492539
This doesn't do the same thing at all.
>>
>>52492595
>>52492601
kek
>>
>>52492601
D.. dad : (?
>>
if ($id == 1 || $id == 3 || $id == 6 || $id == 12 || ...) {
do stuff;
}


Is there an easier way to do this in PHP? Something like:

$array = {1, 3, 6, 12, ...};
if ($id is in $array) {
do stuff;
}
>>
>>52492629
S-sister?
>>
>>52492629
>>52492643

This throws an exception in my tree implementation
>>
>>52492643
So your sister is your daughter? Kek
>>
>>52492637
check out in_array(val, $arr)
>>
>>52492637
$array = {1, 3, 6, 12, ...};
for (int i = 0; i < $array[i].size; i++){
if ($id == $array[i]) {
do stuff;}
}
>>
>>52492681
On my mother's side ;)
>>
>>52492697
Instead of
i < $array[i].size


please read
i < size.$array
>>
>>52492513
how so?

Is it some easy language or something?
>>
>>52492729
-size.$array <= i
>>
>>52492732
10 F# programmers, 4 of them shave their legs and post in trap threads. another isn't sure what they sexually identify as.

brings it to around 38%
>>
>>52492732
no, I'm joking. The link is fake. Women are terrible programmers.

But I did read a study years ago that suggested that men and women ranked much more equally in college for classes in learning haskell, compared to learn C or Java. The theory was women did better because both genders were largely new to Haskell, were as a lot of men would have learned C or Java as a hobby before starting college.
>>
>>52492681
My father's wife's daughter's brother is also my sister's mother's husband's son's daughter's aunt.
>>
>>52492775
... anon

that doesn't make them girls
>>
>>52492787
What if men are just better suited to procedural logic and OOP?

Example: Bitches love lisp
Bitches hate java
Bitches include whiny, effeminate men and actual bitches
Coincidence?
>>
>>52492833
Lisp is procedural and OOP
>>
>>52492833
Everyone hates Java. The only programmer who don't are ones who don't know many other languages. Like, one or two others.
>>
>>52492862
Java is the second language I'm learning and I hate it already.
>>
>>52492862
I know lots of programming languages, and I like Java. It's not my favorite language, but it's very useful.

It's faster than a scripting language, everything you do is very explicit and readable, and it has a large ecosystem so you can usually import a library to solve your problems. It also ports to most platforms very easily.
>>
>>52492862
>Everyone hates Java
Talk for yourself.
>>
>>52492923
And yet you have stuff like C# that is superior in every way. To know C# is to hate Java. I don't think i've ever met someone who knows both pretty well and prefers Java.
>>
Well I've duct-taped my way back to the start, and I still can't fix these damned segfaults.
int sendString()
{
char *s;
printf("Enter sstring to send: ");
scanf("%s",s);
char *fs;
sprintf(fs,"./string %s",s);
system(fs);
return 0;
}


Anyone have any idea why this code has more segfaults than actual working function calls?
>>
>>52492948
C# is to F# what Java is to C#
>>
>>52492923
>very explicit and readable

Would you mind posting some of your Java? Not trying to troll or anything, just I have never seen Java code where the explicitness has aided in readability.
>>
>>52492941
That's "Speak for yourself" Prajeet.
>>
File: 1452909465497.jpg (45KB, 331x331px) Image search: [Google]
1452909465497.jpg
45KB, 331x331px
I want to start using GitHub and upload projects there, but I'm afraid that I will fuck up, do something wrong, and be made fun of.

What should a GitHub newfag know before starting using it? I know the absolute basics and how to use Git already.
>>
>>52492948
The difference between the two languages is very small. I'm very skeptical that a person could like C# and dislike Java.
>>
>>52492941
No, I hate Java too, friend.
>>
>>52492862
i came from python to java and i didnt like that declaring variables
especially in java it seems that you have to write everytime the same word three times

python is really comfy language
>>
>>52492966
agreed.
>>
>>52492975
Not PooInLoo, I'm actually Brasilian. Sorry to not speak it propperly. English is my third language besides Português and Deutsche, anon.
>>
>>52492797
Oh, how naive you are, little anon.
>>
>>52492997
otherwise its fine
>>
>>52492993
>The difference between the two languages is very small.
It's not though. There's piles of broken shit and horrible design decisions in Java that are fixed in C#.

>I'm very skeptical that a person could like C# and dislike Java.
You're talking to someone that does.

>>52493008
You're C# isn't very good either, or else you wouldn't be saying such things.
>>
>>52492980
Careful with personal information and hard-coding credentials.

If people make fun of you, hopefully they'll explain why what you wrote is shit so you can learn.

Antagonizing people is basically the best way to get information from them.
>>
>>52492973
I would but most of the Java code I've written is proprietary.

Java code is very readable in my opinion because the language's entire philosophy seems to be safety and explicitness. A line of code will be verbose instead of cryptic and short, and it's hard to write code that does something other than what it says it will do. There's not much ambiguity in the language.
>>
File: CHECK EM.png (37KB, 987x648px) Image search: [Google]
CHECK EM.png
37KB, 987x648px
r8
pls no >mutable
>>
>>52492965
#define BUFFSIZE 4096

void sendstring()
{
char cmd[BUFFSIZE] = "./string ";
fgets(cmd + 9, BUFFSIZE - 9, stdin);
system(cmd);
}
>>
>>52493134
The problem with this is that it sets a hard limit on how long the string from stdin can be. I don't want to have to do that. If it's literally impossible to do this any other way I guess I can deal with it but still.
>>
>>52493151
and it actually wastes a lot of memory
char buffers are only acceptable of they are used for, duh, buffering
>>
>>52492966
more like F# is to OCaml as Java is to C# 8^)
>>
>>52493220
>is to OCaml
utterly meaningless

it could be fucking perfect and it'd still pale in comparison
>>
>>52493244
please, there's no such thing as a perfect language ~
>>
>>52491552
Learning haskell
>>
>>52493043
c# has more features i guess, but i really enjoy java for its simplicity - it kinda reminds me of c
the only fucking braindead thing about it is the fact that unsigned ints dont exist
but atleast its cross platform
>>
>>52493114
what does the checkem function do?
>>
>>52493277
Signed integers are not portable
>>
>>52493050
>Careful with personal information

Should my GitHub account have any connection to my real identity? Why or why not?
>>
>>52493276
Enjoy writing 'beautiful, and 'elegant' get monads
>>
>>52492965
>scanfing into unallocated memory
GEE, WHAT COULD GO WRONG. On loonix systems there's a "a" modificator for the format string ("%as") that does what you want.
>>
>>52493287
guess
>>
>>52493256
You clearly hasn't programmed in JavaScript, has you?
>>
OCaml is literal fire desu
https://youtu.be/9GJd1hLWPbM
>>52493276
nice
>>52493277
>the only fucking braindead thing...
oh no, there are a lot more...
how about not having value types?
>>52493292
not if it's your first, for sure. don't want to fuck up something and have that publicly linked to you. if you generally get a lot of stars or just put a lot of impressive projects it's fine though.
>>
>>52493276
hows it going?
>>
>>52493289
i dont need to care about memory representation if im wroting high level code
and if im not why would i use java instead of c++ anyway
>>
>>52493295
Why so bitter anon?
>>
>>52493114
Were you supposed to get dubs, anon?

Kek.

Check my quads.
>>
>>52493306
it returns the number of rightmost recurring digits and the digit itself?
>>
>>52493310
well memed

>>52493317
i actually think it adds to its elegance:^)
>>
>>52493333
but i dont want to
>>
>>52493333
If this is actually a script, feel free to post it for us, anon.
>>
>>52493333

Lord jesus look at those repeating digits
>>
>>52493333
d-did you just hack 4chan?
>>
>>52493333
MOOOOT
>>
>>52493327
because i tried and failed and ended up with a 50 line monster that reads from a binary file and packs into a 'struct'
>>
>>52493339
*slow clap*

>>52493333
slow board
>>
>>52493333
chekt
>>
>>52493321
It's going alright. It's really fun.
This thread's a lot better than the last few.
>>
File: () =〉 You.png (3KB, 282x63px) Image search: [Google]
() =〉 You.png
3KB, 282x63px
>>52493333
did you even look at the image
>>
Guys I'm having a brainfart, why does this segfault?


#include <stdio.h>

int main()
{
char *inp;
scanf("%s", &inp);

printf("%s", *inp);

return 0;
}

>>
>>52493395
No, it was just an excuse to shitpost.

Sorry, anon.
>>
>>52493423
You overwrite a random place in memory with your scanf.
>>
>>52493366
so like this?

checkem :: Int -> Maybe (Int, Char)
checkem x =
case filter (\i -> length i > 1) . group $ show x of
[] -> Nothing
xs -> let digits = last xs in
Just (length digits, head digits)
>>
>>52493445
i'll forgive you

if this post gets dubs
>>
>>52493423
You need to allocate memory for inp. Either use a char array, or use malloc.
>>
>>52493423
You're casting a pointer to a pointer. It's already a pointer so you don't need to cast it.
Also you're storing data in unallocated space.
#include <stdio.h>
int main()
{
char *inp = malloc(8192);
scanf("%s", inp);
printf("%s",inp);
return 0;
}
>>
>>52493459
Probably, where's the char coming from though
>>
>>52493451
the stack*
>>
guys
check my singles
>>
>>52493472
that's the digit. I'm converting it to a string as a lazy way to compare the digits

> checkem 12459991
Just (3,'9')
>>
>>52493423
allocate memory for inp

printf("%s", inp);
>>
Does /g/ have any experience in getting a gf?

I'm finding this problem quite difficult.
>>
>>52493423
>why does this segfault
Because it's C? That's the C program for segfault anon.
>>
>>52493460
>#rekt

>>52493487
>#chkd
>>
>>52493500
print(gf);
>>
>>52493500
I have experience in getting a bf, does that count?
>>
File: 1452449294308.png (401KB, 500x708px) Image search: [Google]
1452449294308.png
401KB, 500x708px
Quick, list the non-autistic memestream languages everyone should learn.
>>
>>52493500
>Since you got dubs
You'll need to shower, shave, have clean clothes.
You'll need a job, and preferably a car.
Find some social venue where grils hang out.
Talk to them, and don't be an aspie about it.

Eventually you'll land one m8.
>>
>>52493500
yes anon. you must fuck a girl several times before she will agree to be your gf. ignore her during this time, but still give her attention when you feel she deserves it. you must also fuck better and be more attractive than the other guys she is currently fucking (yes she is fucking other guys if she is single, get over it).
>>
File: 1448224356554.jpg (41KB, 390x390px) Image search: [Google]
1448224356554.jpg
41KB, 390x390px
>>52493451
>>52493462
>>52493465
ty
>>
>>52493544
>chkd
C++, Python, BASH.
>>
File: 1452037061036.jpg (55KB, 379x528px) Image search: [Google]
1452037061036.jpg
55KB, 379x528px
I really need a shit and it's sticking out halfway but I need to finish this program I'm working on, anyone else know this feel?
>>
>>52493550
bullshit
>>
>>52493568
time for you to learn how to poopsock, anon
>>
>>52493500
Have good hygiene and posture, and walk up to a girl and say hi.
>>
File: 1452351989969.png (221KB, 888x900px) Image search: [Google]
1452351989969.png
221KB, 888x900px
What math books does /dpt/ recommend?
>>
>>52493500
Don't. Hooked up with this chick a decade older than me on Saturday. hasn't stfu up since. on about 'relationships' and all that bullshit.
>>
>>52493648
math is for nerds
>>
>>52493648

>>52493683
he's right
>>
>>52493648
What is your level of mathematics?
>>
File: marichan.jpg (53KB, 907x718px) Image search: [Google]
marichan.jpg
53KB, 907x718px
>>52493648
>math
>>
File: ff.jpg (165KB, 1280x720px) Image search: [Google]
ff.jpg
165KB, 1280x720px
>>52493726
Um, lets see. I can add, minus, multiply, and divide. Um, I understand fractions and basic geometry, and um, I understand simple algebra and I know what prime numbers are.

As you can see, I don't have much to learn.
>>
File: BUb3B8g.jpg (83KB, 625x621px) Image search: [Google]
BUb3B8g.jpg
83KB, 625x621px
>>52493603
>>
>>52493568
just squirt some warm water at it
>>
>>52493648
khan academy
>>
How can I get the type of some value in Haskell?

I want to use it in a case statement but it looks like there isn't actually a way to do that.
>>
>>52493568
>not programming from a toilet seat
fucking casuals
>>
File: 1451683583776.gif (2MB, 400x600px) Image search: [Google]
1451683583776.gif
2MB, 400x600px
making snake in chip-8 lads

pong is boring, just a few conditionals, shifts and randoms
>>
>>52493915
Did you ever get it finished?
>>
File: ijj.jpg (68KB, 1280x720px) Image search: [Google]
ijj.jpg
68KB, 1280x720px
>>52493915
No you can't make snake, I'm making snake.
>>
>>52493928
make pac man. ;)
>>
>>52493915
does it has true pong physics ?
>>
>>52493907
Typeable
>>
>>52493810
That's quite a little. Too little that I could actually give any good suggestions. Sorry mate.
>>
File: 1451683513443.gif (2MB, 400x225px) Image search: [Google]
1451683513443.gif
2MB, 400x225px
>>52493925
No, but what was left was the same shit. A few conditionals (checking x y to see if you should bounce, resetting the rand value to determine angle bouncing back, XORing sprites to update them, variable speed through delay, etc)

I can't be bothered putting effort into something simple. Snake at least has nodes to work with and shifting them all around as you move. No time wasted on fancy gui this time, just a loading screen and snake

>>52493928
b-but I'm making snake

>>52493952
true?
>>
>>52493907
>I want to use it in a case statement

For what reason?
>>
>>52493977
the ball bounce direction is dependent on where the ball hit the bar.
>>
File: iio.png (614KB, 640x890px) Image search: [Google]
iio.png
614KB, 640x890px
i want variables in my game to change at certain music pitches.

how do i do this?
>>
>>52491552
Hey /dpt/, how do I find the entry point of a large open-source program? i.e. the source that includes all the other files and has the main function?
>>
>>52493333
post script my nigga
>>
>>52494021
Use YIN
>>
File: 1451683650441.gif (1MB, 500x281px) Image search: [Google]
1451683650441.gif
1MB, 500x281px
>>52494019
oh that would be simpler then, rather than using random values, I check the relative y position of the paddle and ball if a collision occurs. At a paddle length of 4, I can store the possibilities in 2 bits. But yeah, pong is still too simple for my tastes
>>
File: Godel-Escher-Bach-edriverrun-05.jpg (80KB, 960x540px) Image search: [Google]
Godel-Escher-Bach-edriverrun-05.jpg
80KB, 960x540px
>>52493648
>>
>>52494028
just grep int main
>>
>>52494028
main.cpp
>>
>>52494021
fourier transforms
>>
>>52493907
post code. the answer is either pattern matching or to not do what you're doing.
>>
>>52494060
those look like scary words

and the graphs on the wiki page look even scarier

https://en.wikipedia.org/wiki/Fourier_transform

can you explain it like i'm a retard?
>>
>>52494084
before FT: graph is how the sound looks - how to move the speakers (how computer perceives it)
after FT: graph is pitch on x axis vs loudness (how humans perceive it)
>>
https://www.youtube.com/watch?v=Mk3qkQROb_k
>Java programmers
>>
>>52494006
>>52494079
It's part of my program's argument parsing. Basically I want to do `some block of code` if there are arguments, and `other block of code` if there aren't.
I figured the easiest way to do it would be to case the args itself with Nothing and _, but that doesn't work.
import System.Process
import System.Environment
import Text.Printf

main :: IO()
sendString :: IO()
writeString :: String -> IO()

sendString = do
print "Enter string to send: "
s <- getLine
let fs = printf "./c_string %s" s
callCommand fs

writeString str = do
print str

main = do
--args <- fmap unwords getArgs
case getArgs of
Nothing -> do sendString
_ -> do
args <- fmap unwords getArgs
writeString args


This code obviously fails.
>>
File: sine_wave.gif (6KB, 446x304px) Image search: [Google]
sine_wave.gif
6KB, 446x304px
>>52494084
this probably isn't a good explanation for a retard, and i'm no expert here so i might be wrong, but

the simplest form of a sound wave is a sine wave (pic related). this is formed by the function y = sin(x). hopefully you learned about this function in high school at some point. this can be altered to have higher pitch or whatever by doing things such as y = 2 + sin(x).

sound waves in nature are not always this simple, however. they are formed by many sine waves combining, forming a very complex function that you can't really derive pitch from. fourier transforms basically transform the complex sound wave into its sine wave constituents, allowing you to determine things such as pitch.
>>
>>52494202
are you sure that _ isn't "any value"
try ""
>>
>>52494227
_ is 'any value', but the problem is that (im pretty sure) getArgs wouldn't return anything if there's no args. I'll try "" though.
>>
>>52494202
It's not as simple as that.
getArgs
returns a list of byte strings -- you'll have to check against its length and use
maybeRead
and so on.
>>
>>52494249
>>52494227
Well shit, that worked!
Thanks anon!
>>
>>52493333
I'm happy about this resurgence of scriptgets, they haven't been around enough lately
>>
What are you drinking and listening to while programming?

Just poured myself a tall glass of the finest house orange juice listening to https://www.youtube.com/watch?v=4ZHwu0uut3k. About to start chip-8 snake, I've got most of the design down during downtime at work.
>>
>>52494202
args <- fmap unwords getArgs
if null args then
sendString
else
putStrLn args
>>
>>52494341
I'm drinking milk and listening to my bf play dragons dogma
>>
>>52494384
gay
>>
>>52494341
mostly red wine and taylor swift.
>>
>>52494393
ikr it looks dumb
>>
>>52494202
try
anon = do
args <- getArgs
case args of
[] -> sendString
strings -> writeString (unwords args)
>>
>>52494341
binged on bourbon, now drinking water. listening to the clacking of my coworkers' keyboards.
>>
>>52494432
why not
anon = do
case getArgs of
[] -> sendString
strings -> writeString (unwords strings)
?
>>
import std.stdio;

void main(string[] args)
{
writeln("Apologize Britcucks!");
}
>>
someone who knows more about crypto than me, should i use sha1 or md5 for checksums (or something else entirely?)
>>
>>52494470
md5 is awful, use sha-2
>>
>>52494469
We're sorry Orange Prince
It's the damn scots
>>
>>52494469
Bloody scots
>>
>>52494463
That wont compile because getArgs :: IO [String] . getArgs is a computation that does IO and then returns a string. We need to be talking to the argument string itself. Using <- tells the compiler to sequence the actions, saying "when getArgs is done, do this case statement on the result."

http://adit.io/posts/2013-04-17-functors,_applicatives,_and_monads_in_pictures.html
>>
two programs do the same thing
one in haskell, one in c

C source code length: 573 bytes
Haskell source code length: 302 bytes

C binary length: 7872 bytes (7.8KB)
Haskell binary length: 1546712 bytes (1.5MB)


damn do I love haskell, but it really is a meme
>>
File: 1452351559589.gif (131KB, 600x338px) Image search: [Google]
1452351559589.gif
131KB, 600x338px
>>52494469
What is it we need to apologise for, anon?
>>
>>52492303
>ocaml
>import
Choose one.
>>
>>52494470
Resident cypherpunk here. Neither. Or this >>52494479 anymore because of length-extension and because we have better things now anyway.

You should use BLAKE2b. It's more secure than both of those and SHA-2, and faster than all of them.

https://tools.ietf.org/html/rfc7693

There's a convenient fast implementation in libsodium, or on the official site. https://blake2.net/
>>
>game server
I assume I should be using udp for connections?
How do I handle handshake/login? Roll my own half-assed stateful connection from udp? How do common firewalls/NAT handle client-initiated udp connections?
>>
>>52494712
Just use ocaml.
>>
File: 1434820143796.jpg (1MB, 1687x1200px) Image search: [Google]
1434820143796.jpg
1MB, 1687x1200px
Ano... what are constructors for senpai?
>>
File: 42.png (17KB, 1172x391px) Image search: [Google]
42.png
17KB, 1172x391px
Umm I'm new to this shit,is this good code,and is it correctly written
>>
>>52494738
Initializing an object to a valid state.
>>
>>52494776
Girly code/10
>>
>>52494696
i'd use it, but most distros don't even have a package for it yet so using it over something else (right now) would force people to manually compile it and shit. if i ever make a distro with this package manager then i'll include blake2 though
>>
File: loop.png (10KB, 404x363px) Image search: [Google]
loop.png
10KB, 404x363px
>>52494800
Well I am a girl soo
>>
>>52494776
Always share actual text instead of images.
int rightNumber = 42; Assign when you declare, if possible
Check your braces, for the love of god.
>>52494858
While loop is more idiomatic than do-while, prefer it.
Avoid continue if possible.
You increment a twice, avoid code duplication.
while (a < 20) { 
if (a != 15) {
printf...
}
a++;
}
>>
File: primer.jpg (2MB, 4160x2340px) Image search: [Google]
primer.jpg
2MB, 4160x2340px
Just showed up
>>
>>52494631
Not a Haskell programmer, but there must be some kind of static linking going on in the Haskell case to bloat a tiny program like that so much. 1.5MiB is just ridiculous, it must be statically linking the stdlib or something.
>>
>>52494941
Hmm I thought my brace indentation was fine anyways thanks for the feedback
>>
>>52494969
what is it going to teach you?
c++ syntax<
>>
>>52494776
>>52494858
What text editor are you using and what are you using to compile?
>>
>>52494969
I don't know any of those names.

Burn the book.
>>
>>52494969
why did you buy an anatomy book?
>>
>>52495055
It should be:
int main (void) { 
while (...) {
if (...) {
do_this();
}
do_that();
}
}

Also consider using a for-loop:
 for (int a = 10; a<20; a++) { 
if (a != 10) {
printf...
}
}

which may read nicer to some people.
Other than that it looks really good - keep at it!
>>
>>52495088
Dev c++ I'm using a toaster so Visual studio was out of the question
>>
Running through project euler, trying to learn haskell.

When I get stuck, I find myself writing imperitive-style pseudo-code, then trying to translate late it to haskell, which never works.

Do I just need more practice? Do you guys get the same feels? Do you translate those terrible imperitive thoughts in your head into beautiful recursive functions?
>>
>>52494969
will you read that till next christmas?
>>
File: ZFK9zQO.png (22KB, 1699x90px) Image search: [Google]
ZFK9zQO.png
22KB, 1699x90px
lmao best compiler errors
>>
>>52495197
>errors in your code
Commit Count Dooku immediately
>>
>>52495233
it was just a mistake i made when copy-pasting something, no need to sperg
>>
>>52495136
I try to think in terms of list operations. Which are you having problems with, anon?
>>
>>52495263
>it was just a mistake
No. You are a mistake.
You've proven your incompetence. Begone.
>>
>>52495110
Welp did a few fixes hopefully this look better
#include <stdio.h>
#include<conio.h>

int main (void){

int rightNumber = 42;
int enterNumber;
int numberOfTries= 0;

while(numberOfTries<3) {
printf("Please enter number");
scanf("%d", &enterNumber);

if (enterNumber == rightNumber){
printf("YOU GOT IT\n");
break;
}

else if(enterNumber!=rightNumber){
printf("WRONG NUMBER\n");

numberOfTries = numberOfTries +1;
}
}

getch();
}
[\code]
>>
>not needing to repeat yourself is overrated
>these are the kinds of thing syou learn with experience
What did he mean by this?
>>
H-how do I build a good library for competitive programming?
>>
1. open file in vi
2. Type: gg=G
3. Save and exit
>>
>>52495328
"Hi, I am a retard"
>>
File: MnQ660M.png (17KB, 474x450px) Image search: [Google]
MnQ660M.png
17KB, 474x450px
>>52494858
This bracket style makes me uncomfortable.
>>
>>52495355
W-what are you talking about?
>>
>>52495308
still terrible, see >>52495362
>>
#[repr(C)]
struct ClientInitPacket {
magic_number: [u8; 4],
protocol_version_min: u32,
protocol_version_max: u32,
}

#[repr(C)]
struct ServerInitPacket {
session_id: u64,
protocol_version: u32,
public_key: [u8; 256],
}

#[repr(C)]
struct StandardPacket {
command_id: u64,
session_id: u64,
data: [u8, 496],
}
}

Fuck, designing a wire protocol is hard.
The data in the StandardPacket would obviously differ depending on the command. That's kind of easy, it's the handshake bit that's bothering me as that's hard to change in a backward compatible way. Anyone see any obvious issues?

The server sends its public key purely for fields like 'password'. I don't forsee any use for a client public key and it would be easy enough to add it later as part of a StandardPacket.
>>
File: sFFT.png (123KB, 700x398px) Image search: [Google]
sFFT.png
123KB, 700x398px
>>52494084
If you have a time dependent function, FT will convert it to a frequency dependent one.
>>
>>52495296
right now I'm trying to find 3-digit factors of a given number. (i.e. 38520 = 120 * 321)

so I'm thinking:
Try to divide number by a decreasing increment
If it succeeds, then see if result is another 3 digit number
if result is another 3 digit number, store both in list
else just return an empty list
resume decreasing increment until you reach 100


But that's not at all how haskell works. Instead, I need something more like

nDigFactor :: (Integral a) => a-> [a]
nDigFactor 1 = []
nDigFactor n
| otherwise = factors ++ nDigFactor (n `div` (head factors))
where factors = take 1 $ filter (\x -> n `mod` x == 0) [999,998..100]
>>
>>52495382
indentation languages win again :^)
>>
>>52495308
You could just use else instead of else if, since it'll either be equal to the correct number or it won't
>>
>>52495489
Or they could stop being a 'tard and use superior Allman-style.
>>
>>52495505
Or you could stop being a tard with OCD.
>>
>>52495454
This is how I thought about the problem:
I want numbers bigger than 100. And filter out numbers that are not factors of the given number. 

and this is what I wrote:
p a = filter (\x -> a `rem` x == 0) [100..a]
>>
I want to learn Python. Is netbeans a good idea? what online course you reccomend? I have some java, asp.net and php knowledge.
>>
>>52495634
Thanks anon

Trying to use a=a+1 logic is getting me in trouble. I'll try to focus on list logic.
>>
How do I do secure key-exchange, given that the two users have not pre-exchanged public/private key pars by some other (secure) mechanism?

All I want to do is send a 256byte password hash, without exposing myself to replay attacks.
>>
>>52495634
>'rem'
>>
>>52495698
>netbeans
no anon
you aren't learning java, stay away

most of the time a text editor with syntax highlighting is just fine, otherwise use PyCharm or Spyder
>what online course
they're all pretty shit, most of them are just holding your hand or spoonfeeding
read a book, or go through an online course and then try to make something yourself
the information sticks with you better when you make something that actually has a use/application

https://automatetheboringstuff.com/
>>
>>52495750
Client sends (hash xor clientsecret)
Server sends ((hash xor clientsecret) xor serversecret)
Client sends (((hash xor clientsecret) xor serversecret) xor clientsecret) == (hash xor serversecret)
Server calculates ((hash xor serversecret) xor serversecret) == hash

Generating secure secrets and password hashes is left as an exercise for the reader. But iff both your secret and hash are cryptographically secure, and you do not reuse the secret then hash^secret is shannon-secure.
>>
>>52495750
Use a library in whatever language you're using.

Don't roll your own security.
>>
>>52495818
>yes goyim, use our perfectly safe non-trojan security library
>it's obfuscated for your own benefit
>>
>>52495833
>yes retard, you're smart enough to implement your own security protocols
>us jews, I mean hackers, surely won't steal your information!
>>
>>52495858
>non jews are retards
fucking racist
>>
>>52491552
>yes retard, you're smart enough
10/10 my life story
>>
who laravel here
>>
>>52495813
That's fucking retarded
Attacker can easily break that shit if they can intercept the full handshake.
Client's second message ^ server's message gives you the clientsecret.
clientsecret^ client's first message = plaintext.
>>
>>52495877
>>52495858
look at me being a dumbass and responding to the OP because I didn't have the reply highlighted
>>
Anyone who tells your to roll your own encryption/security handshakes is either malicious or ignorant.
>>
>>52495911
>yes retard, you're smart enough
>>
Is self documenting code a meme?
>>
>>52495784
thank you anon
>>
>>52496038
I believe so. At the same time, you must write you code as if no one is going to read the comments.
>>
File: snake.jpg (15KB, 769x409px) Image search: [Google]
snake.jpg
15KB, 769x409px
It begins
>>
>>52494978
Haskell compiles to C-- before it goes to binary, so there's actually an entire C-- interpreter sitting within the executable of every Haskell program. This is why, unlike C, Haskell code can't be directly disassembled.
>>
>>52496191
C-- isn't interpreted. It's compiled to native code.
>>
>>52496211
Correct, but Haskell itself is (C-- acts similar to the 'bytecode' of Java and Lua). So while C-- is compiled to native code, Haskell isn't, so every Haskell-based executable is really just a Haskell emulator written in C--.
>>
>>52496191
>>52494978
I imagine if anon compiles with the -dynamic flag, he would get a much smaller binary size.
>>
>>52491715
>There are people in this thread who are learning PHP instead of C.
>>
>>52496249
>The back end of the compiler transforms Core code into an internal representation of C−−, via an intermediate language STG (short for "Spineless Tagless G-machine"). The C−− code can then take one of three routes: it is either printed as C code for compilation with GCC, converted directly into native machine code (the traditional "code generation" phase), or converted to LLVM virtual machine code for compilation with LLVM. In all three cases, the resultant native code is finally linked against the GHC runtime system to produce an executable.
Haskell is compiled like C or C++, not Java and Lua.
>>
>>52496250
Brought it down to about 24K, which is still almost three times the size of the C binary.
>>
whats the quickest way to get a VS like experience on GNU/Linux? i just want to jump in and write some quick and dirty C++ without spending a week configuring emacs and spending the better part of the lecture writing makefiles
>>
>>52496266
>There are people in this thread who are learning any language instead of OCaml
>>
>>52496278
QtCreator
>>
>>52496278
NetBeans or Eclipse is probably your best bet.
>>
>>52496285
>There are people in this thread learning OCaml.
>>
>>52496278
vim
>>
Rate my Haskell code, /dpt/!

https://gist.githubusercontent.com/Gamerdog/af13d5f4bff606fa39fb/raw/33e0bf0a4c17d52e3cb89ad20fe153eaff42ff7e/strings.hi
>>
>>52496278
Vim + Clang
>>
i prefer 1tbs
>>
>>52496289
even if i dont want to write GUI applications?

>>52496293
which one and why?

>>52496303
>>52496336
>thinking vim is any better than emacs in this regard
>>
>>52496449
>which one and why
Doesn't really matter. Both are extensible IDEs with great plugin support. Both look like ass. I've had positive experiences with both and use neither. Pick your poison.
>>
>>52496449
QtCreator is also good for non Qt programs.
>>
>>52496449
>being the plebest
>>
>>52496301
>There are people in this thread who still don't know OCaml
>>
>>52496480
are there any plugins you would recommend for the best experience on either IDE?

>>52496548
if i want to work on a proper project on *nix ill use emacs, but right now im not doing much programming aside from the odd bit of python on linux and i cant be fucked manually doing shit an IDE can do for me.
>>
>>52496560
>There are people in this thread who still think OCaml is the best language
>>
Does anyone know how to change the autoidentation rules of vim? In C it tries to do this shit:
    switch (lua_type(L,i))
{
case LUA_TNUMBER:
{
M_APM x=Bnew(L);
m_apm_set_double(x,lua_tonumber(L,i));
lua_replace(L,i);
return x;
}
case LUA_TSTRING:
{

There is no reason for the tab after the case to be there. I want to fix this shit.
>>
File: 1452843995301.jpg (55KB, 300x316px) Image search: [Google]
1452843995301.jpg
55KB, 300x316px
>mfw trying to learn my first language, C

It gets easier, right?
>>
>>52496565
>being terminally retarded
>>
>>52496594
Yes, definitely - especially considering you're learning C first. Everything else will be a lot easier once you have C under your belt.
>>
>>52496574
>There are people in this thread who shit on OCaml without even trying it and pretend to be expert on the topic
>>
>>52496597
look, i dont give a flying fuck about your little dick waving contest with your 1337 h4xx0r fonts and your tiling window managers, ill use whatever works til i can be arsed to learn lisp so i can have a proper emacs setup without having to debug my editor.
>>
>>52496594
>he fell for the cmeme!
>>
>>52496584
Why the fuck do you have braces in a case statement? Do you have literally no idea how switch statements work in C?
>>
>>52496622
Someone add a computer_science_graduate.jpg to this post!
>>
>>52496660
Not my code man.
>>
>>52496661
>le funny /g/ memes XD
youre the reason i only come here for the /dpt/
>>
>>52496660
Typical /dpt/ "c programmer", literally don't even know how C case tags work and yet try to lecture people about it.
>>
>>52496680
You should go back to reddit and stay there, then. It's superior in every way after all.
>>
File: scope.png (449KB, 940x587px) Image search: [Google]
scope.png
449KB, 940x587px
>>52496660
>Why the fuck do you have braces in a case statement?
>>
NEW THREAD

>>52496734
>>52496734
>>52496734
>>
>>52496584
emacs has a setting called syntactic indentation which does the exact same thing you described, maybe vim has something similar
>>
>>52496718
>le reddit jokes xd
nah, its you who belong on reddit, go circlejerk over there like the autist you are
>>
>>52496613
nigga like 1/2 my github repos are ocaml and almost every single personal project i've done in the past year is too
https://github.com/nv-vn?tab=repositories
not even kidding, i've done an interpreter and two compilers + gone through a book doing the exercises in OCaml, written my own JSON/XML library, a game engine, a text editor, an IRC bot, a text editor, a build system, an alternative standard library, and a file uploader, not to mention my experiments with MirageOS and eliom
pretty sure i don't "shit on OCaml without even trying it and pretend to be expert on the topic"
>>
>>52496594
If you learn C and Haskell first, everything else will fall into place
>>
>>52496798
>half of it is forked
>the other half is 5 lines of rubbish code
Sure showed us!
>>
>>52496584
:set tabstop=4
>>
>>52496584
oh I misread that. Never seen that before, sorry.
>>
>>52496584
>>52496746
It's :set cino+=l1. But it only works if you put the brace on the same line as the case label. The only way to make it work with braces on the next line is to turn off all indentation after a case. This seems to be a corner case that vim missed.
>>
In some lots of math problems I need to divide integers by integers, and due to the math the result is guaranteed to be an integer.

What's the best way to go about this in haskell? Currently I'm using:
round $ (fromInteger x)/(fromInteger y)


but it feel so much more clunky than x/y
>>
>>52497279
try
div x y
>>
>>52497381
wow, that helps. thanks anon.
Thread posts: 348
Thread images: 32


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
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.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.