/dpt/ - Daily Programming Thread

What are you working on?
Previous:

Attached: maxresdefault.jpg (1280x720, 80K)

Other urls found in this thread:

en.wikipedia.org/wiki/Multiple_dispatch
pastebin.com/4mmPxmWd
github.com/shdown/luastatus
pastebin.com/raw/L010cBGB
gitgud.io/TGUILua/TGUILua
smatchcube.github.io/SICP/Ex2.49/
twitter.com/SFWRedditVideos

is freelancing worth it?
I'm going to be kicked out by the end of the month
I'll work min wage tier pay
pls help

Thank you for using an anime image.

I'm toilet training my cat.

i started learning python and recently install manjaro because of some fuckery i did on debian.

my question is should i continue with what i assume was python 2 or use this python 3 with its print (variable) instead of print variable ?

how much more different is it? i dont mind learning just curious as to what the consensus is now or if people are still saying its not ready

try ruby

Can't you just use any python version you want?

fine

well the syntax is slightly different for a reason i've yet to figure out

when popular linux distros completely scrap python 2 in favor of python 3 i will stop using python 2

until then, i see no reason to swtich
it's a pretty small switch anyways

C is an absolutely trash langue holy fuck this is dog shit.

yup thats what i figured, thanks.

>there exists a one liner in python that generates strong AI

what's the problem?

I'm on the fruitful function and recursion chapter of this beginner's book I'm going through and I don't get multiple dispatching. When would I do this instead of just writing if/else statements?

impossible

Where is POO?

Daily reminder that __auto_type, statement expressions and local functions make gnuc acceptable lisp.

yea but it has few "features" and you can write fast code without having to think about a million shit "features"

What do you mean?

why use multiple dispatching instead of just "if x and y = true"
I don't get what the purpose of it is

can you write a top tier performant game engine using only functional programming

ie sicp shit like streams and objects made out of functions and lambdas

Function body is the type signature

yes

multiple dispatching in the sense of what exactly?

why dont people do it then
seems to me a lot of bugs would be avoided

no

maybe

i don't know

I guess checking parameters to recursively do something. I'm only like 50 pages in and I have no programming experience, not sure if I'm explaining it correctly. If you're checking multiple values and doing something different as they change. How is it different than if/else statements? or is it just to avoid writing a bunch if there's a lot of things going on? I tried to read the wiki article

en.wikipedia.org/wiki/Multiple_dispatch

learned C recently, I was casually reading about C++ and couldn't figure out many differences from struct. Most results points out that the real difference is that it can be protected, private or public; whereas structs are always "public".
so what are the advantages of a private/protected class? arent they (and its methods) going to be readable in memory anyway?

can you repeat the question

Multiple dispatch means something different to what you'er trying to explain, I think. Could you post some code that illustrates what you mean?

>Most results points out that the real difference is that it can be protected, private or public; whereas structs are always "public".
That's not true. In C++, the members of a struct are public by default and the members of a class are private by default. You can still explicitly make the contents of a struct private or protected.
There is no other difference between classes and structs in C++, but by convention structs usually only take advantage of C features.
>so what are the advantages of a private/protected class?
Encapsulation.
>arent they (and its methods) going to be readable in memory anyway?
I guess, but you'll have to jump through some hoops to get to them.

I was always told the benefit of private was abstraction. By restricting how other objects can interact with your class you can more more easily change your underlying code and so long as your interfaces remain unchanged anything that depends on your code will be none the wiser.

should I wrap all my pure functions in a thing that memoizes them or just install Haskell

PY-TKINTER

I swear to god I haven't typed so much bullshit in my life and want to die 3 times over already.

I have a csv file with an unknown number of row entries.

My TKinter GUI would be supposed to generate a drop-down list with an entry for every row. How the shit do I write this?
Documentation either sucks or is nonexistant.

Attached: tcl-tk.jpg (297x273, 11K)

func Ack(m, n) {
m == 0 ? (n + 1)
: (n == 0 ? (Ack(m - 1, 1))
: (Ack(m - 1, Ack(m, n - 1))));
}


