/dpt/ - Daily Programming Thread

On what are you working, Jow Forums?

Old thread:

Attached: 003eeff9.jpg (405x500, 37K)

Other urls found in this thread:

pastebin.com/H2muGxLm
coursera.org/learn/machine-learning
coursera.org/specializations/deep-learning
ecee.colorado.edu/ecen5533/fall11/reading/free.pdf
hackage.haskell.org/package/base-4.11.1.0/docs/Data-Foldable.html#v:traverse_
twitter.com/SFWRedditImages

Verified by who

Am I being overambitious in thinking I could teach myself machine learning and possibly get a job within that sector? Turns out I like math and actually enjoy the algebra but there's just so much to learn. I have no idea when I should start my first project or even what it should be.

reading the Go programming language book, pretty comfy, reminds me of C programming language book.

Please use an anime girl next time.

Attached: 1528696375861.png (1026x1038, 706K)

I shmell a death grips fan

this is a programming thread, not a coding thread

God, unironically.

Go is basically a cleaner C without manual memory management or pointer arithmetic, which is why Jow Forums hates it so much.

install shen

>has gc
>anything like C
pick one and only one

It only seems like C, until you realize, it's nothing like C.

C doesn't have generics because the necessary CS theory didn't exist when C was created.

Go doesn't have generics because its users can't understand them.

>t. never used go
C isnt about manual memory management.

Go has interface generics. Stop trying to your way through everything and it isnt an issue and you write better code.

I think a Googlist has escaped: What's the number we're supposed to call when this happens so Google knows to come and collect them?

>Go has not generics
yes, we know

C has void pointers. We learned that they suck about 30 years ago, and that's why almost all modern statically typed languages support parametric polymorphism.

It has interface generics. Stop trying to your way through everything.

Learn what a Go interface is an how it works, nobody is ever referring to blindly passing things as Interface{}

>void pointers
Hope you're not doing pointer arithmetic on those.

What are good C++ IDEs? I use CodeBlocks at school and my friend said that's disgusting. Do you guys even use IDEs? I've been told to use Sublime and installing a separate compiler

Attached: 1526773803056.jpg (1191x670, 84K)

>nobody is ever referring to blindly passing things as Interface{}
Give me an example of Go generics that isn't literally this.

How do I program in Agda without learning Emacs? My brain can't handle learning two new things at the same time.

Implemented interfaces you mong. Go isnt restricted to a single interface for a type so slap it around all over and write clean safe code that expects particular types with safe shared attributes and functions

>If you're on Windows
Visual Studio, it's bloated as fuck, but the debugger is actually really good
>Not on Windows
Who the fuck knows, they're all shit, just learn to use a good editor(vim/emacs), and gdb/lldb.

>Stop trying to your way through everything
What does that even mean? "Stop trying to write flexible yet obviously correct code"?

>Implemented interfaces you mong.
But, that's inheritances, not generics, right?

Even Java supports implementing multiple interfaces for a type.

just use regular identifiers

Question for nim folks: how good is the JS/C interop? I kinda want to adapt some C libraries for ARM MCUs and add some way for users to have a JS-based human interface built into their code.

Hey Jow Forums, learning C and made a binary search today. Is it any good? I haven't included anything to deal with the element never being found, just curious if I'm on the right lines here

pastebin.com/H2muGxLm

excuse the pastebin, cannot for the life of me figure out how to format code on Jow Forums.

Its only safe as long as T remains in a type set friendly to the operations of the function. Theres no such thing as completely safe T functions outside of a simple storage container.

Go has no concept of inheritance. Interfaces in Go do not share the same limitations as in other languages.

My b I was thinking inheritance not interface

What does C need to be a functional language? You can return functions, and functions with prefilled arguments (currying), you can check type equality, it has generics. You can write a type-generic map(), but only one that operates in-place.
What more is needed?

Function pointers are by defintion lambdas so *technically* C has functional capability.
Its just not whats really meant by "functional language" where you have full lambda *expressions*

>Theres no such thing as completely safe T functions outside of a simple storage container.
What the fuck am I reading

learn Haskell

>Go has no concept of inheritance
Nor does it have a concept of generics.

Something that you only come to understand after dealing with too many MAKE IT ALL GENERIC!!!@ C++ metatemplate programmers bullshit.
Genericism is not inherently safe in any capacity.

Plugging your ears doesn't make it go away.

It does, but users aren't allowed to define their own generic data structures or functions.

>It does, but users aren't allowed to define their own generic data structures or functions.
So, for all intent and purpose, it doesn't.

