/dpt/ daily programming thread - Go edition

Previous thread: Jow Forumso edition.

Go on and tell us what you are working on Jow Forums.

Attached: gomascot.jpg (500x500, 108K)

Other urls found in this thread:

clhs.lisp.se/Body/m_defgen.htm
wiki.haskell.org/GHC/Memory_Management
fpcomplete.com/blog/2017/07/iterators-streams-rust-haskell
stackoverflow.com/questions/46606283/converting-a-pil-image-to-wxpython-bitmap-image
wxpython.org/Phoenix/docs/html/wx.Bitmap.html#wx.Bitmap.FromBuffer
twitter.com/NSFWRedditVideo

First for lisp

Any ideas why it's doing this? Am I declaring the typedef wrong?

No generics.

>go

Attached: golang.jpg (770x478, 62K)

Idiomatic ternary in Go:
a := func() int { if test { return 1 } else { return 2 } }()


Why do statement-oriented languages still exist?

wat?
clhs.lisp.se/Body/m_defgen.htm

That's multimethods, not parametric polymorphism.

whaddayamean

Attached: FeL81Wa.jpg (730x398, 50K)

I want to make video games. Should I learn C++?

>moving goalposts

nah man you gotta find a language with linear dependent type systems

What? I just want to make an rpg

Why is it called the Daily Programming Thread when there's more than one a day?

>linear dependent type systems
Explain what this means in normal speech

>falling for the meems

>linear
values can only be used once
>dependent
values of a type satisfy on a runtime predicate

Attached: errnil.jpg (700x720, 82K)

>linear
Linear values must be used exactly once.
>dependent
Variables can be lifted to the type level, where they statically quantify over all their possible dynamic values.

I need some help. I am using wxPython to create a GUI for a simple program I am making. In the program, I am using the Image module from Pillow to do some changes to a picture. When I save the image to disk, everything looks as expected. When I try to display the image using wx.StaticBitmap, it looks fucked up. The image that is shown also doesn't seem scaled even though the wx.Image shows the correct scaled width and height. Any help will be appreciated. Also, dim is a tuple that holds a scaling factor for the image.

def wx_to_PIL(bitmap):
size = tuple(bitmap.GetSize())
try:
buf = size[0]*size[1]*3*"\x00"
except:
del buf
buf = bitmap.ConvertToImage().GetData()
img = Image.frombuffer("RGBA",size,buf,"raw","RGBA",0,1)
return

