/dpt/ - Daily Programming Thread

Previous thread: Free functions are not OOP edition

Other urls found in this thread:

pastebin.com/e254Gugk
lodev.org/cgtutor/randomnoise.html
en.wikipedia.org/wiki/Bicubic_interpolation
blog.sigfpe.com/2006/08/you-could-have-invented-monads-and.html
nimh.nih.gov/health/find-help/index.shtml
en.wikipedia.org/wiki/FLAGS_register)
twitter.com/SFWRedditGifs

Java is notOOP becasue Java is not Smalltalk

void f(int x); // this is oop, x receives the message

explicit this pointers to structs as a function argument is not OOP in disguise

>not OOP in disguise
right, it's just plain OOP

I have a programming stupid question -

I made a twitter bot and now want to upload it to github, what do I do about the auth keys? Do I just take them out before committing changes?

What are you working on, Sup Forums?

b-but user im intelligent, please believe me or ill be a bigger retard


(im just impersonating a retard in the last thread)

you can only do OOP in java, don't you know

>(im just impersonating a retard in the last thread)

I did this yesterday for one of those roll what to code meme threads (random image generator).
pastebin.com/e254Gugk

What are those weird vertical and horizontal light strokes? They shouldn't be there.
I followed this tutorial lodev.org/cgtutor/randomnoise.html and you can see the same problem on the pics there. I tried to modify it in different ways to see what's happening here but I could only ever make it worse.
Can someone tell me how to get rid of those light strokes? Is that something with floating point precision?

reading up on IO completion ports and how to use it with sockets, sounded kinda intimidating when i first heard about the magic it is, now, not at all.

>What are those weird vertical and horizontal light strokes?
it's from linear interpolation
use bicubic or something more advanced

you werent there? oh man, you missed something glorious

(cont)
also check this article, the pictures show the difference between the two en.wikipedia.org/wiki/Bicubic_interpolation

friendly reminder that you can express perlin noise comonadically

Put them in a seperate file, and load them from your script. Then add the seperate file to your .gitignore

could be an artifact of the noise itself

Thanks user. Just googled around and got the same idea before you responded.

Thanks.

>friendly reminder
I'm a noob if that wasn't obvious in my previous post so that's not really a reminder to me.
"Comonadically" means it has something to do with functional programming, yep?

Explain to me monads and why they are useful like I'm 5. Every article I found is difficult to understand.

perlin noise can be expressed with a zipper, and all zippers are comonads

now you know

Monads are applicative functors with a join operation (M (M a) -> M a)

I don't understand, what is a join operation? What are applicative functors? What is (M (M a) -> M a) supposed to mean?

sounds a bit like category theory, yea?

M (M a) -> M a
is the type signature of "join"
join is simply a function that has this signature, that is specific to a particular monad

M a is like M in other languages

An applicative functor M is a functor that has the following additional operations
pure :: x -> M x
(also called "return" for monads)
ap :: M (x -> y) -> M x -> M y
(apply, )

It's me again:

I'm reading this and it's really cool. Atleast the parts that I can understand are.

My question is how can you perform a bitwise operation such as AND on 2 binary numbers of different size?

Am I correct to assume that you would line up the binary digits so their MSB allign and perform the operation on corresponding bits?

Is that what it meant by defining negative numbers as being preceded by an infinite amount of ones?

Yes, monads are from category theory

0 is the identity for AND, so I assume by substituting that for the other digits

0101 & 10011001 -> 00000101 & 10011001

No you would line up the LSB

this which is because 0101 = 101 = 00000101

i see, i never studied any haskell and have only recently begun reading up on category theory.
call me out if im wrong, but i would rather think of perlin noise as an endomorphism, or at the very least a homeomorphism

Thanks for trying to explain but it's like you are talking in another language. I can't understand shit.

What languages do you use?

