[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: 32
File: 1452547354514.jpg (31 KB, 309x400) Image search: [Google]
1452547354514.jpg
31 KB, 309x400
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 (94 KB, 1225x630) Image search: [Google]
dennis-ritchie.jpg
94 KB, 1225x630
>>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 (6 KB, 381x178) Image search: [Google]
1394691046880.gif
6 KB, 381x178
>>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 (45 KB, 331x331) Image search: [Google]
1452909465497.jpg
45 KB, 331x331
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 (37 KB, 987x648) Image search: [Google]
CHECK EM.png
37 KB, 987x648
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 (3 KB, 282x63) Image search: [Google]
() =〉 You.png
3 KB, 282x63
>>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 (401 KB, 500x708) Image search: [Google]
1452449294308.png
401 KB, 500x708
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 (41 KB, 390x390) Image search: [Google]
1448224356554.jpg
41 KB, 390x390
>>52493451
>>52493462
>>52493465
ty
>>
>>52493544
>chkd
C++, Python, BASH.
>>
File: 1452037061036.jpg (55 KB, 379x528) Image search: [Google]
1452037061036.jpg
55 KB, 379x528
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 (221 KB, 888x900) Image search: [Google]
1452351989969.png
221 KB, 888x900
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 (53 KB, 907x718) Image search: [Google]
marichan.jpg
53 KB, 907x718
>>52493648
>math
>>
File: ff.jpg (165 KB, 1280x720) Image search: [Google]
ff.jpg
165 KB, 1280x720
>>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 (83 KB, 625x621) Image search: [Google]
BUb3B8g.jpg
83 KB, 625x621
>>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 (2 MB, 400x600) Image search: [Google]
1451683583776.gif
2 MB, 400x600
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 (68 KB, 1280x720) Image search: [Google]
ijj.jpg
68 KB, 1280x720
>>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 (2 MB, 400x225) Image search: [Google]
1451683513443.gif
2 MB, 400x225
>>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 (614 KB, 640x890) Image search: [Google]
iio.png
614 KB, 640x890
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 (1 MB, 500x281) Image search: [Google]
1451683650441.gif
1 MB, 500x281
>>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
>>
>>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 (6 KB, 446x304) Image search: [Google]
sine_wave.gif
6 KB, 446x304
>>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 (131 KB, 600x338) Image search: [Google]
1452351559589.gif
131 KB, 600x338
>>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 (1 MB, 1687x1200) Image search: [Google]
1434820143796.jpg
1 MB, 1687x1200
Ano... what are constructors for senpai?
>>
File: 42.png (17 KB, 1172x391) Image search: [Google]
42.png
17 KB, 1172x391
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 (10 KB, 404x363) Image search: [Google]
loop.png
10 KB, 404x363
>>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 (2 MB, 4160x2340) Image search: [Google]
primer.jpg
2 MB, 4160x2340
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
Thread replies: 255
Thread images: 32

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.