func Ack((0), n) { n + 1 }
func Ack(m, (0)) { Ack(m - 1, 1) }
func Ack(m, n) { Ack(m-1, Ack(m, n-1)) }


this is just an example from rosetta code of the ackermann function in some language, but they provided a solution using multiple dispatching. what's the real world usage of it? is it faster than if/else?

That looks like method overloading to me.

Though method overloading works because the type is known but not the value.

Not faster, just something something that can clean up code in some cases. Pattern matching like in your example or in Erlang can make certain real-world situations much nicer.

I'd call overloading a subset of multiple dispatch. Idk, Wikipedia might say something different. It doesn't really matter anyway. I don't get why computer science or even coding classes teach this stuff.

Unless proven otherwise I don't believe for a second that the second method is faster than the first. Something that depends on high level language features like that will almost always be slower than good old fashioned if else statements.

I don't know if this is the right thread for my question but I figured this didn't warrant its own thread. I haven't done any programming in 3 years, and all I had before that was a college degree and 2 years fixing bugs in C/C++. How do I get back into it specifically to get a job? I'm not looking to get my dream job or anything, just an entry-level job so I'll at least be working in programming again, but I don't know how to build a portfolio or what's in demand right now.

for an Ackermann function (3, 4)

if/else
real 0m0.159s
user 0m0.198s
sys 0m0.028s

multiple dispatch
real 0m0.319s
user 0m0.373s
sys 0m0.030s

but like said, it can make things much nicer

import tkinter as tk

csv = ['row 1 and stuffs', 'row 2', 'row 3', 'there are probably other rows too']


def variable_changed(current_opt, *evt):
print("Variable changed:", current_opt.get(), evt)


def main():
root = tk.Tk()
root.bind('q', lambda e: exit())
root.geometry("400x300")

current_opt = tk.StringVar(root)
current_opt.set(csv[0])
current_opt.trace('w', lambda *evt: variable_changed(current_opt, *evt))

w = tk.OptionMenu(root, current_opt, *csv)
w.grid(row=0,column=0)


tk.mainloop()

if __name__ == '__main__':
main()

I've been trying to solve all of the problems in the book C: How to program and having a hard time doing it.

Please don't laugh at my brainlet.

At the very least you should post your skills on a LinkedIn profile and put anything possibly impressive on GitHub, linked from there. I know LinkedIn is kinda annoying, but it's easily underestimated how useful the profile is.

Try not being stupid. :^)

code: tests = test[0];

enter code here

Holy shiet thanks that was fast

What.

Making mangled name in C is really tedious.
Function overload and namespace is really the most ground breaking feature of C++

I did update my LinkedIn, but I don't have a GitHub (or anything to put on it if I had one). I figured that's what I need since everywhere I've applied told me they don't want to hire me because I've been out of the field for too long and don't have any of my own code to show. But I don't really know what I should code to start building up a GitHub either.

Enjoy your unstable ABIs, fag.

I'm not a winfag so I don't have to worry about that.

>C: How to program and having a hard time doing it
this sounds like an awful book

Worst case you waste some time making projects for your GitHub but still learn things in the process that'll show if/when you do any interviews. They're pretty good at telling who knows their stuff.

The one thing I want to use C++ for. Sadly, a lot of the language is cancerous. I heard Google makes it tolerable by forcing their engineers to only use a subset of the language. The Python philosophy: make sure there's only one right way to do everything.

>I don't really know what I should code to start building up a GitHub either
I don't think it's that important what you code. Just sitting down and making even a small project will go a long way. Take a week, make something, anything, use github, then try to apply for some new jobs.

It's that type of book you get in college. A perfect book for beginners, the activities come from easy to real hard heuristics and shit (at least, for a beginner).

Attached: 1465509253964.png (1280x720, 335K)

>I heard Google makes it tolerable by forcing their engineers to only use a subset of the language.
You heard wrong, but I can see why a lot of people would make the mistake of thinking that.

How do I do exactly this in C?

function steps(n) {
for (let row = 0; row < n; row++) {
console.log(' '.repeat(n - row - 1) + '#'.repeat(row + 2));
}
}

steps(4);

connection error?

