/dpt/ - Daily Programming Thread

What are you working on, Sup Forums?

Previous thread:

Other urls found in this thread:

youtube.com/watch?v=E8I19uA-wGY
lmgtfy.com/?q=python while modulo swap algorithm
docs.racket-lang.org/guide/for.html
docs.racket-lang.org/reference/sequences.html
pastebin.com/Wk4x4EnR
pastebin.com/niWcP3Qe
github.com/jon-hanson/parsecj
matt.sh/howto-c
pastebin.com/575cdmp2
thebarchive.com/data/b/image/1516/02/1516021448758.jpg
twitter.com/SFWRedditGifs

first for java

functional design patterns are work arounds for what object oriented programming makes easy to solve

youtube.com/watch?v=E8I19uA-wGY

What do you set your company domain as for personal Java projects? I want to make a HelloAndroid app and this stupid pajeet shit wants a domain and to name my package as com.blah.hello

This thread is pathetic. It is not about programming. It's just a bunch of computers illiterates and freshmen memeing about whatever they just learned.

A quick search shows that most arguments used here are not original and have been copied from some trendy tech blog or other shit site.

The only real programming questions I have seen so far are from beginners(it's fine to be a beginner btw).

This entire site is shit and I don't know why anyone would regularly come here.

So im trying to write a UDP client and server. The problem is that for some reason when my client sends command the first time it works, all consecutive times the first letter is deleted. Also the contents of hello which is a char are filled with garbage characters.

This is my server's loop:
while(1){
if(recvfrom(server_fd, buffer, buffersize, 0, (struct sockaddr *) &clientaddr, &clientsize)tid);
}


and this is my client
while(1){
scanf ("%[^\n]%*c", command);
sendto(sock, command, cmdsize, 0, &serv_addr, addr_length);
printf("command sent\n");
if((valread = recvfrom(sock, buffer, buffersize, 0, &serv_addr, &addr_length))

Thanks.

One of my several personal domain names, naturally.

>giving personal info to the pajeetnet

>where does my char go?
>getchar()
Fucking mystery.

Do you wear tinfoil hats around the house?

starting to like this one, frankly

Thats what I get for googling how to pause my program...

Continuing the fizzbuzzery
val m = Seq(3 -> "Fizz", 5 -> "Buzz", 7 -> "Hiss", 11 -> "Howl")

for (i v} match {
case Nil => i
case xs => xs.mkString
})

The only book I know that teaches FP ""design patterns"" is HTDP. And does anyone actually read that? I feel like the people who pursue fp aren't the kinds of people who memorize """design patterns.""" That's more of an oop thing. The autistic brains of ooplets like to categorize everything so they try to categorize thought too.

Thanks. It's pretty old. I posted for the first time in the beginning of 2016 but it never took off.

keep it up mang, it has potential
don't do it every thread tho, go for once a week or something, so people don't learn to ignore it before it has a chance to start reproducing

Thanks. Will do that.

while(y):
x, y = y, x % y

What is this? (Python syntax)

Sup Forums cool kids club checklist

[x] hate OOP
[x] hate IDEs
[x] use only Haskell
[x] never produce actually useful software (this is important)
[x] wear knee socks
[x] tiling window manager
[x] dark-like-my-soul customized colors
[x] hate popular Linux distributions (because too intelligent for them)
[x] apply this list to self, post results as if anyone cared

y assumes the value of of the rest of the division of x by y
x assumes the value of y

(define (fizzbuzz/custom n mapping)
(for/list ([p mapping]
#:when (zero? (modulo n (car p))))
(cdr p)))


or

(define (fizzbuzz/custom n mapping)
(define filter (compose zero? (curry modulo n) car))

(for/list ([p mapping]
#:when (filter p))
(cdr p)))

Ok smart guy one more question for you,
how come no matter what I do char *hello = "Hello from server";
comes out as buffer: Hello fr��b
?

>while(y):
> x, y = y, x % y
>Python
lmgtfy.com/?q=python while modulo swap algorithm
third link

>not programming
Fuck off.

And while(y) continues until y is zero. It's the Euclid algorithm to find the minimum common divisor.

...

>minimum
>greatest
ftfy

thx

>#:when
>#
>:
At first glance i thought that was a common lisp style keyword but that # is throwing me off. Is this a reader macro or a keyword? What the fuck does it do?
>curry instead of cut
Yuck.

>from first principles
oh lawdy, I thought the n-gate guy was exaggerating

No idea, post full code.

No, only when I'm outside of the faraday cage I've built into my walls.

docs.racket-lang.org/guide/for.html
docs.racket-lang.org/reference/sequences.html

You
#lang racket

(define (fizzbuzz/custom n mapping)
(define ls
(filter-map
(λ (pair)
(match-define (cons m s) pair)
(and (zero? (modulo n m)) s))
mapping))
(if (empty? ls)
(number->string n)
(string-join ls "")))

(define mapping
'((3 . "Fizz") (5 . "Buzz") (7 . "Hiss") (11 . "Howl")))

(for ([i (in-range 1 101)])
(displayln (fizzbuzz/custom i mapping)))

vs the guy she told you not to worry about
val m = Seq(3 -> "Fizz", 5 -> "Buzz", 7 -> "Hiss", 11 -> "Howl")

for (i v} match {
case Nil => i
case xs => xs.mkString
})

server: pastebin.com/Wk4x4EnR
client: pastebin.com/niWcP3Qe

Arguments ive been running are ./server 8080 8081 and ./client 8081 127.0.0.1

Tinfoil (aluminum) is not a good enough conductor to make a Faraday cage. You might want to try putting your head in a bird cage instead.

Yup that confirms it. Racket was a mistake. Just use common lisp.

For scientific programming, Julia is truly the language of the gods.

I'm currently in a graduate class where the problem domain leads to a bunch of nonlinear ODE's that need solving, and this is exactly what Julia is currently amazing at. I can write a macro-based DSL to translate a top level spec to a differential equation that I feed to differentialequations.jl for solving, or feed it to mathematica via mathematica.jl for exact solutions. And I can use interact.jl to vary the parameters with sliders in my Jupyter notebook.

I just automated a big chunk of the class-related work that will be dumped on me in the coming week, which is pretty sweet.

I think that's because in FP it's just so natural. When everything is an expression, you can just refactor any pattern you see into a function and design patterns just become regular functions (or type classes, huh) so there is no ideology to make around them. OOP sometimes requires non-obvious workarounds (I think I stumbled upon some factory pattern when trying to bypass limitations of Java's generics but that was long time ago) and that's where design patterns perhaps make some sense. It's actually stupid that they make sense; I think that only proves that something is wrong with the language. Then there are these trivial patterns that are there only so that brainlets could feel better about themselves for knowing them.

What have you done? You've doomed this thread to death by smug FP weenieposting!

>functional design patterns are work arounds for what object oriented programming makes easy to solve

I'd love to see you implement parser combinators with OOP.

github.com/jon-hanson/parsecj

Right, so first of all do const char* thing = "string", string literals are immutable.
Then you have both strlen and sizeof(thing). I'll assume that you have already figured out that sizeof does not work how you expected, but will tell you why anyway. sizeof returns the size of an object, in case of a pointer it will probably be 8, regardless of what it points to.
You can use sizeof when dealing with strings, but you will have to do this instead:
const char[] thing = "string", this will make a character array big enough for the string. Sizeof will work as you expected with arrays.

Now, to get to the point; The reason your program did not work right is as follows: strlen does not count the null-terminator.

Whoops, array thing should be
"const char thing[]", instead.

c++ is the greatest language of all time

the great debate
/*
*
*
*
*/

vs

/*
*
*
*
*/

;;; There is no debate.
;;; You use this.

/**
*
*
*
*/

/*
*
*
*/


/*
*
*
*/

THANKS SO MUCH
I actually though I tried this but I will burn this into memory, just did strlen(buffer)+1

No debate here.
/***** *
* *
* *
**********
* *
* *
* *****/

nvrm scratch the +1

rlwrap's history feature isn't playing nicely with R outside of when it's asking me if I wanna save my workspace. It's not cute. Any way to make R just read normally and not use the ncurses or whatever its doing to capture my up arrow inputs?

>I'd love to see you implement X in Haskell
We can go back and forth all day about this, since anything that's possible in Haskell is possible in Java and the reverse

Some things are inherently better with recursive syntax and some things are inherently better at OOP. That's why Haskell copies so much from OOP with class types and whatnot

hey it's the *RAWHDRAHAHHEMM* male hillary *BRWAHAHEHHEEMM* clinton

# I'm not sure I know what you mean?

>anything that's possible in Haskell is possible in Java
You mean except for having a plain function outside of a class? Or omitting type annotations? Or HKTs? Or... forget it. No sense arguing with Javeets.

Not the guy you were responding to, but Java supports lambdas now just f.y.i.

People like you are giving us fp guys a bad name.

>us fp guys
Reminder that Scala "programmers" don't count.

>runtime code of conduct checks

Directly translate this to Java pls. I want a laugh.
(define (noisefactory noise-table)
(lambda (n)
(let ((noises (filter identity (map (lambda (e) (if (= (remainder n (car e)) 0) (cadr e) #f)) noise-table))))
(if (null? noises) n (apply string-append noises)))))
(define fizzbuzzhisshowl (noisefactory '((3 "Fizz") (5 "Buzz") (7 "Hiss") (11 "Howl"))))
(for-each print (map fizzbuzzhisshowl (iota 100)))

Don't worry. [insert favorite functional programming language here] can't do [insert language feature here]

(defun fizzbuzz (n &aux (f (mod n 5))
(g (mod n 3)))
(cond ((= f g 0) 'fizzbuzz)
((= g 0) 'fizz)
((= f 0) 'buzz)
(t n)))

(loop :as i :from 1 :to 100
:do (format t "~&~a" (fizzbuzz i)))

Fuck you, I'm a hired smug lisp weenie.

Recommend a good book/site for learning "modern C"?

matt.sh/howto-c

>can't do [insert language feature here]
9/10 times it's because [language feature] is a hack that exists solely to compensate for your shitlang's lack of abstraction abilities.

redpill me on HKTs

Sorry, but I can't read garbage

>I can't read garbage
So you never learned to program in Java properly? Understood.

What esoteric programming language is this?

No I didn't cause I never learned Java

i could try but i dont understand this code

What is this shit?

Learn to indent rajapoo

so, I have a job interview for a position that'll involve being a sort of bridge between testing and software development, essentially I'll be curating a c++ driven automated test framework, not writing new parts of it but ill need to be familiar enough to know what most given chunks of code are doing

any youtube videos or other resources i can go over to brush up on software design for that kind of use case?

>c++ driven
>automated
>TEST framwork
f

friendly reminder that black women are the best programmers

ded thred

ded industry

Something for the real niggers: pastebin.com/575cdmp2
>tfw you realize nothing beats bashthebarchive.com/data/b/image/1516/02/1516021448758.jpg

kotlin

This is common knowledge by now.

Testing my Perlin noise implementation I wrote in C++. Programming after not doing it for some time feels comfy.

>software design
Not involved in the slightest here.
Learn different testing forms, whitebox, blackbox, unit test, SDIT methodology, regression vs smoke testing, sanity checks, etc.
You're a "tester into maybe a developer", think testing first.

Neat. Post picture.

>buckleyposting

Doesn't quite work at the moment.

ok
public static void main(String[] args) {
ArrayList list = new ArrayList();
list.add(new Tuple(3, "Fizz"));
list.add(new Tuple(5, "Buzz"));
list.add(new Tuple(7, "Hiss"));
list.add(new Tuple(11, "Howl"));
Function fizzBuzzHissHowl = noiseFactory(list);

for (int i = 0; i < 100; i++) {
System.out.println(fizzBuzzHissHowl.apply(i));
}
}

public static Function noiseFactory(ArrayList tuples) {
return (Integer i) -> {
String s = "";
for (Tuple t : tuples) {
if (i % t.x == 0) {
s += t.y;
}
}
if (s == "") {
s = i.toString();
}
return s;
};
}

private int getScore() {
if (checkRoyalFlush()) { // Royal Flush
return 10;
} else if (checkStraightFlush()) { // Straight Flush
return 9;
} else if (checkMult(4)) { // Four of a Kind
return 8;
} else if (checkFullHouse()) { // Full House
return 7;
} else if (checkFlush()) { // Flush
return 6;
} else if (checkStraight()) { // Straight
return 5;
} else if (checkMult(3)) { // Three of a Kind
return 4;
} else if (checkTwoPair()) { // Two Pairs
return 3;
} else if (checkMult(2)) { // One Pair
return 2;
} else { // high card
return 1;
}
}

How do I rewrite this so it's not so goddamn ugly?

switch statements, nigger monkey

>for
>+=
Not really a direct translation. I was hoping for functional Java code using those maps and filters and streams. The post was a response to user talking about lambdas after all.

one minor possibility: you only need "if"s, not "else if"s
and "else" can go too

Stop doing it procedurally, you street shitter.

You need to ground it.

t. nigger monkey

I've been programming for a number of years but have been thinking of learning some C. Do you guys have some recommendations on the best place to start with C?

...

>pajeetnet
Like call centers?