I ultimately agree, but I find it amusing to note the disdain with which Go users are treated by the language's developers.

nothing,
trying to bolt on """features""" kills a language.
see C++.
And then the abomination that's liquid haskell.

I second . C++ being a monstrosity doesn't mean that generics are inherently unsafe.

Adding generics probably saved Java.

I don't mind Go, I've used it for hobby projects, and in Uni.
But apologists/evangelists that won't realize the language's shortcomings, can suck a fat one.

made a little script that detects what colors are in a photo and how much area they take up.

Attached: color_script_cpp_opencv.png (1493x821, 279K)

Just store amount of used ints in the first element of the array and keep track of it that way. You'll learn better ways of allocating shit later

well generics coincide with POO.
C is not an FPL, and will never be one, no matter how many gymnastics cniles try to pull off.

>Is it any good?
It's your typical(naive) implementation of binary search, it's not good nor bad.
If it can't out perform(it wont, btw) bsearch(3), use bsearch(3).

I was fortunate in that uni taught me ML first and foremost. There was a mandatory Java course later, but the prof made it quite clear that it was only taught because businesses were upset that grads kept trying to get them to ditch Java and C# and switch to functional languages. Lectures were peppered with sarcastic remarks like "apparently this is practical, despite being completely unsound/impossible to reason about" and "you'll note that ML has a much cleaner and shorter way of doing this, but it's too academic and abstract".

Right so that's what I'm wondering, how is it naive exactly?

Generics as implemented in Java is a poor version of parametric polymorphism, which is an essential part of most modern statically typed functional languages.

* as implemented in Java is a poor version of *.
can be said about a lot of things.

[co-de] (your code here) [/co-de], without dashes.

Let's go through it line by line


int binSearch(int ar[], int x);

Not needed. Put your functions in lexicographic order, so binsearch is above main. That's usually nicest to read, so try to avoid prototypes if possible.