that's not a question?

Attached: 1465333395741.png (549x560, 258K)

Why doesn't this shit work: pastebin.com/4mmPxmWd

I'm gonna be famous with this thing:
github.com/shdown/luastatus

Attached: EdGvYARoq4Q.jpg (833x1133, 225K)

i managed it
for(int row = 0; row < n; row++) {
for (int i = 0; i < n - row - 1; i++) {
printf(" ");
}
for(int j = 0; j < row + 2; j++) {
printf("#");
}
printf("\n");
}


Can I not do this without nested for loops? this feels so stupid, really.

Jow Forumsents, I need help.
I haven't programmed in a year cause of depression and I really need to get back into it.
I need to learn Python (for reasons) but I need to have something to make. And maybe some pointers on how to get started.
Installed the new visual studio with anaconda. Is that all I need?
Think I'm gonna make a simple game for shits and giggles. Maybe starting with pong or something. Any good game libraries out there?

youre not the boss of me

>his language doesn't have vectorized operations
pathetic

for encouragement and comraderie

>complaining about nested loops
what is wrong with you

>writing O(n^2) code
i really hope you don't have a job

>please loop through this N*N matrix faster than O(N*N)

Attached: 5f2fe2e9e4852b63d35b6f93d7d7866b.jpg (400x400, 25K)

your sweet little javascript string method has a loop in it you retarded asshole
you're actually writing a nested loop either way

Attached: 1511028889546.png (349x491, 203K)

git is the greatest technology of the last decade and a half
yea i guess there's mercurial as well

easy
resize it until it is sparse
convert it to sparse format (one of cost, doesn't affect the complexity)
done

are there really no difference? like, no stability updates? backend improvements?

>look mom, this function by itself is THEORETICALLY O(n)

I'm reading K&R and doing task "print all lines in input that are longer than X"
I have no idea why, but the last line always overwrites old ones in memory.
It is not a syntax mistake at least in the (array)allocation or print part, because if I try to print a line that hasn't been put into the array it will output NULL.
#include
#define printlen 5

int main ()
{
char *line; /* array of characters with undefined length */
size_t len = 0;
ssize_t readline;

char* *mem; /* array of character arrays with undefined length */

int i, count;
count = 0;

while ((readline = getline(&line, &len, stdin)) != -1)
if (readline > printlen){/*if line is smaller than 5*/
mem[count] = line; /*put it in the array of character arrays */
++count; /* increment counter for storing lines*/
}

for (i = 0; i < count; ++i) /* print each line in array */
printf("%s", mem[i]);
}


Pwease help!

Attached: 29177698.jpg (460x460, 30K)

which compiler should I use for C# on linux?

you aren't initializing mem anywhere
user, what are you doing

Rewrote my tree manipulation library. When I first wrote it I didn't fully grok trees so the code's now a lot better.

>unironically using K&R after 1990

I only called a variable array of character arrays mem.
Why would I not initialize it? It would not compile without initializing a variable you use...

Oh nevermind, I didn't properly read what you wrote, lol

dumb frogposter

just make the inner loop its own function and hide it in DONTLOOKHERE.c

pastebin.com/raw/L010cBGB
this answer by me was accepted by leetcode and i want to kill myself, is workplace code all like this? its fucking shit. i literally just added more ifs after every trial xd

that many ifs qualify you as an AI programmer

That's not really multiple dispatch, that's pattern matching. It should compile to the same code as the first.

...

gitgud.io/TGUILua/TGUILua
Just released 1.0 for my library that provides bindings for TGUI, a GUI library built on top of SFML.

What did he mean by this?

Attached: enough_musk_spam.png (597x704, 80K)

Attached: tight_control.png (607x825, 97K)

>I suspect that "most horrible person" would disagree.
>c
pronounced si, means yes in spanish dumb amerifat

>elon shitposting
literally nothing new
doubt he's done much programming beyond maybe python

fucking boomer has couple of monsters and shitposts on twitter, nice cringe

I'm doing some useless images thanks to the SICP meme book: smatchcube.github.io/SICP/Ex2.49/

Attached: Ex2.50.png (256x256, 2K)