def showImage(self,image):
img = PIL_to_wx(self.PIL_image)
img = wx.Bitmap.ConvertToImage(img)
img.Rescale([dim[0],dim[1])
self.imageFrame.SetBitmap(wx.Bitmap(img))
self.panel.Refresh()

Attached: file.png (1012x855, 976K)

what are named return values???

or more likely- what are functions with scoped responsibility

FUCK. copied the wrong method. Also, the initial loading of the image is fine. Pic related

def PIL_to_wx(image):
width,height = image.size
bitmap = wx.Bitmap.FromBuffer(width,height,image.convert('RGBA').tobytes())
return bitmap

Attached: file.png (1013x855, 399K)

what are exceptions :S

yes

>lisp
>no generics
lol

a lot of game companies use c++, my company uses c++ too. but I use C on personal projects. I strongly don't recommend working for a game company though.

If you wanna make a run of the shitmill rpg just use rpg maker or something.

this is just an example of bad code from bad engineers

also, people who complains about languages are really stupid and not fit into the IT world, so pls just kys

what company do you work for, if I may ask?

what are structs

as you can see, your weeb shit seems to be split into 3 off-set subsets of pixel/colors. So your I/O and conversions go fucky somewhere.
Try to narrow down the problem
- can you skip rescaling and test if you still have the issue? (Most likely yes)
- Can you try to reproduce the issue with a simpler image, e.g. 60x60 pixels with increasing values - 0,0=rgb(0,0,0), 0,1=rgb(0,0,1), 0,2=rgb(0,0,2). This should give you a good idea of which pixel ends up where when your code fucks it up.

Wait so functional languages prefer linked lists? I thought linkedlist were evil.

How do I into javascript?

Linked lists are quite elegant in a lot of ways.
They're just awful for cache performance.

Immutability prefers linked lists. Functional programming is not antithetical to mutation.

var int = eval("one");

So are functional langauge not very good for performance?

I don't know much about immutability yet

not actually linked lists, but iterables on which you can execute some lambda function (transformation) lazily

what are MONADS

Attached: 1515899157694.jpg (700x681, 83K)

Why do you think functional languages are so slow?

Laziness can make linked lists more efficient

Attached: 1517829643124.png (217x255, 70K)

>So are functional langauge not very good for performance?
Typically not, especially compared to the likes of C.
Although you can make the mistake of awful cache performance in any language.

>> Using different terminology from everyone else.

I like Multimethods and use them frequently. But it's a completely different concept.

>Single line nested bracketing
Just because you can doesn't mean you shouldn't.

Because they can't take advantage of the cache which is faster to read from or am I wrong?

>7 return values from a single function
That's just bad programming.

That, and producing a shitton of garbage due to immutability.

He's incorrect about linked lists and cache performance for garbage collected languages. Any non shit garbage collector uses generational garbage collection which keeps locality high for most linked lists.

But yes top tier functional code is much slower than top tier imperative code.

>exceptions instead of maybe

exactly, except that they're not slow at all.
fp can apply pretty strong optimizations on the code, making it blazingly fast.
only problem is the high garbage collection overhead due to immutability

>blazingly fast
giggling_teenagers.jpeg

>inb4 haslel 1GB/s garbage generation
wiki.haskell.org/GHC/Memory_Management
>not uncommon to produce 1gb of data per second (most part of which will be garbage collected immediately)

I think it's by design. I personally think multimethods make more sense in a functional language like CL. I know CL is not "strongly" functional by Haskell autists, but still.

>But yes top tier functional code is much slower than top tier imperative code.
because you're trading performances for abstraction power, that can be good for game development, but for the other 99% of IT not that much

Linked lists are only bad for cache performance if you're using a horrible language which doesn't have a compacting garbage collector.

A good compacting allocator can allocate nodes by just incrementing the nursery pointer and writing to the new memory. When the nodes are moved from the nursery to the main heap, almost all the nodes in the linked list will typically be allocated next to each other, so your cache locality will be about as good as if you were using arrays.

Your intuition from sepples about what is fast and what isn't *does not carry over languages with a good GCed runtime*. Linked lists are much faster in Haskell than in sepples, even if you pool allocate them in sepples.

The problem happens with or without the scaling. I should have mentioned the purpose of this program. It is supposed to create a chromatic aberration effect which is why the RGB channels are split up. The issue is that once I convert the PIL image back to wx.Image, it gets all fucked up. If I saved the PIL image to disk and view the image, the effect is applied correctly.

>1gb/s
Damn. Is there anyway to avoid that with functional languages? Is it because it has to copy always? Can't it just share the common pieces?

>Can't it just share the common pieces?
it's 1GB/s AFTER sharing the common pieces

jesus Haskell != whole fucking fp langs
Rust is a fp lang and get away with it using RAII

Every time you want to create a new value, you must allocate more memory. However because you do know values will never change, you can reuse them freely rather than making copies.

>it gets all fucked up.
how? Post a before and after, otherwise we'd actually need to read the code

That's misleading. The work that Haskell's GC has to do on young objects is only proportional to the number of objects that are alive, and independent of the number of young objects that are dead, ignoring cache misses if the live objects are spread out.

Unreachable objects in the nursery will just not be copied over to the main heap, and will just be overwritten whenever new allocations happen in that space.

Yes, Haskell is particularly bad because almost everything is boxed (lots of little heap allocations) and garbage collected. Without boxing or GC (e.g. with linear types) you reach MMM efficiency when it comes to space usage.

>not all FPlangs are Haskek
>Rust is a fp lang
FPlets are getting desperate

see this

...

one
jiggabyte
persecond
of pussy and ass

>Your intuition from sepples
I consider this the greatest form of insult. Sepples is trash.
>Linked lists are much faster in Haskell than in sepples
Wow, so Haskell has magical pixie dust, making it faster than any possible "native" language?
Please tell me the exact details of its implementation any why it can't be replicated anywhere else.

see

He's clearly a rustfag. No FP weenies would every call rust functional. The borrow checker is antithetical to one of the core ingredients of functional programming which is unlimited extent of data.

I have a question. If hardware was changed to suit FP would FP be faster? I am not very knowledgeable on hardware.

Julia has both multimethods and generics. They are completely orthogonal concepts, and work together very well. Parametric polymorphism can generate an infinite number of multimethods, like this:

sametype{T}(x::T, y::T) = true
sametype(x,y) = false

#example:
sametype(1,2) #returns true
sametype(3.0,1) #returns false

>The borrow checker is antithetical to one of the core ingredients of functional programming which is unlimited extent of data.

Attached: 1522280161860.jpg (481x523, 49K)

fucked up as in the screenshots I posted before.
Initial opening of the image is fine: Once I do any edits, it looks like this: I posted the code that displays the image. In the code. self.imageFrame is a wx.StaticBitmap object.

Having a decent GC. Java linked lists also perform better than the C++ ones. C++ is slow because it has pointer arithmetic so its allocator has to be non-moving.

Linked lists are also faster in Lisp and Java and Go for the same reason. No magic space pixie dust. It's just generational garbage collecting. Sepples doesn't have a garbage collector so there you go its linked lists suck.

>The borrow checker is antithetical to one of the core ingredients of functional programming which is unlimited extent of data
please explain me how does the borrow checker limits the "unlimited extend of data"

And lazy evaluation.

forgot to mention that the displayed image after the edit is not what it looks like. It shows way too much separation and shows shifts of bands that I didn't even touch yet. If I save the edited image to disk, it looks as expected.

Lisp machines were pretty well liked back in the day. But they're dead now.

I like monadic error handling desu, wish more non functional languages would start using them properly

>how does limited data lifetime limit the extent of data

Attached: brainlet.png (645x729, 56K)

ffs you're missing the point
>Initial opening of the image is fine:
>Once I do any edits, it looks like this:
but then you post
>t is supposed to create a chromatic aberration effect which is why the RGB channels are split up
and
>forgot to mention that the displayed image after the edit is not what it looks like. It shows way too much separation and shows shifts of bands that I didn't even touch yet.
Can't you properly isolate the issue by temporarily avoiding/disabling *any* modification of the image - including the chromatic aberration stuff.
Right now I can't tell which parts of the fucked upedness are intended and which are not.

Is Android studio necessary to develop for Android? I want to keep muh Vim but I want a custom-made IRC client to flamewar in class.

so you're saying that fp imposes that data shouldn't be limited by anything?
so tell me why immutability is needed, please
tell me why fp langs generates so much garbage objects

Here's a benchmark of Rust and Haskell, where Haskell uses rapidly allocating linked lists and Rust uses in-place mutating allocators:

fpcomplete.com/blog/2017/07/iterators-streams-rust-haskell

Haskell still manages to have respectable performance, thanks to a combination of good compiler output and good GC performance.

I see uncaffeinated all the time on r/progamminglanguages. There's this guy Jon Goodwin over there working on a language called Cone which is pretty neat.

>fpcomplete.com

I'm writing a pure functional language (proof of concept) with a borrow checker, homeboy.

i need python guys

Attached: maxresdefault2.jpg (1280x720, 130K)

alright, managed to fan up a decent shitstorm
time to fold'em

Oh ok. I misunderstood what you were asking. I commented out the scaling and chromatic aberration stuff. It seems like when it converts from PIL to wx.Image, it gets fucked up. So the code in this post:

Attached: file.png (1015x857, 749K)

Is it possible to use methods as arguments in Java?
I've gotten into this habit with Javascript, being able to use methods as arguments allows me to write extremely modular code.

I've got the python you need right here bb

test

I'm new to functional programming but I like it so far. I like the idea of functions being like math functions and taking in an input and giving output with no side effects. Still confused how to write more advanced programs but it is neat.

>typecase

Attached: 1508516904947.png (916x914, 998K)

Using Java 8 or newer, yes.
Look up closures, functional interfaces, lambdas and method references.

so help faggot

Attached: images.jpg (210x240, 6K)

>answering a question with "look up four different things"
Every time someone answers a question by giving me a yes/no answer and telling me to look up something, they're usually wrong.

I see you've taken some code from stackoverflow.com/questions/46606283/converting-a-pil-image-to-wxpython-bitmap-image
>wx.Bitmap.FromBuffer(width,height,image.convert('RGBA').tobytes())
have a look at
wxpython.org/Phoenix/docs/html/wx.Bitmap.html#wx.Bitmap.FromBuffer
and note that there exists FromBufferRGBA
does this give you a nagging feeling that there's an obvious fuckup in yo code?
in the future, at least have a 10-second skim of the docs /smug

The answer is switch to C# and use delegates. You won't really know the difference.