int main (){
int array[50] = {2,5,7,10,14,17,20,23,25,31,33,36,37,EOA};

No need to put the [50]. You can just put array[] = {...};, since it knows the size at compile time.
printf("%i",binSearch(array, 23));

It's "%d\n". not "%i".

(cloudflare connection error, cont'd)

>how is it naive exactly?
Apart from the fact that its a literal implementation of the binary search algorithm, I coulnd't tell you.
Your implementation(literally the way anyone would implement binary search at first) would probably be good enough for 99% of use cases, but then there are some serious specialty applications out there that require some freaky levels of optimizations, and that's where specialty implementations come in.
Just take a look at optimized search algorithms, or algorithms in general, they have had mathematicians spending months if not years tweaking any sort of magic number they can to gain minute performance gains.

int binSearch(int ar[], int x){

Multiple issues here.
>it's customary to receive it as a pointer, e.g. int* ar, although it's a matter of taste
>arrays are usually called arr, or sometimes ptr if passed as pointers, or s for strings
>take an argument int n which is how big the array is, don't use EOA.
>new line for opening brace of functions, or at least space
if (i % 2 == 0)
midPoint = i/2;
else
midPoint = (i/2)+1;

This part here is just i/2 rounded up. It can be written easier as
midPoint = (i+1)/2;

However, array indexing starts from 0. Shouldn't you be rounding down? Wikipedia says so.
Also, some people recommend always using braces for if statements, otherwise you can cause trouble like Apple's goto fail;

while (1){
if (x < ar[midPoint])
midPoint = midPoint*1/2;
if (x > ar[midPoint])
midPoint = midPoint*3/2;
else
return midPoint;
}

midPoint here stops being descriptive. Use something like i or idx.
The implementation itself is flawed. It can't divide by two, it's supposed to have a "lowest" and "highest" value. Then it takes i - (i - low)/2, if arr[i]'s too big, and i + (i - high)/2, if arr[i]'s too small.
Try doing it with 1-10 in your head.
What about k-means? That won't work for compressed images.

I don't shy from Go's faults, I fucking hate the obnoxious dev environment and explicit casting syntax is fucking obnoxious, and the overly light standard library means you end up relying on a bunch of community made packages which is just..never a good time
But "muh generics" is such a weak reason to shit on a good language. Go makes concurrency stupidly easy, it's pleasant to use, it's reasonably performant, and most importantly it's *clean*. You almost have to go out of your way to write obtuse Golang code.

Golang has plenty of faults, the occasional need for generics really isn't one of them.

It's not hard to get a job in the sector if you have proper expectations.
Right now, ML is two tiers
>people with PhDs in math/stats/cs who do all the cool shit
>pajeets who basically manage databases and data pipelines and write software that scrubs data
I'm really sorry to say that I have witnessed very little in between those two extremes.

t. data shitter.

>Go makes concurrency stupidly easy
Clojure also makes it easy and is additionally a much better designed language.

>it's *clean*. You almost have to go out of your way to write obtuse Golang code
Go denies you almost all proven means of abstraction. Individual lines may be easy to understand, but the whole is lost in a mess of details. You can't see the wood from the trees.

Thanks a lot user, really appreciate this. A lot of my behaviour is probably explained by the fact I'm currently at the end of chapter 1 of the K&R book, for the record, eg I haven't met pointers yet. Again though, thanks, this is exactly what I was looking for.

Other languages do concurrency too, yes, but NOTHING compares to "go " for spawning new concurrent operations, especially paired with the built in channels.
Plus goroutines only allocate an initial 8kb of stack memory, because green threading, so you don't have threading limitations like JVM has of using native OS threads which are stupidly expensive. Java (and by extension Clojure) have to be conservative about how often and how many concurrent threads they spit up everywhere because of this.

>Go denies you almost all proven means of abstraction.
In terms of coherency? Not at all true.

>the occasional need for generics really isn't one of them.
generics are a benefit in most code-bases though golets down-playing their significance is the real obnoxious thing.

How is this for a CS self-study curriculum?

>SICP
>Haskell bok
>Type-Driven Development med Idris
>Algorithms CLRS bok
>Compilers drage bok

This. Generics (i.e. parametric polymorphism) begets parametricity. Parametricity begets free theorems. Free theorems beget reasoning. Reasoning begets correctness.

Beneficial? Occasionally. An absolute every day necessity? Not even remotely.
Be honest with yourself, when was the last time you NEEDED to write something in a completely genericized form that wasn't a storage container? And I mean NEEDED, not "I wanted to metatemplate this template with templates for this one specific partial specialization template"

seppletards pretending generics are the most important thing since electricity are even more annoying

>Beneficial? Occasionally. An absolute every day necessity? Not even remotely.
They are for me.
>Be honest with yourself, when was the last time you NEEDED to write something in a completely genericized form that wasn't a storage container? And I mean NEEDED, not "I wanted to metatemplate this template with templates for this one specific partial specialization template"
I wrote several generic functions today. I also used numerous generic functions in a library. Though I did not write them, the library authors needed generics functionality in order to write them.

need vs want is a false-dichotomy.
People enjoy generic code because it makes their code-bases smaller, easier to maintain, and pleasant to work with.
Having to implement X of the same function/whatever vs's one with T t args is much better.
>sepples is the only language with generics

all you need is k&r

>I wrote several generic functions today.
To do what?
Did you make sure they didn't reference anything specific about any type of any kind? Because otherwise you've written broken generic functions that will explode later.

> I also used numerous generic functions in a library
And what did those do? Did they store things? Because I write C++ all goddamn day long and every time I grab a library, it's only generic when it needs to have "some container of stuff". Otherwise things want specific types because functions normally do specific things.

>Having to implement X of the same function/whatever vs's one with T t args is much better.
Again, when does this happen outside of containers or god-forsaken Factory Patterns? It's so absurdly rare to see generics being leveraged for anything other than "hold onto this thing".

>Am I being overambitious in thinking I could teach myself machine learning and possibly get a job within that sector?
no. there's a bunch of free resources online, and it's not that hard to learn, especially if you like math. and you don't need to be particularly good at programming, either (most ML majors can't program for shit lol). unless you're very self-directed, i'd recommend something with a bit of structure; in particular, i'd suggest checking out these courses (if you don't want to pay for them, you can still audit them for free):

coursera.org/learn/machine-learning
coursera.org/specializations/deep-learning

if you're missing any of the requisite math or need to brush up, check out Khan Academy. i also highly recommend the YouTube channel 3Blue1Brown; the guy gives very intuitive explanations / visual demonstrations of the fundamental concepts of calculus, linear algebra, neural networks, and other math-related shit which give a good sense of their deeper meanings/relationships, and serve as great primers or refreshers

drop SICP and replace it with a math book.

meme/10
Enjoy your "so high IQ I can't even get a job"

Those are good books for actually understanding programming and not being a pajeet, but you probably won't get a job if that's what you're going for. The algorithms in that book are based around imperative programming so you'll need to understand that. Learn you a Haskell is outdated if that's what you're using, Haskell Programming from First Principles is pretty good from my experience.

Overall, remember the most important thing when learning anything is to actually do it. You can read all the books you want but it won't stay in your head unless you try to apply it. And the best way to get yourself to apply it is to actually enjoy it.

>Did you make sure they didn't reference anything specific about any type of any kind? Because otherwise you've written broken generic functions that will explode later.
I am completely sure. They use typeclasses to safely operate on values of the generic types.

>And what did those do? Did they store things?
They were mostly boring transformations like traverse and foldMap.

>Again, when does this happen outside of containers or god-forsaken Factory Patterns?
generic functions in an API.
But you're really hung up on this "BUT DO YOU NEED TO DO IT????" obsession.
No you don't, but why the fuck wouldn't you if you could? You're basically arguing against better code. Which i guess fits in with Google's terminal brainletism

Reminder (not to you specifically, but a reply to your post feels like an appropriate place to bring it up) that Google devs aren't (or at least weren't) allowed to use exceptions in C++.

