[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

/dpt/ - Daily Programming Thread

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 327
Thread images: 31

File: daily programming thread2.webm (2MB, 600x338px) Image search: [Google]
daily programming thread2.webm
2MB, 600x338px
old thread: >>55638331

What are you working on, /g/?
Also, there was no active /dpt/ thread on /g/ for several minutes! Stop being lazy!
>>
How do I prevent SQL injections?
Do I just strip out semicolons on user input?
>>
>>55652406
Parameterized queries.
>>
in haskell, without writing it all out, how can I get the list

[[1..2],[1..3]..[1..9]]

that is, a list of lists ranging from 1-2 to 1-9?
>>
>>55652615
>without writing it all out, how can I get the list
just write a nested loo-
>in haskell
lololololololol nevermind
>>
File: 1465342088029.gif (456KB, 260x146px) Image search: [Google]
1465342088029.gif
456KB, 260x146px
>>55652649
great post anon, thanks!
>>
>>55652615
If writing it like that doesn't work then haskell isn't cool enough
>>
>>55652406
hory shet
>>
File: ss+(2016-05-22+at+09.11.02).jpg (37KB, 395x442px) Image search: [Google]
ss+(2016-05-22+at+09.11.02).jpg
37KB, 395x442px
>>55652615
Though of how to do it myself

muhlist = [[1..n] | n <- [2..9]]
>>
>>55652799
>yfw even the simple task of setting up your variables requires solving a puzzle in haskell
>>
>>55652267
/dpt/ help me. I'm trying to learn Schmeme and write a tail-recursion function, but it keeps throwing errors at me.

http://pastebin.com/rfpYRHm3

( define sumOfSquares
( lambda (L)
(sumOfSquaresHelper(L '()) )))

( define sumOfSquaresHelper (lambda (L acc)
(cond
(( equal? L '()) acc)
(( = 1 1 ) (cons acc (+ ( * (car L)(car L))))
(sumOfSquaresHelper (cdr L) acc)))))

(sumOfSquares '(2 2))


Gives me "application: not a procedure;
expected a procedure that can be applied to arguments
given: '(2 2)
arguments...:"

What the fuck do you mean it's not a procedure, it's literally calling sumOfSquaresHelper.
>>
What are some good SDL2 readings?
>>
File: nobulli.jpg (63KB, 572x497px) Image search: [Google]
nobulli.jpg
63KB, 572x497px
>>55652861
Tbh the solution was kind of obvious I was just thinking you could write it as a range.

I'm just going through project euler and all my solutions have been in shorter lines than my C solutions, and it's fun so I enjoy it
>>
>>55652988
python solutions would be even shorter
might as well learn that instead
>>
>>55653003
you should learn golfscript then
>>
>>55653003
except python is ugly as fuck and often slow as fuck, haskell is sexy and pretty fast, functional programming is super fun
>>
>>55652903
Why are you applying L to the empty list?
>>
>>55653006
also wouldn't hurt to learn a couple 'trick' languages that print out things like the lyrics to 99 bottles of beer with a single character source file
>>
>>55652903
>http://pastebin.com/rfpYRHm3
nigga what in the fuck are you doing?
change line three to (sumOfSquaresHelper L '())
>that formatting
why?
>(= 1 1)
why?
read SICP
>>
>>55653071
>read SICP
That's what I'm doing!
>>
>>55653015
python is like twice as fast as haskell bruh stop maymaying
>>
>>55653123
Maybe cpython but otherwise haskell seems faster, I admit I don't have much experience but that's just from what i've seen
>>
>>55653134
no, regular python
cython could be more like 20x faster
haskell is not a fast language by any means
>>
>>55653071
>(= 1 1)
>application: not a procedure;
expected a procedure that can be applied to arguments
given: #t
arguments...: [none]

Look, it just works.
>>
>>55653123
>>55653134
>>55653153
Haskell is faster in Haskell vs vanilla Python. If you use Cython, that would be faster of course. I'm unbiased.
>>
Ask a programming expert anything
>>
>>55653262
Why are you on /g/
>>
>>55653134
>>55653153
>>55653261
cpython is the slow as shit vanilla python interpreter
cython is a different language entirely
>>
>>55653273
You're right, I should be out finding a mate or learning how to cook
>>
>>55653330
Yeah I meant cython
>>
>>55653273
Why are you on /g/
>>
>>55653387
I'm a bad programmer
>>
Cython mentioned
>try the naive implementation of the Fib sequence in C, Python and Cython
>C: ~4 mins
>Cython: ~7 mins
>Python: ~2 hours
Interpreters were a mistake
>>
>>55653411
For fib(50), btw
>>
hey /dpt/, do you like this art style?
http://imgur.com/gallery/mWkeC
http://dyingsungame.com/screenshots/ffyy909uci06fk9til13ddch40ubp5
>>
Is there open source software that incrementally archives 4chan?
>>
>>55653411
python just has a slow design, interpreters can be a lot faster than that
>>
>>55652267
can anyone help me with C++ threads and mutex stuff ?
>>
>>55652406

XSS_clean that shit or force the user to not use shit like semi colons
>>
>>55653443
It looks pretty good but I wish it didnt have so much harsh "blacks".
It would really benefit from some half-lambert so it isnt just shading to black everywhere
>>
File: gskldhgdfhlkgd.png (84KB, 235x250px) Image search: [Google]
gskldhgdfhlkgd.png
84KB, 235x250px
>tfw don't get the job because I studied data structures but all the questions were high level OOP questions

feels bad I was so ready for shit with linked lists, stacks, binary search trees but no it was simple shit like what is polymorphism that I had completely forgotten.

at least I got a nice offer from another company. But fuck me that just stings when I get a call saying they were looking for more "technical experience" basically saying I'm stupid as shit.
>>
>>55653553
You are, desu. Not understanding polymorphism? Seriously?
>>
>>55653553
kek, was asked what polymorphism was in year 1 CS
>>
>>55653553
poly;orphism ain't OOP
>>
>>55653411
Should have done haskell to solve this argument
>>55653015
>>55653123
>>55653134
>>55653153
>>55653261
>>
>>55652958
i just started learning, so i'd recommend lazyfoo.net
>>
>>55653502
>It looks pretty good but I wish it didnt have so much harsh "blacks".
UHH Sexist and RACIST much?!
>>
>>55653553
>high level OOP questions
jesus christ
>>
>>55653606
>>55653626

I learned polymorphism in my first year of CS and just completely forgot how to explain it on a higher level.

that was my first technical interview and I just fucking crashed under the pressure.
>>
>>55653659
That was from awhile ago and I don't know Haskell
>>
>>55652406
Hash everything. If all that gets passed to SQL functions are strings of 0-f, then SQL injections are impossible.
>>
>>55653553
>I get a call saying they were looking for more "technical experience"
I'm sure what they meant was "practical experience"
because in the real world you're essentially never going to implement your own linked list, stack, or binary search tree
so of course someone who knows what they're doing is not going to ask you questions about that

they only care if you know how to solve a real problem and can understand the other programmers code
>>
>>55653730
I don't get how people can "understand" something and not know how to describe it
>>
>>55653799
ok then, explain to me what the word "because" means without looking it up
>>
>>55653738
main :: IO ()
main = print $ fib 50

fib :: Int -> Integer
fib 0 = 0
fib 1 = 1
fib n = fib (n-1) + fib (n-2)


I'd repeat the test myself but I'm too lazy to rerun hour long tests and I don't have the same setup as you to steal your results
>>
>>55653834
"Because" is reversing a modus ponens by exhibiting the premise.
>>
>>55653834
>dictionary.com has just logged a peculiar spike in traffic for the page defining "because"
>>
I'm getting close to finishing reading my first java basics book.
Can someone tell me what I should do next?
I wanted to do this finnish course (http://mooc.fi/english.html) quickly since I tought that the author didnt talk about certain things in depth enough
>>
>>55653799

>I don't get how people can "understand" something and not know how to describe it

well polymorphism is a bad example because I never really used in much in my CS courses.

but for stuff like classes, inheritance, libraries,testing I didn't know the formal definition but I have used it a ton but can only explain it using examples.
>>
>>55653834
Because gives a reason to the statement in front of it.
>>
>>55653799
Explain a number or a computer.
>>
File: 4637572177.jpg (105KB, 600x862px) Image search: [Google]
4637572177.jpg
105KB, 600x862px
>>55653071
Great, it fixed it, now "acc" returns " '() " regardless of however much I cons it.

Fuck this language, fuck SICP, when do I reach meme enlightenment?
>>
I am taking a course on C to learn how Objects work to program making games
>>
>>55653553
Polymorphism is basically you having many different forms of the object For example

We could have a base pie object and then we could have many different forms of the base pie object such as blueberry pie object applepie object and strawberry pie object

>>55653942
Sicp is a meme book it will not help you with relevant programming you are better off learning C or Java
>>
>>55652903
>that formatting

>What the fuck do you mean it's not a procedure
'(2 2) is not a procedure.
>>
>>55653846
>>55653928
My point is more that if you purport to understand something then you should be able to explain the reasoning behind why it exists, what it's useful for, how to use it, and depending on the subject, how it accomplishes its purpose.

Unfortunately, standardized testing typically only covers the "how to use it" and maybe "what it's useful for" parts. If you only remember those parts then you're going to have trouble reconstructing it later and likely don't fully understand it as a concept.
>>
>>55653991

>Polymorphism is basically you having many different forms of the object For example

in the interview I got close to that definition I said functions called based on the data type supplied. but he had to hold my hand a bit on that question and I got hung up on shit I knew.

for example what's the difference between I a class and an object? I knew it in my head but it took me forever to spout the answer because I kept thinking I was wrong as fuck.

my nerves were shot by the 3rd question out of 14 in the interview.
>>
>>55654080
A class is the blueprint of the object. What were the other questions?
>>
>>55654080
>what's the difference between I a class and an object
This is the classic
>How nervous are you?
question
>>
>>55654080
You need to be specific like how I said giving an example relating to actual Object programming your explanation does not relate to objects at all

A good answer is a class is a blueprint and an object is an instantiation of the class
>>
File: afsdfadf.png (432KB, 495x636px) Image search: [Google]
afsdfadf.png
432KB, 495x636px
>>55654098

I took the interview last Tuesday but off the top of my head:

>explain .Net
>what is OOP
>what is functional testing
>what should be put on a Software Specification Sheet?
>what is inheritance?
>if class B derives from class A what else can you do with class B?
>if you test software and it comes back perfect what does that mean? is your software bug free?
>explain use cases
>how do you describe a use case?
>what is a UML?

The questions are straight forward but my nerves were terrible so I probably missed half because I was second guessing myself the whole way.

It was my first technical interview how do I get better and not make my nerves so utter dog shit?
>>
CLion, NetBeans or Code::Blocks?
>>
>>55654373
I have used Code::Blocks for coding and debugging in C which is nice.

Netbeans is good to especially for web dev.

never used CLion
>>
How does one become a god at programming?
>>
File: ifeelit.jpg (448KB, 1200x988px) Image search: [Google]
ifeelit.jpg
448KB, 1200x988px
I'm trying to move from Java to C#, as my uni almost exclusively teaches java until Programming III, where we go into a bit of C.

Any exercises or small projects to get me to make the transition easier? I've noticed there's a large amount of similarities from Java to C#, so it hasn't been hard so far.

also inb4

>poo in loo
>>
What's the best scheme and why is it bigloo?
>>
>>55654477

do it for an ungodly amount of time for your entire life
>>
>>55654477
Spin in a circle 3 times, jump and yell "MAY THE SILICON BE WITH ME" as loud as you can. If it didn't work, you didn't yell hard enough. Try again,
>>
what's a good naming scheme and folder/namespace layout for naming classes in c#?

lets say i'm handling anime episodes and i have individual classes for different cases, would an appropriate scheme be something like namespace Classes.File.Episode with class name "Individual", or just Classes.File with "IndividualEpisode" in there, along with "MultipleEpisodes" and "RangeOfEpisodes"? How much information should the class name convey?
>>
>>55654506
the only right answer :(
>>
>>55654477
Be born autistic
>>
>>55654206
>explain .Net
A mechanism invented by Microsoft in an attempt to lock developers and their software in to the Windows platform
>>
>>55652267

I don't have a question or topic to discuss, I just want to vent. Feel free to call me a retard/faggot.

>be doing job interview
>coding test
>get to the very end
>"cool, so everything works, I just have a few more questions"
>"okay, so what's the time complexity"
>O(n)
>"okay good, so what's the space complexity"
>uhh I'm not sure
>"okay that's fine"
>"we'll be in touch"
>close skype call
>instantly figure out what the space complexity is
>>
>>55654878
what did you have to code?
>>
I want to learn ruby and build my portfolio. Anyone got any fun little programming project ideas?
>>
>>55654891
yeah learn javascript or java instead of a hipster retard language
>>
>>55654886
I'm paranoid about people finding me out, so I'm not gonna say exactly, but I will say it was super simple (like 1st year CS undergrad homework simple), it's just that I used some C++ standard library stuff which made me think figuring it out was more complicated than it actually was.
>>
>>55654932
I already know java, any ideas for javascript?
>>
>>55654955
Was it FizzBuzz? Don't tell me you messed up FizzBuzz after all that training we gave you.
>>
>>55653991
>Sicp is a meme book it will not help you with relevant programming you are better off learning C or Java
It's helped in that I now can't turn anything that's more than 30 lines of code into a function.
>>
File: *ling ling* it's for you.jpg (64KB, 720x552px) Image search: [Google]
*ling ling* it's for you.jpg
64KB, 720x552px
>>55654932
>javascript instead of a hipster retard language
dude wut
>>
>>55655018
No, it was more of a string processing problem. And I didn't mess it up, I just had a brain fart when the interviewer asked me about it at the end, so he possibly thinks I'm stupid even though it worked.
>>
>>55655079
At the end of the day javascript > ruby.
>>
>>55654874

Tell me when has anything made by Microsoft not been a attempt to lock developers and users into the windows platform?

I mean damn the company releases open standards and then doesn't follow them in their own products.
>>
>>55655147
Yeah, but consider how subtle that is
compared to
>Here's a framework that your users will have to install in order to run your software.
>We will release it only for Windows.
>>
>>55655147
hololens uses unity as a graphics engine, does that count?
>>
>Write a recursive function for generating all permutations of an input string. Return them as a set.

DAE suck ass at recursive problems
>>
>>55655079
how is js hipster
do you also think that the web is hipster?
>>
>>55655360
Read "the little schemer" senpai
>>
>>55655107
Was it reverse a string?

was it remove each x element from the string?

was it remove duplicates from a string?

I need to knoww
>>
>>55654932
>javascript or java
ehm, both are hipster retard languages
>>
>>55655400
I PM'ed you the question :)
>>
>>55655446
can you pm it to me too??
>>
how do you pm others? i cant find the button :(
>>
>>55655512
It's the x in the corner
>>
>>55655499
Sorry, I gave that other guy the only copy of it I have :(
>>
what x?

ehm, you can resend it
>>
>>55655446
>>55655499
>>55655512
>>55655537
>>55655538
well memed my friends this is almost as memed as Java is a shit language for no reason what so ever
>>
>>55655555
>java programmer trying to b8 real programmers again
>>
>>55655555
But Java is shit for multiple reasons.
>>
>>55655555
ayyy nice get friendo
what is "memed" though?
>>
>>55655562
Java programmers are real programmers

your argument invalid

>>55655566
You are going to list reasons which do not matter in real most programming applications but obscure reasons no one cares about
>>
>>55655552
here dude
>>
>>55655586
Yeah, "any argument you may have is invalid", sure then.
>>
>>55655613
>actually arguing for my statement that java are not real programmers
you're embarrassing me
>>
>>55655612
no work :(
>>
Does anyone understand how Kadane's algorithm works? It computes the maximum contiguous subarray sum for a given array.

int Kadane(std::vector<int> const &a)
{
int max_current = a[0];
int max_global = a[0];

for(size_t i=1; i < a.size(); i++)
{
max_current = std::max(a[i], max_current+a[i]);
max_global = std::max(max_global,max_current);
}

return max_global;
}


I don't get how to come up with this. The articles I've read and youtube videos I've seen aren't helpful either.
>>
wtf my fellow gamers btw have you seen dat boi meme? its PRICELESS, I cant get the PM stuff going :(
>>
>>55655695
what meme tfw /r/OutOfTheLoop Lol hah
>>
>>55652267
Fuck off this programming fag meme
>>
>>55655739
bruhhhh
>>
>>55655671
I think Kadane's algorithm says that the maximum contiguous subarray sum (MCSS) for a given subarray ending at index i (that is the subarray's last element is i) can be one of the following:

1. MCSS of the subarray ending at (i-1) + array[i]
2. array[i-1] itself

So you go through calculating the MCSS for each element in your entire array (max_current).

The max of all the MCSS for each element is max_global. The key part is calculating all the max_current values for each element of the array.

The trick is recognizing that the max_current for a given element array[i] is either array[i] OR MCSS[i-1] (ie your previous max_current value)+array[i]
>>
>>55652267
So I'm trying to mess with a game for practice purposes. Never done anything like this, so I'm having some trouble.

In Cheat Engine, I've found the offset for what I think is the mine timer, but its in this format: "minesweeper+54892"

How do I read/write this address? I don't know what to do.
>>
>>55656090
it's short hand for "base address of the minesweeper.exe module + 0x54892"

in your program if you want to figure out the base address dynamically you can iterate through the loaded modules in memory

for now you can look it up in cheat engine or click "add address manually" and put in minesweeper.exe to see what it is
>>
Sorry for asking this since I assume it's a super common question but I'm having a ton of issues with trying to learn coding.


Regular language comes super easy to me (taught myself Japanese and German) but programming is super hard for me. I tried python but i was shit at it.

Are there any structures courses you guys reccomend? Codecademy was awful in my experience.


Thank you very much
>>
>>55656139
Also are there any useful languages other than python you would reccomend me to learn? I read the sticky but couldn't come to a distinct conclusion. All I know is that I don't think python is a good fit for me
>>
>>55656090
I wrote this some time ago, should help you get started if you're into C++:

http://pastebin.com/aa1HksAX
http://pastebin.com/SqL6wx9f

I guess it's fairly well commented.
>>
File: 1399999089049.jpg (183KB, 850x850px) Image search: [Google]
1399999089049.jpg
183KB, 850x850px
Could someone PLEASE explain to me what a "symbol" is in lisp-family languages, and what purpose they serve?

I have literally NEVER seen a language with a "symbol" data type, and I don't understand what you can do with symbols that you can't do with strings.

Any guidance?
>>
>>55656205
I was in the same boat it was very difficult for me to learn the mindset of programming. What did I do? I tried code academy first and failed horribly did not understand programming because it was hand holding. I then tried How To Think like a computer scientist Python interactive book then they explained actually how a programmer thinks and I slowly started to get it. What did i do next? I enrolled in a university java programming course and had professor explain things to me privately and went to teacher assistants for help then I started to program small applications on my own.
>>
What the fuck do I program???
Do I just go through this algorithm's 3rd edition and code all the fucking algorithms in it??? I DON'T KNOW WHAT TO DO!!!
>>
>>55656205
the only way to learn is making small programs my man, take a languaje, i would recomend c but thats my opinion, look for a book, and make programs, simple things as printf("hello world") will make you learn
>>
>>55656363
or you could take java, use netbeans as ide, video2brain have good starting videos
>>
>>55656386
I already have been coding in Java for like 1 year as part of my college training. Though to be fair I took my last class in 2012 and have been neet since. Last class I took was a Comp organization class.

Have not programmed since. HELP ME!!
>>
>>55656277
http://stackoverflow.com/a/8847767
>>
>>55656363
>algorithm's 3rd edition

Lolwut, 4th ed. has been out for a while now dude.

Contribute your shit to the master race algos repo https://github.com/kennyledet/Algorithm-Implementations
>>
>>55653443
Yes
>>
>>55656436
Talking about this.

https://www.amazon.com/Introduction-Algorithms-3rd-MIT-Press/dp/0262033844
>>
>>55656325
>>55656367
Thank you very much guys. Appreciate it
>>
>>55653628
you don't know anything about OOP then
>>
>>55656518
>https://www.amazon.com/Introduction-Algorithms-3rd-MIT-Press/dp/0262033844

Ah. But still, join Algorithm-Implementations if you want to have your work featured on a relatively popular site, for employers.
>>
>>55655079
hipsters use stupid javascript libraries and frameworks and its really a bunch of shitty meme names but javascript is not a hipster language, its literally the web as you know it and couldn't be further from hipster
>>
>>55656554
Forgot link: http://algorithm.zone/
>>
>>55655940
I just had to do a programming assignment for a 2D disjoint subset, using dynamic programming, this past week in C. I understand the 1D way, but they didn't really explain how to do it in 2D. Consider yourself lucky.
>>
>>55656554
Last commit is fucking 2015 bro!!! WHAT THE FUCK DO I PROGRAM!!!
>>
>>55656736
Something you are interested in

What are you most interested in?
>>
Just fixed clang::TypeName::getFullyQualifiedName to fully qualify parameter type names if you pass it a function type
>>
File: 1468969394661.jpg (2MB, 5000x2813px) Image search: [Google]
1468969394661.jpg
2MB, 5000x2813px
haha good watch :D
https://www.youtube.com/watch?v=LEgxS_vzQjU
>>
>>55656745
Killing minorities. Saving the white race. Cute girls like Anzu! Beethoven. Japanese video games. Aristotle. Having fun on 4CHAN!!!
>>
>>55655360

import sys, math, random, collections, operator, functools

get_perm = lambda s, strings=set(): (
strings
if len(strings) == (
math.factorial(len(s))
/
functools.reduce(
operator.mul,
map(
math.factorial,
collections.Counter(list(s)).values()
),
1)
)
else
get_perm(
''.join(random.sample(s, len(s))),
set(list(strings) + [s])
)
)
>>
programming challenge of the day

Create a simple chat room application
>>
>>55653628
polymorphism has to do with inheritance and is one of the 3 tenets of OOP
>>
>>55656800
>not creating 2 AI bots that chat with each other and learn indefinitely
it's like 2010s passed you by /dpt/
>>
>>55656833
I said simple you troll
>>
>>55656235
>http://pastebin.com/aa1HksAX
>well commented
no comments
>>
>>55656885
except that's the `simple` from 10 years ago. keep up
>>
>>55656822
I thought the only tenets of OOP were message passing and encapsulation
>>
>>55656910
alright champ post yours
>>
>>55656969

the big three are abstraction, inheritance, encapsulation

too bad I couldn't remember it for the interview
>>
File: mul.png (3KB, 384x220px) Image search: [Google]
mul.png
3KB, 384x220px
did i do it?
>>
>>55657029
why is no one replying to my post? are the 4chan servers down?
>>
Quick!

Write a function that swaps two ints in Java
>>
>>55657056
trindad says no
>>
>>55657029
You use multiply anyway.
>inb4 that's the joke
>>
>>55657082
Wow you figured it out :^)
>>
>>55656765
please remove this
>>
I need to have a continuous 1KB block of memory, containing several structs with data that must be known at compile time, in C. What's the best way to go about this?

I thought I could contain it all into a packed struct, but I forgot that you can't have structs initialized inside of a struct at compile time.
Am I stuck using gcc linker magic to make a separate 1KB region of memory where I throw all my shit in, or is there a better way?
>>
>>55657164
Why can't you allocate 1KB on the heap, and access individual elements by casting from void* ?
>>
>>55657215
Don't have any heap memory.
It's embedded code from work that fell into my lap yesterday, and it's suffering from feature creep and needs more features added on to it apparently.
>>
>>55657164
>you can't have structs initialized inside of a struct at compile time
Yes you can.
struct {
struct {
int a;
} a;
struct {
int b;
} b;
int c;
} s = {
.a = { .a = 1 },
.b = { .b = 2 },
.c = 3
}]/code]
>>
Hey panopticon guy are you lurking this thread by any chance? Any ETA on ELF support?
>>
>>55652267
Babby's first JSON-RPC

I'm writing personal server utilities in Go which I can use via websockets.
>>
>>55656568
This, fuck frameworks and libraries that don't create functionality that's non-trivial to do with vanilla JS.
>>
>>55653553
lol?
>>
>>55657717
xD?
>>
>Tfw you are shit at programming but you want to be good

someone post an easy programming problem and you can laugh at my attempt to solve it
>>
>>55657624
only FSK support for now
>>
>>55657756
Make me a not shitty recursive Fibonacci function
>>
>>55657756
print all elements from a list recursively
>>
>>55657756
Scrape all current post titles from /g/ and print them to stdout.
>>
>>55657751
:^)
>>
>>55657826
d:^)
>>
Trying to into Haskell but still having some trouble trying to stop thinking of problems the way I'd solve them normally.

Also trying a game again but got stuck with too much OO bullshit.
>>
>>55657886
post code

Haskell isn't bad for imperative programming either desu
>>
>there are people in this thread who sincerely struggle with oop
>>
>>55657903
I wish I struggled with OOP, it's a god awful paradigm
>>
>>55653411
You want to do one high performance function in interpreted language, you are just wasting the potential. Interpreted languages exist to ease the burden on the programmer side, not on computers. If you want performance, nothing is stopping you to move the function to the C side and moving the result back. That's why there's no good game engine purely on interpreted languages, they are slow for a reason.
>>
>>55657768

public static int fib(int n) {
if (n == 1) return 1;
int fib1 = 0;
int fib2 = 1;
return fib(fib2 - fib1);
}

public static list(int[] arr)
{
int num = arr.length() - 1;
return list(num - 1)
}


>>
>>55657903
>There are people here who like OOP
>>
>>55657976
>not shitty
>>
>>55657976
Well

Can't say there wasn't an attempt
>>
>>55657976
>Fib
>Only ever returns 1
>>
>>55657978
>there are NEETs here
>>
>>55657978
>There are Pajeets on /g/
>>
>>55657978
>not being a mouth-breather is the same thing as liking oop
you probably can't even fizzbuzz and have the gall to opine on topics you know nothing about.
fucking summer
>>
>>55657992
>>55657995
>>55658003
I don't understand recursion
>>
Prints an ASCII histogram from a list of digits 0-9 based on frequency

histogram :: [Integer] -> String
histogram = histAns . histIter . histStart

histAns x = snd $ (iterate histIter x) !! (maximum (fst x))
histIter (a,s) = (\(t,y) -> (t,y++"\n"++s))
(unzip [((max 0 (x-1)),(if x /= 0 then '*' else ' ')) | x <- a])
histStart c = ([length (filter (\t -> t == n) c) | n <- [0..9]],
"==========\n0123456789\n")
>>
>>55658009
>>55658018
PaNEETs?
>>
>>55658045
To what end?
>>
>>55658044
IDK, but to understand recursion I had to actually write the functions calls in a paper. And then how everything "unfolds" became apparent.
>>
>>55658044
do you understand what a function is?
yes? you understand recursion.
no? have you considered learning how to program?
>>
I used regex in my project today; praise me

https://github.com/ErikHumphrey/incremental-phone-number-entry/releases/tag/0.2
>>
>>55658078
what do you mean? I have no idea how it works I usually use loops to do problems
>>
>>55658089
It's shit
>>
>>55658096
>t. pajeet or year 1 cs student xddd
>>
>>55658078
literally just read through the function and actually think about what it's doing
>>
File: 1448669112662.jpg (3MB, 2560x2880px) Image search: [Google]
1448669112662.jpg
3MB, 2560x2880px
I like OOP
>>
File: OOP.png (69KB, 1210x467px) Image search: [Google]
OOP.png
69KB, 1210x467px
>>55658114
>I like OOP
>>
File: 1473776.jpg (15KB, 400x400px) Image search: [Google]
1473776.jpg
15KB, 400x400px
This is the face of /dpt/
>>
>>55658089
>this is the average poster on /g/
1. get a haircut
2. hit puberty
3. learn to smile

otherwise good job
>>
>>55658096
Recursion is never used in real application don't worry about it and only focus on processing loops
>>
File: 1464632537832.png (152KB, 1948x858px) Image search: [Google]
1464632537832.png
152KB, 1948x858px
>>55658133
>not even 18
Sounds about right, judging from the recent influx of Python supporters
>>
>>55658133
erik "computer hacking is my specialty" humphries
>>
>>55658096
Just try to learn recursion, sometimes it's better than a loop solution (and better if it has tail-call optimization.)
>>55658111
That was the first I found a recursive function.
>>
>>55658149
the first time*
>>
>>55658096
in order to understand recursion, you must first understand recursion.
>>
>>55658149
>recursion, sometimes it's better than a loop solution
nope, you should never use recursion in production code
>>
>>55658133
nice teeth you got there faggot
>>
>>55658179
>you should never use recursion in production code
TCO function calls are as efficient than for loops
>>
>>55658179
I shall do as I please
>>
>>55656769
WELL?!?!?? WHAT THE FUARK do I do?
>>
File: 1457975691973.gif (1MB, 245x280px) Image search: [Google]
1457975691973.gif
1MB, 245x280px
>>55658198
>are as even than
come on
>>
File: index.jpg (12KB, 225x225px) Image search: [Google]
index.jpg
12KB, 225x225px
>>55658089
HAPPY BIRTHDAY!!

HAPPY BIRTHDAY!!

HAPPY BIRTHDAY!!

HAPPY BIRTHDAY!!
>>
>>55658218
I was considering saying "more efficient", since in some cases it is indeed true (no incrementing)
>>
>>55658229
shut the fuck up eric
>>
void myFunction(int x = 15) {
if (x == 0) return;
/* do stuff */
--x;
}

> void can be altered so that it returns a value each iteration,
> and returns a final value (that could be ignored if not needed)
> you can choose the starting point (or leave it at a default)
> or if you don't want choice, create another function that forcibly calls it with that
void myFunction() {
for (int x = 15; x > 0; --x) {
/* do stuff */
}
}
>>
>>55658248
Never fucking reply to me again unless you're contributing to the thread.
>>
File: 1458104751364.png (73KB, 180x180px) Image search: [Google]
1458104751364.png
73KB, 180x180px
>>55658272
no
>>
>>55658269
whoops, should call myFunction(x-1)
>>
File: qqqqq.jpg (127KB, 500x500px) Image search: [Google]
qqqqq.jpg
127KB, 500x500px
Guys how do I hack the terminal?
>>
>>55658071
Just an exercise to try doing things functiotally
>>
>muh C casting
>muh global variables
>muh impurity
Cfags on suicide watch
Haskell confirmed for unsafe masterrace

test :: IORef [a]
test = unsafePerformIO $ newIORef []

main = do
writeIORef test [42]
bang <- readIORef test
print (bang :: [Char])
>>
Java Object Oriented Programming is the best and most reasonable way to program in modern times
>>
>>55658677
I guess I just wasn't made for these times.
>>
>>55658677
++
>>
Struggling with this assignment question that asked me to fill and ArrayList with Contacts and then sort them by name and then by number. The question has a 'hint' at the end to use the Comparable interface with a static class variable, but if I'm going to sort something more than once shouldn't I be using Comparator? I'm so fucking confused.
>>
>>55658747
>Comparable
https://www.mkyong.com/java/java-object-sorting-example-comparable-and-comparator/
>>
>>55658747
Comparable implements an overridable comparator function that you can then define. You need two comparable functions so you should create two static functions that return a Comparator. Define one that sort by name and the other to sort by number. When you then want to sort these you should call
Collections.sort(listToSort, Type.getNumberComparator());
>>
Why is Swift so comfy?
>>
>>55658677
OOP is fundamentally flawed.
>>
>>55658813
Apple shill pls go
>>
>>55658784
>>55658801
Once more into the void. Thanks.
>>
>>55658818
What?

>>55658814
No it's not you are wrong it is great way to make programming logical and make sense and organize your code easily. It makes it much easier to maintain changing one specific part in a class.
>>
>>55658848
>Once more into the void.
I'm going to attempt the question again.
>>
>>55658815
It's open source now you know.
>>
>>55658848
Good job spouting the crap that someone else told you.
Your argument doesn't have any substance.
>>
>>55658875
You have 2 good sources explaining it well goodluck
>>
>>55658747
Assuming this is java, iirc:

The interface comparable stipulates that a class implementing it must implement a method of such signature:
 InstanceA<T>.compare(InstanceB<T>) 


Where the idea is that the method will return a -1, 0 or 1 or something along those lines as the result of your compare method. The method itself is up to you as to what constitutes InstanceA being less than, equal, or greater than InstanceB.

Been years since I've done that though
>>
>>55654497
Many room for poo

>>55653836
>>55653411
Haskell (524 sec):
fibbad :: Int -> Int
fibbad 0 = 1
fibbad 1 = 1
fibbad n = fibbad (n - 1) + fibbad (n - 2)


main :: IO ()
main = do
putStrLn "Calculating fib(50) naively"
print $ fibbad 50


C (166 sec):
#include <stdio.h>

int fib(int n) {
if (n <= 1) {
return 1;
} else {
return fib(n - 2) + fib(n - 1);
}
}


int main(int argc, char** argv) {
printf("Fib(50): %d", fib(50));
}


Both were compiled with -O2
>>
>>55658955
So Haskell takes a bit more than 3x the time as C
>>
File: 1.jpg (31KB, 446x442px) Image search: [Google]
1.jpg
31KB, 446x442px
>>55658818
>>
>>55658955
>>55658973
Actually my C implementation is wrong since it is a 32-bit int that overflows, but you get the idea.

GHC (for Haskell) uses a big enough Int on my system, but I could have used the Int64 type if I wanted to be sure anyway.
>>
Now that variadic templates exist, why isn't std::cout and stream operators in general deprecated yet?
>>
File: 2.jpg (22KB, 507x240px) Image search: [Google]
2.jpg
22KB, 507x240px
>>55658818
using it
>>
>>55658973
Yeah but it's S T A T E L E S S
>>
>>55658955
I'm surprised Haskell didn't just calculate "fibbad 50" at compile time

No unsafePerform.., and it's not an IO
>>
>>55658986
Comparator != Comparable
Comparable allows the sort method to do the comparing on its own using the compare method.
>>
>>55658955
Also it may be possible to get better haskell speeds by using unboxed integers, but likely GHC already did that optimization.

>>55659017
So is the C version. Maybe a better benchmark would be something that is usually done statefully in C
>>
>>55659042
Yeah but you can't use two implementations of Comparable on the same class.
>>
>>55659066
You just do both comparisons on the one compare method.
>>
>>55659084
No. Unless you're trying to say that they should be ordered with field priority, in which case that is definitely not what the anon was asking about.
>>
>>55652267
Trying to figure out how OO works. I don't know why people get confused about functional programming, it's loads easier than OO.

>inheritance, mixins, interfaces, traits, accessing fields and methods from other objects, etc.
Vs.
>pass a function to another function along with relevant arguments, return data and continue manipulating data
I'm just trying to figure out how to write a GUI using the standard library in my language. Simple OO is kind of enjoyable and fun, but yeesh. I've never done any kind of object-oriented/class-based programming before.
>>
>>55659375
How did you get started with programming? I've never met anyone that started with functional programming, usually people get indoctrinated in OOP right away.
>>
>>55659375
It's not that any which way is especially hard to teach, it's that it's harder to go from one paradigm to another because it's so foreign to what you know.
>>
>>55659417
>>55659421
I find Object programming easier than mathematical function programming it is too difficult!
>>
File: image.png (2KB, 256x29px) Image search: [Google]
image.png
2KB, 256x29px
>>55652267
How can you edit a file_field button's height? I can make it wider or narrower, but not taller or shorter. At best, I've been able to create an invisible space around it that turns your cursor into a hand, indicating that when you click it something will happen, but it's just a ruse. For what it's worth I've also managed to turn the button/file_field fully invisible, partially visible, and fully invisible under normal circumstances but partially visible when you hover your cursor over it.
>>
>>55659417
Read that How to Design Programs was a good book to learn programming, read it through and did all the exercises, then did Little Schemer. I've never even programmed in anything outside of Lisp. I've been programming for about a year or so now. I haven't had any real need to venture outside of this language, so I never bothered. My language has first-class classes and objects as well as functions, and the GUI library is written using it so I figured it would be a good idea to start learning. On some of the trivial fizzbuzz-level toys I did, OO seemed like a sometimes convenient tool since you can keep data and methods acting on them together, but I honestly have no idea how I would adapt algorithms to it for any larger-scale programming.

>>55659421
I guess that's the case. I feel that if I can get enough of a handle on it to get everything off the ground I'll be able to go back to programming functionally and separate the class/object-based GUI into its own module. It's such a weird jump. I guess this is how a lot of other programmers feel when they jump into FP, although I feel that conceptually FP is a lot simpler than classes, objects, inheritance, interfaces, etc.
>>
File: VimProgress_jul_19_2016.png (13KB, 646x542px) Image search: [Google]
VimProgress_jul_19_2016.png
13KB, 646x542px
Working on the vim setup for my newly installed linux system now that I'm not side tracked by other tasks. Any suggestions for general dev plugins to try aside from what I've got?

I kept it pretty spartan on the laptop and it's served me well. Still gotta add fugitive or vcscommand.
>>
>hut dur state is a bad thing
Jesus christ kill yourselves.
>>
>>55659689
who are you quoting dude
>>
>>55659689
You're a fucking idiot. Shared state is fucking horrible, and makes programs difficult to reason about.
That is why OOP is shit: it encourages shared state.
>>
>>55659785
Then why is OOP dominating the programming world right now all over and especially Java which every single programming job is all in Java. Simple because it is the best paradigm right now
>>
>>55659689
>>hurr durr state is a bad thing
>hurr durr monadic state is a bad thing
>>
>>55659809
Just because something is popular, it doesn't mean that it's good.
>>
>>55659829
All professors and all software professionals I have worked with have all said OOP and Java are both good compared to a random non professional guy who claims it is shit

Who would you rather trust professionals or some random dudes opinion?
>>
File: comfy.png (82KB, 1183x628px) Image search: [Google]
comfy.png
82KB, 1183x628px
Daily reminder - if your language isn't functional, it's dysfunctional
>>
Is there any sane way to implement recursion in lexical scopes without "lec-rec" constructs
>>
>>55659860
Again, popular != good. Don't drink the OOP koolaid.
In order to write high quality programs, you need to be able to understand your program's state and how it changes over the program. State is everything.
Shared state makes programs difficult to reason about and leads to hard to maintain, buggy code. That's why people give you shit for using global variables.
However, in your fantasy OOP universe, you've encapsulated all of your state into little units, but it doesn't solve the shared state problem. You're still sharing staring state between your objects. OOP even encourages it.
The functional programming approach to dealing with shared state to to remove state all together. Why track state over the lifetime of your program if you don't have to? It seems clear that this is the direction that people are going towards.
Java and OOP are shitty relics of the past.
>>
>>55659960
fix :: (a -> a) -> a
>>
>>55659981
That's what let-rec is...
>>
>>55659976
They are still regarded as best practices for OOP and they are not relics because they are taught everywhere and all the jobs are OOP java jobs or C
>>
>>55659990
Why not just have fix as a builtin function?
No need to have let rec syntax
>>
>>55660007
That's LESS sane than let-rec.
E.g.
fn foo () { bar() }
fn bar () { foo() }

How do foo and bar locate eachother?
>>
>>55659995
Do you ever question anything? Do you ever try to improve?
Software development is still a very young industry. People don't have all of the answers.
Doctors use to just use bloodletting to cure any sickness. People eventually realised it was shit and moved on to more modern medicine practices. Are you going to continue being an OOP-weenie, bloodletting to the very end because it's "common practice"?
>>
>>55659689
In this day and age state isn't really necessary except in limited memory use case like embedded systems. In every other use case, state is more of a liability than it is useful.
>>
>>55660048
What kind of software do you write?
>>
>>55660043
>Comparing medical procedures to programming
>calls me a weenie

This is why your argument is invalid
>>
>>55660023
Switch the function you call
>>
>>55660065
>Complaining about insults on 4chan, especially one as tame as 'weenie'
Also, do you care to explain why you think my analogy is bad.
>>
File: code.png (27KB, 675x697px) Image search: [Google]
code.png
27KB, 675x697px
Making a program in C that displays the Greatest Common Denom. of a fraction while using structures. Anyone know why this is telling me that Line 14 is a "struct Fraction ** " when it is supposed to be "struct Fraction * "?

Little bit confused why its telling me its a pointer of a pointer
>>
I'm starting to think the haskell community is paying people to shill.

Each paradigm has it's strengths and weaknesses. Functional isn't the answer to all problems, OOP isn't always shit.

Procedural is good for separating data from functions that operate on it. OOP is nice for representing data that is tightly coupled to functions. Functional languages are insanely flexible and are good at generating very generic abstract expressions of problems.

Each is just a tool. Use the one that fits and most logically expresses your current problem.
>>
>>55660103
I would agree with you, but metaprogramming is actually better than all other paradigms
>>
>>55660103
>OOP is nice for representing data that is tightly coupled to functions
OOP at its core is about the encapsulation of state. Not
thing.do(other_thing)
.
>OOP isn't always shit
No, it always is.
>>
>>55660114
1) Metaprogramming isn't a paradigm
2) Metaprogramming is just the noisier, uglier brother of abstraction
3) template <template <typename...> typename Temp, typename S, S n, S n2>
>>
>>55660102
On line 20, you're declaring f as a pointer. You're then passing &f on lines 24-26, making it a pointer to pointer.
>(*f).numer
f->numer is a shorthand for that.
>>
>>55660114
notice haskell wasn't mentioned until fib was brought up, since literally all it's good for is simple math
>>
>>55660157
(You)

>>55660103
No, it's just other people have started trying it and realising how good it actually is.
If you were here a few months ago you'd know we had a lot more functional programmers
>>
>>55660177
Haskell is really nice, I fucking love it and I'm a total languages nerd, however writing haskell code becomes a Monad mess and debugging can be frustrating.
>>
File: magagrill.png (170KB, 376x328px) Image search: [Google]
magagrill.png
170KB, 376x328px
>>55660061
shitty
>>
>>55660177

I've been here for years. The haskell pushing has been noticeably worse than usual.
>>
I'm making a graphics builder for SCADA stuff as a side project for my job.

Anyone have any experience with standard control mechanisms for select/drag/hittest/etc? I'm technically an EE so I've never had to build something like this before. I've got the draw and hittesting working, but for some reason I'm stuck on how to implement the select/multiple select and how to handle mouse move/mouse down/mouse up
>>
>>55660195
>>55660048
I'm actually really curious, not trying to be a dick or anything. I like Haskell but I wouldn't use it to actually build anything and I want to know how people put it to use.
>>
>>55660192
>tfw lift lift lift lift get
>tfw no structural effect system
>>
>>55660212
To be specific, not how to implement it function wise, but how I should implement the overall if this->then this stuff. Programming es hard
>>
I'm leaving this as a repository for people to argue why their paradigm of choice is best and how it is practical in any of the following common applications of programming:


language design
e.g. C compilers, assemblers, parsers, type systems
embedded programming
e.g. real time systems, microcontrollers
drivers, kernel
e.g. graphics drivers, other hardware interfaces
numbers, statistics
e.g. machine learning, number crunching
web dev, front end
e.g. facebook, google, tinder
web dev, back end
e.g. facebook, google, tinder
graphics, audio, video
e.g. photoshop, premiere, ableton
video games
e.g. crysis, league of legends, WoW


Also feel free to contribute additional fields.
>>
Repost from/sqt/ because it's almost dead:

If I have a text file containing, say, 2,000 names, and I need to choose one randomly, how would I do it? I don't think storing it in an array would be useful... Would It require linked lists?
>>
>>55660245
RNG from 1-2000, then iterate to it. No need to store it, unless you're doing more to it
>>
>>55660245
Take advantage of text streaming.
First iterate through the entire file just to count the number of lines. And then choose a random line #, and then repeat the first step but stop at the n'th line, and there you go.
>>
File: 1468201535553.gif (1MB, 331x1003px) Image search: [Google]
1468201535553.gif
1MB, 331x1003px
>job is to convert C# to Node.js
>implement features in Node.js

have I become a pajeet? will the initial foray into non-neet life be complete shit?
>>
>>55660243
OOP doesn't help with any of those.
>>
>>55660245
#!/usr/bin/python3
import random
print(random.choice(open('names.txt').readlines()))
>>
>>55660267
Alright... Sounds simple enough... Thanks!

Something like this seems to be working, I'm just curious if there's any "more" efficient way to do it;

    std::string processingString = "";
int numOfLines = 0;
while(inputFile >> processingString)
{
numOfLines++;
}
inputFile.clear(); //clear the buffer
inputFile.seekg(0, std::ios::beg);

srand(time(0));

int wantedNum = rand() % numOfLines;

std::cout << "Random Number = " << wantedNum << std::endl;


for(int i = 0; i < numOfLines; i++)
{
inputFile >> processingString; //To advance to the desired line number
if(i == wantedNum-1) //Because
break;
}
std::cout << processingString;
>>
>>55660372

I really fucked up the link
>>
Been learning perl recently since I know I'll be needing it for a job I'm starting soon.

Anyone can recommend some links with exercises. Please, nothing math related ie project Euler etc. Coming from a sys admin role if that helps
>>
>>55660314
#!/usr/bin/ruby
n = 10 # take N lines at random
puts ARGF.readlines.sample(n)
>>
>>55660023
Make them addressable (whatever that means in your compiler/interpreter implementation) before they are actually defined
>>
>>55660227
Oleg's "Extensible Effects" or "More Extensible Effects" are structural effect monads. The second one's paper shows better performance than monad stacks, I think, but maybe not, I don't remember. The original extensible effects had issues like requiring Typeable and using Dynamic, which is slow
>>
>>55660717
I mean language support
Does Idris use a flat effect system?
>>
>>55660199
>>55660103
I do it for free
>>
>>55660723
I mean I know you can attach effects to variables, but I believe that's just a consequence of dependent typing and not an actual structural type & effect system

Don't suppose there are any languages with flat or structural coeffects?
>>
>>55660245

my attempt in C

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main(int argc, char *argv[]) {
FILE *f = fopen(argv[1], "r");

int c;
int count = 1;

while ((c = fgetc(f)) != EOF) {
if (c == '\n')
count++;
}

srand(time(NULL));
int picked = rand() % lines;

rewind(f);

while (picked >= 0 && (c = fgetc(f)) != EOF) {
if (c == '\n')
picked--;
else if (picked == 0)
putc(c, stdout);
}

fclose(f);
return 0;
}
>>
>>55657056
>>
>>55658279
>>55658218


Who dis is?
>>
>>55662310
public static int[] swapInts(int a, int b){
int[] result = new int[2];
result[0] = b;
result[1] = a;
return result;
}

Why not this instead?
>>
Or even
public static int[] swapInts(int a, int b){
return {b, a};
}
>>
>>55662457
>>55662485

I wanted to exhibit how you could do it using addition and subtraction and the same variables, since it's a question asked by some interviewers these days.
>>
>>55662485
>return {b, a};

That's not a valid Java statement bro
>>
public class Pointer<A> {
public A val;
public Pointer(A a) {
val = a;
}

public static swapInts(Pointer<Integer> a, Pointer<Integer> b) {
a.val = a.val + b.val;
b.val = a.val - b.val;
a.val = a.val - b.val;
}
};


Might have fucked up java syntax
Thread posts: 327
Thread images: 31


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.