this but keep sign extension in mind (or just don't do bitwise operations on signed integers, at least not in C/C++)

blog.sigfpe.com/2006/08/you-could-have-invented-monads-and.html
Have you read this? It's probably the best tutorial out there.

C, Perl, Python, Javascript and I know a little bit of Common Lisp.

>no types whatsoever

just google monad and the other things, you won't learn anything from a post

learn a language with static typing
ideally haskell

C is statically typed.

>C is not statically typed

>hurr hurp durp

Oh shit, I didn't see C was there
C doesn't have generics or HKTs though

I did read it in the past but didn't really understood it.

I do want to learn haskell however I fear that if I do not know basic stuff such as what is a monad I will not be able to do shit with it.

>jumping on the bandwagon
shame on you

monads aren't really basic in the sense that you don't need to understand them to use haskell

:30:2: warning: passing argument 1 of ‘generateNoise’ from incompatible pointer type [enabled by default]
:12:6: note: expected ‘double (*)[800]’ but argument is of type ‘double **’
:31:2: warning: passing argument 1 of ‘generateNoise’ from incompatible pointer type [enabled by default]
:12:6: note: expected ‘double (*)[800]’ but argument is of type ‘double **’
:32:2: warning: passing argument 1 of ‘generateNoise’ from incompatible pointer type [enabled by default]
:12:6: note: expected ‘double (*)[800]’ but argument is of type ‘double **’
:33:2: warning: passing argument 1 of ‘updateScreen’ from incompatible pointer type [enabled by default]
:10:6: note: expected ‘double (*)[800]’ but argument is of type ‘double **’
:33:2: warning: passing argument 2 of ‘updateScreen’ from incompatible pointer type [enabled by default]
:10:6: note: expected ‘double (*)[800]’ but argument is of type ‘double **’
:33:2: warning: passing argument 3 of ‘updateScreen’ from incompatible pointer type [enabled by default]
:10:6: note: expected ‘double (*)[800]’ but argument is of type ‘double **’
: In function ‘updateScreen’:
:58:2: error: ‘for’ loop initial declarations are only allowed in C99 mode
:58:2: note: use option -std=c99 or -std=gnu99 to compile your code
:59:3: error: ‘for’ loop initial declarations are only allowed in C99 mode
: In function ‘generateNoise’:
:69:2: error: ‘for’ loop initial declarations are only allowed in C99 mode
:70:3: error: ‘for’ loop initial declarations are only allowed in C99 mode
: In function ‘mipmap’:
:91:2: error: ‘for’ loop initial declarations are only allowed in C99 mode


top kek

>C doesn't have generics or HKTs though
good

can't spell faggot without Go

All anime girls that program in C are instant waifu material to me. Say to to shit girls who like java or python.

I do know that haskell uses monads in multiple things such as for IO or for stuff such as the maybe monad but I never really used it so I might misunderstand their importance.
Well, I guess my only hope is to learn about them while learning haskell. Thank you user.

*say no to

You have to understand the basics of monads in haskell and how to use them for that.

I am ok-ish profficient with haskell and have no idea why monads exist outside of haskell and how to use them.

What about cute boys that look like girls and program in C?

>who like java or python.
please tell me what's wrong with java or python with credible arguments

They are shit

excellent taste

I mean you can program in haskell while not understanding monads
Monads in category theory are like those in haskell, except with join rather than bind


>credible arguments
>inb4 any argument that says they're bad is "not credible"

nimh.nih.gov/health/find-help/index.shtml

python is great
I have some problems with java, but if it were the only oop language I'd use it

Not an argument. try again you memelord

I'm not sure how you want to understand monads. If you want to understand the mathematics behind it, read 'Notions of computation and monads' and other articles by Moggi. But you seem to be too retarded to comprehend them on this level. If you only want to acquire an intuition, just learn Haskell and use them.

What? It's just warnings.

it's treatable, there's still hope for you

>expecting people on g to have arguments outside of "i dont like it"
having a proper discussion is impossible man

Stop spamming the real thread with links to this shit, mentally ill faggot!

>It's just warnings.
lmao

you don't ship software with "warnings"

What's wrong with the OP?

No need to be such a dick

I just want to tell someone that I think btn-default btn-block looks really good.

>you don't ship software with "warnings"
truth be told, you never ship

not always, but when i do i break everything

i told you to google it

that faggot obviously learnt some basic haskel shit so he just shits on your head with explanations that explain unknowns in terms of more unknowns

Okay... I'm a bit less confused now... So basically, I need to check whether the Fibonacci sum will be an overflow, which can be done by
if(logBASE2(num1) + logBASE2(num2) > static_cast (logBASE2(MAX_long_long) )

and if it returns true, the sum overflows...
Now (and I know this is beyond stupid of me to even ask at this point), how would I do this:
>then allocate more bytes apply operations on them as partial solutions
I'm guessing it has something to do with logarithms, but I can't think of anything...

I am 'that faggot'

I told him to learn some Haskell so he'd understand functional programming and parametric types, so he could learn the signatures, so he could then learn stuff like effects and coeffects

>Current Job Openings
>Hacker / Software Engineer

what do?

If you're hair isn't blue or pink, your not getting hired.

>job
>hacker

>job
>software """"""""""""""engineer""""""""""""""

man

shit stain how many times was a person with blue or pink hair hired over your ass

A bit new to C, building a game board. Anyone know how I would change the for statement to not constantly print out C? I need it to print out C for the first tile, W for every 3rd tile, L for every 5th tile and G for every 7th tile. Been stuck on this for a bit

no logs at all, it would be like if you had 2 bytes and tried to add 0x01 to 0xFF, you would then first detect the overflow, then allocate another byte, set the first byte to the overflowed value and then add the 1 to the 2nd byte, if that makes sense.

also the log trick might be a litle computationally expensive, if you have the possibility to, i would query the cpu status register for its overflow bit.

let me know if that helps

I do know about functional programming and parametric types, I find the signatures unclear however.

My bad...

if(logBASE2(num1) + logBASE2(num2) > static_cast (logBASE2(ULLONG_MAX)*2 )
// Because ULLONG_MAX = 2^64-1, which when the log2 is truncated, is the same as logBASE2(2^63)

twist: he's a 2D anime-kin and he keeps getting turned down in favor of 2D anime girls.

In the case of Java, C# exists.

M a means M in some other languages

a -> b
means a function that takes an 'a' and returns a 'b'

a -> b -> c = a -> (b -> c)
a function that takes an 'a' and returns a 'b -> c'
(this is also like a function that takes two arguments, 'a' and 'b', to give a 'c')

A monad (in Haskell) is some type M for which there exist functions
fmap :: (a -> b) -> (M a -> M b)
-- from functor
return :: a -> M a
-- from applicative
bind :: (a -> M b) -> (M a -> M b)

(this is ignoring applicatives, but that's not really important atm)

I bet your joke of a waifu only ever uses graphical interfaces for everything. How lame.

>means M in some other languages
Such as what languages? Is it like a template in C++ or something?

Yeah

In that case, does return :: a -> M a for example mean that return takes an argument a and returns the same argument with a type M? Because I am not sure if I understand that correctly.

Yes

M is a parameterised type of kind (type -> type), so M a is a type.

Thanks

for instance, Lists are a monad, so
return x = [x]
-- list consisting of one element
Maybe is also a monad
return = Just
-- return x = Just x


There are additional laws that are needed for monad operations but they aren't important atm, most of the time if you've got the signatures right then it'll work anyway

Question, why did you type three for loops instead of a nested for-loop?

int(i = 0; i < s; i++)
{
int(j = 0; j < s; j++)
{
if(i==0 && j==0)
//Print 'c'
if(j%3 == 0) //Every third tile
//Print 'w'
if( ((i*s)+(j))%5 == 0) //Every 5th tile
//Print L
...
}
}

I sort-of understand the explanation, but without logarithms, how would you detect the overflow? You would have to add the numbers first (or their logarithms, if you're doing what I did), and check if the value overflows

unsigned a,b,c;
a = b + c;
if (a < b) {
/* overflow */
}

And another question, how would you "allocate another byte"? That's the part I'm really stuck on...

you can also just use arrays as numbers

array of length 10000 could represent a number of length 10000 and do addition, multiplication and division algorithms on top of that

like {1,2,3} could be number 123

much easier and more general

> {1,2,3} = 123
What's {10, 2, 3}

to detect the overflow, i would use an intrinsic, depending on the platform you are working on it could be something like __getcallerseflags which returns the flags for the cpu (en.wikipedia.org/wiki/FLAGS_register)

allocating the additional byte would, again depening on your language be either a realloc call in C or something like a vector::push_back()

Got a long weekend to work on my pet project.
Should I give it a weeb friendly name or go for some obscure norse pagan name?

135 in base 10, assuming base 11.

I'd prefer a, 2, 3