Yeah, i watched a talk a senior google manager did. And they basically limit their people to a strict subset of sepples because "too many people can't use THING right".

My boss finally gave me permission to wear my fursuit at the office. I'm so excited! Finally my coworkers will get to meet the more important side of me.

So the generics you're so hung up on absolutely having to have are used for common things that Go can achieve with built-in types in the first place
I would get it if you were bitching about boilerplate interface writing for multiple types or something but this isn't an issue in the language

Generics != Inherently better code, or inherently more maintainable, or inherently more anything other than introducing accidents by way of literally being generic unless its used for should-be-STL-but-isnt things like fold or map or storage containers.
But nooo, noo, writing things explicit for exactly for what they operate on is bad. For shame on writing clean clear safe code!

>too many people can't use THING right
How sad that the response was not to train them to use it right.

You shouldn't use exceptions in C++ if you aren't a complete fucking retard though

>"too many people can't use THING right"
Be honest, nobody uses THING in C++ right.

when is tcc going to support c11 atomics?

have you actually gotten a data science job without a degree, though? because i don't know of anyone who has

I can't respect a language which promotes using a product where a sum would be more appropriate as best practice.

>that Go can achieve with built-in types in the first place
in twice/3x the code, sure.
Have fun copy/pasting shit when i can just do it in one declaration.

How would you implement traverse_ in Go?

5 minutes

>But nooo, noo, writing things explicit for exactly for what they operate on is bad. For shame on writing clean clear safe code!
ecee.colorado.edu/ecen5533/fall11/reading/free.pdf

Yes, we all took algorithms and abstract linear algebra. Nothing implements things this way except Haskell, and look how well that does.

Built in container types are one of the only truly generic parts of Go, so no, it would take me roughly the same.

As in tree traversal?

I have a mental health issue that has caused me a fair amount of financial problems. This issue is book collection, either digital libraries or slaves to be placed on shelves in meatspace.
I am searching for the most consolidated single download point of data that I can find. Does anyone have a programming/math/computer science/engineering mega pack of books and videos so I can melt the inside of my brain and slowly replace it with the upcoming IBM Carbon nano tubes

Why isn't Java entirely deprecated already?

Attached: unknown.png (715x70, 16K)

>Nothing implements things this way except Haskell
and ML, Miranda, Idris, Agda, ...

hackage.haskell.org/package/base-4.11.1.0/docs/Data-Foldable.html#v:traverse_

Go "programmers" really are what pike describes in that quote, wow.

sunken cost, same with C and sepples

his mom

Do you mean this one?
>The key point here is our programmers...
>They’re not capable of understanding a brilliant language...
>So, the language that we give them has to be easy for them to understand

in go that would be about 20 different traverses to cover all the primitives.

I was writing this script to capture stills from youtube videos, is there any way to save the captured image as a file directly with a Save As dialog?
Chrome doesn't allow opening new tabs with only data URIs anymore, embedding it as an image in a new tab is just clunky.

window.screencap = function() {
var vid = document.getElementsByClassName('video-stream')[0];
var canvas = document.createElement('canvas');
canvas.width = vid.videoWidth;
canvas.height = vid.videoHeight;
var ctx = canvas.getContext('2d');
ctx.drawImage(vid, 0, 0, canvas.width, canvas.height);
var img = canvas.toDataURL('image/jpeg', 1.0);
var nt = window.open();
nt.document.body.innerHTML = '';
};

Attached: burg5.jpg (1897x1344, 335K)