[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y ] [Home]
4chanarchives logo
/dpt/ - Daily Programming Thread
Images are sometimes not shown due to bandwidth/network limitations. Refreshing the page usually helps.

You are currently reading a thread in /g/ - Technology

Thread replies: 255
Thread images: 24
File: kA3SmWq.jpg (190 KB, 1268x1695) Image search: [Google]
kA3SmWq.jpg
190 KB, 1268x1695
Harold edition
>>
Old: >>52992368
>>
>>52997687
2nd for functional programming is a meme
>>
python is pretty cool guies
>>
I am going to redpill you about the GPL.

Some cucks (among many we have) are trying to promote BSD, MIT, Apache and other licenses because they are hired by corporations that can make privative software thanks to those licenses by putting some closed source on top and fuck everyone else.

For example, Darwin is an operative system in which Apple collaborates with the "open source" community. Because it is a BSD derivative, Apple uses that operative system and put it some closed source bits and call it OS X.

Sure, you can use Darwin, but is crippleware, is of much lesser quality. And Apple is not even full fascist here, they at least have some degree of cooperation. Microsoft on the other hand in the 90's spread memos about how to fuck up Linux and the free as in freedom community. Is called "embrace, extend, extinguish". See for yourself: https://en.wikipedia.org/wiki/Embrace,_extend_and_extinguish https://en.wikipedia.org/wiki/Halloween_documents

If you were in charge of Microsoft, and you had no ethics, what would you do knowing that you could harm the free software community just by reusing "open source" software in your favor, put some bells and whistles, and extinguishing the original product?

I beg you consider the GPL and LGPL over everything else. One can't possibly know what is being used under the hood of many privative software, and you never know when something "open sourced" sometime ago is now part of closed source software.

Even the LGPL, because you can have a fully functional application in LGPL which someone can cut off the interface, put a privative interface to it and deprecate any other interface by changing the API (systemd?).
>>
>>52997753
>python
>being a faggot
>>
File: 1366072880628.jpg (90 KB, 500x540) Image search: [Google]
1366072880628.jpg
90 KB, 500x540
>Get halfway into a pet project
>Lose all motivation
>Can't even bother to make more than one or three line changes every attempt I make
why must this always happen
>>
>>52997836
because you're an anime loving fagwad
>>
Many computer users run a modified version of the GNU system every day, without realizing it. Through a peculiar turn of events, the version of GNU which is widely used today is often called “Linux”, and many of its users are not aware that it is basically the GNU system, developed by the GNU Project.

There really is a Linux, and these people are using it, but it is just a part of the system they use. Linux is the kernel: the program in the system that allocates the machine's resources to the other programs that you run. The kernel is an essential part of an operating system, but useless by itself; it can only function in the context of a complete operating system. Linux is normally used in combination with the GNU operating system: the whole system is basically GNU with Linux added, or GNU/Linux. All the so-called “Linux” distributions are really distributions of GNU/Linux.

Many users do not understand the difference between the kernel, which is Linux, and the whole system, which they also call “Linux”. The ambiguous use of the name doesn't help people understand. These users often think that Linus Torvalds developed the whole operating system in 1991, with a bit of help.

Programmers generally know that Linux is a kernel. But since they have generally heard the whole system called “Linux” as well, they often envisage a history that would justify naming the whole system after the kernel. For example, many believe that once Linus Torvalds finished writing Linux, the kernel, its users looked around for other free software to go with it, and found that (for no particular reason) most everything necessary to make a Unix-like system was already available.
>>
>>52997836
Why do you always rely on fucking motivation is beyond me.
Discipline is the one true art of mastering things.
>>
>>52997874
cool writeup actually, thanks
is Hurd an attempt to make a complete OS with non-Linux kernel?
>>
>>52997967
I’d just like to interject for a moment. What you’re refering to as Windows, is in fact, NSA/Windows, or as I’ve recently taken to calling it, NSA plus Windows. Windows is not an operating system unto itself, but rather another locked down component of a fully functioning NSA system made useful by the NSA corelibs, shell utilities and vital system components comprising a full OS as defined by the government.
Many computer users run a modified version of the NSA system every day, without realizing it. Through a peculiar turn of events, the version of NSA which is widely used today is often called “Windows”, and many of its users are not aware that it is basically the NSA system, developed by the NSA.
There really is a Windows, and these people are using it, but it is just a part of the system they use. Windows is the kernel: the program in the system that allocates the machine’s resources to the other programs that you run. The kernel is an essential part of an operating system, but useless by itself; it can only function in the context of a complete operating system. Windows is normally used in combination with the NSA operating system: the whole system is basically NSA with Windows added, or NSA/Windows. All the so-called “Windows” versions are really versions of NSA/Windows.
>>
>>52997986
It's really hard to figure out problems and code if you're not motivated.
>>
>>52997987
That's an ancient /g/ copypasta, anon. You're not supposed to take it seriously.

And as for your question, Hurd predates Linux by quite a bit.
>>
>>52998008
What?
You really need to learn to figure things out even though you don't "want" them. Its not that you should sustain an 8 hour coding spree, but change something every day.
If its not code, write some documentation, or refactor variable names.

Even if its only three lines you just have to push yourself to start it.
>>
File: 1960s american highschoolers.webm (2 MB, 640x316) Image search: [Google]
1960s american highschoolers.webm
2 MB, 640x316
Got a weird bug, which I'm pretty sure is a logic error on my part Language is Swift.

When I run this code in a Cocoa interface, it saves the value as a string and makes it the placeholder text instead of writing the value. The weird part is when I open the window back up, that value is the placeholder text, and when I submit it, it takes the value, just like I want it to do the first time around.

Effectively it causes a user interface bug where the user would have to save the api key, close the window, open it again, and click save again. Kinda weird.

field is too long, so posting in the next post
>>
Daily reminder
GPL is communism
GPL is a pyramid scheme
GPL is illegal
>>
>>52998018
well I started coming here daily just recently
>>
can /dpt/ implement foldr in C#?
>>
>>52998124
I am going to redpill you about the GPL.

Some cucks (among many we have) are trying to promote BSD, MIT, Apache and other licenses because they are hired by corporations that can make privative software thanks to those licenses by putting some closed source on top and fuck everyone else.

For example, Darwin is an operative system in which Apple collaborates with the "open source" community. Because it is a BSD derivative, Apple uses that operative system and put it some closed source bits and call it OS X.

Sure, you can use Darwin, but is crippleware, is of much lesser quality. And Apple is not even full fascist here, they at least have some degree of cooperation. Microsoft on the other hand in the 90's spread memos about how to fuck up Linux and the free as in freedom community. Is called "embrace, extend, extinguish". See for yourself: https://en.wikipedia.org/wiki/Embrace,_extend_and_extinguish https://en.wikipedia.org/wiki/Halloween_documents

If you were in charge of Microsoft, and you had no ethics, what would you do knowing that you could harm the free software community just by reusing "open source" software in your favor, put some bells and whistles, and extinguishing the original product?

I beg you consider the GPL and LGPL over everything else. One can't possibly know what is being used under the hood of many privative software, and you never know when something "open sourced" sometime ago is now part of closed source software.

Even the LGPL, because you can have a fully functional application in LGPL which someone can cut off the interface, put a privative interface to it and deprecate any other interface by changing the API (systemd?).
>>
>>52998138

It's literally impossible.
>>
File: 1431869353976.gif (2 MB, 240x180) Image search: [Google]
1431869353976.gif
2 MB, 240x180
>novice programmer looking for projects to do
>everything is either retard tier or out of my league
>all of it is uninteresting
>>
>>52998138

what is foldr and why is it useful
>>
>>52998164
make fappy bird
>>
>>52998138
uh
hm
All right I'll give it a shot.


int avg(int a, int b) {
return (int)(((long)a + (long)b) / 2);
}


H-How did I do, anon?
>>
What GitHub alternative do you use, /dpt/?
>>
>>52998164
prime fizzbuzz

prime and multiple of 15 -> "Fizzbuzz"
prime and multiple of 5, not 3 -> "Buzz"
prime and multiple of 3, not 5 -> "Fizz"
otherwise -> number
>>
>>52998164

JUST DO IT
>>
>>52998124
MIT/BSD/X11 is the superior choice in my opinion, anon, but please, stop shitposting.
>>
>>52998164
same
it's shit
>>
File: eggplant emoji.jpg (66 KB, 700x700) Image search: [Google]
eggplant emoji.jpg
66 KB, 700x700
>>52998091
import Cocoa

class SavePreferences: NSViewController {
// message that says "Api Key saved" default state hidden, just a text string
@IBOutlet weak var apiKeySavedText: NSTextField!

//NSUserDefauts is the preference storage mechanism
let defaults = NSUserDefaults.standardUserDefaults()

var apiKeyTitle = NSUserDefaults.standardUserDefaults().objectForKey("userApiKey")

//MARK textfield for api key, a simple text box
@IBOutlet weak var textFieldApiKey: NSTextField!

//MARK when this button is pressed, save API Key as default preference
@IBAction func btnSaveApiKey(sender: AnyObject) {
self.defaults.setObject(self.textFieldApiKey.stringValue, forKey: "userApiKey")

//synchronize() is the method that is supposed to write the values to NSUserDefaults
self.defaults.synchronize()

//console debugging
print("apikey saved as", self.apiKeyTitle)

//show the "API Key Saved" message text string
apiKeySavedText.hidden = false
}

//initialize the state of the window on load
override func viewDidLoad() {
super.viewDidLoad()

//initial state of saved api key message
apiKeySavedText.hidden = true

// if the userApiKey value in NSUserDefaults is not blank, set the placeholder text to the value of the userApiKey
if(self.defaults.valueForKey("userApiKey") != nil) {
textFieldApiKey.placeholderString = self.defaults.valueForKey("userApiKey") as? String

}
}
}
>>
>>52997986
This. Motivation comes and goes and you shouldn't rely on it.
>>
>>52998199
DO ITTTTT
>>
>>52998183
gitlab for school and bs, bitbucket for portfolio and employers
>>
GPL is literally a trojan virus
>>
>>52998183

my hard drive you fucking faggot
>>
>>52998164
Write a game of billards in your language of choice.
Not overly complex, not overly simple.

>b-b-but I don't wanna!
Then fuck off and find your own project that actually interests you.
>>
>>52998257
it's spelled pool
>>
>>52997986
discipline and mental fortitude is good to have but motivation and passion is what really makes you do great things.
>>
File: programming utilities.jpg (26 KB, 724x724) Image search: [Google]
programming utilities.jpg
26 KB, 724x724
>>52998278
discipline, mental fortitude, motivation and passion are great and all

but what if you could have all of them at once
>>
"don't need motivation, just discipline" is a >>>/vg/agdg meme and look at how not good they're doing
>>
>>52998278
>motivation
>passion
sure is SJW in here. Go commit some CoC's on github projects you don't even understand
>>
>>52998327
sure is underage in here
>>
>>52998278
You can't stay motivated all the way through. Consistency is much better in long term rhan short outbursts even of the most sincere and beautiful passion. At some point you'll find a point where you're just not interesred, and you'll have to push yourself to get into the "zone" again.
>>
>>52998322
Daily reminder that if you're loyal to the cause, you'll shitpost in /vg/agdg/
>>
>>52998327
hurt feefees detected
>>
>>52998275
ooh look an exercise in semantics, oh wait that's bikeshedding
>>
>>52998187
piss easy
#include <stdio.h>

int isPrime(int x) {
for(int i = 2; i < x / 2; ++i) {
if(!(x % i)) return 0;
}
return 1;
}

void primeBuzz(int x) {
for(int i = 0; i < x; ++i) {
if(isPrime(i)) {
!(i % 15) ? printf("Fizzbuzz") :
!(i % 5) ? printf("Buzz") :
!(i % 3) ? printf("Fizz") :
printf("%i", i);
} else {
printf("%i", i);
}
}
}

int main() {
primeBuzz(101);
return 0;
}
>>
>>52998377
bahaha you retard
>>
I've been looking for an easy way to expose web services hosted on my home computer to the internet because I don't want to fuck around with NATs, firewalls, DNS, domains, or any other bullshit like that and I found ngrok. It's a tool you run from command line that forwards traffic from a web address (http://xxxxxxxx dot ngrok dot io) to local host on a specified port.

Just set up my first server using node.js in like five minutes. Feels good. I'm POSTing shit from a javascript app on my tablet and writing that shit to a file on my desktop.

Next step I'm gonna write the server in C because node.js isn't cool.
>>
>>52998322
Never been there. My conviction comes from, of all places, DJT. You either do your reps and study daily or you whine on 4chan about losing motivation.
>>
What's the simplest way to build a web application using C#? I know almost nothing about web development.

Ideally I'd be able to use something similar to the WPF framework when it comes to design, writing some XAML with a view to guide you makes life lot easier, and data binding makes the whole process a breeze.

But as I said, don't know the first thing about web development.
>>
File: Right-fold-transformation.png (10 KB, 320x158) Image search: [Google]
Right-fold-transformation.png
10 KB, 320x158
>>52998170
foldr applies an aggregation function to a list. For example, in pseudo code:
foldr(function, list, initial) { 
agg = initial;
for i in list:
agg = add(agg, i);
return agg;
}
foldr(add, [1,2,3,4] 0) = 10
foldr(add, [1,2,3,4] 1) = 1

It is important because it demonstrates a language ability to turn a list structure into a function structure.
>>
>>52998417
>What's the simplest way to build a web application using C#? I know almost nothing about web development.

Open up VS and start a new ASP.NET application.

Boom, VS gives you an example web app that's feature-devoid but fully functional and loads right up when you hit start.
>>
>>52998410
>DJT
Designated Jizz Towel?
>>
>>52998417
ASP.NET uses a similar MVVM system that WPF does, but you're obviously not going to be writing webpages in XAML.
C# is pretty much a backend-only language for the web, so you'll need something in front for buttons and shit.
>>
>>52998425
foldl is objectively better than foldr

can't easily foldr a lazy list
>>
>>52998425
>explaining foldr with imperative programming
no
>>
>>52998455
*any lazy list
(that includes infinite lists)
>>
>>52998455
memel is objectively better than memer

can't easily memer any memey meme
>>
>>52998465
Have you heard of the IPL language?
>>
>>52998486
You must be 18 years of age or older to use this website
>>
>>52998455
it's the other way m8
also foldl sucks, use foldl'
>>
>>52998486
meme is memely memer than memey

can't meme memer memey memest memes
>>
>>52998377
Oh come on. I thought no one will fall for that joke. Look at the output and come back to us.

Python one liner
print("\n".join("Fizz" if x==3 else "Buzz" if x==5 else str(x) for x in range(100)))
>>
>>52998487
have you heard of the clean programming language
>>
>>52998512
I'm a code monkey, I do what I'm told, not what I believe.
>>
>>52998502
Foldr over an infinite list:
f(list[infinity], f(list[infinity-1], f(...

Foldl over an infinite list:
f(list[0], f(list[1], f(...
>>
>>52998451
>>52998434
I have absolutely no idea what all these different templates are.

I just want to be able to build a simple page that displays information using a WPF Bindings style system.
>>
>>52998527
Have you heard of Common Lisp?
>>
>>52998486
>>52998511
>people once shunned the usage of that word
>this is now the normal discussion on /g/
Oh, how mighty have fallen.
>>
>>52998545
You're why our jobs get outsourced to pajeet in India.
>>
>>52998425

I don't get it.

Why would you apply a function to a list and not just feed the function a list of inputs.
>>
>>52998567
you mean the emacs scripting language?
>>
>>52998561
Just fucking google it.
>>
>>52998593
Emacs uses Elisp, not Clisp.
>>
>>52998583
foldr(+,[1,2,3]) would return the sum of [1,2,3], 6.
Thats an example where its useful
>>
>>52998583

Sum of elements in a list:
fold (+) 0

Product of elements in a list:
fold (*) 1

(a && b && c && d ...) over a list:
fold (&&) true

(a || b || c ...) over a list:
fold (||) false

Concatenate list of strings into one string:
fold (concat) ""
>>
Why can't I find an entry level job? I have 3 decently sized projects on GitHub all in different languages, I have a BS in CS, and an AA degree and I got good grades. I got my BCS degree two years out of high school because of a college enrollment program. I worked throughout college, though in McDonald's. I applied to internships in college, but one, I was rejected because they didn't consider me a senior in college, and another, I'm not sure why I wasn't hired. I applied to many entry level positions but got only one call/onsite interview but nothing came of that. What do you recommend I do? I'm kind of frustrated with this shit.
>>
>>52998583

never mind I read the code and I understand now. Still not sure why it is called foldr. That's just function that calls another function multiple times.

I hate when functional fags make stuff sound more complicated than it actually is
>>
>>52998648
U probally not white
>>
File: 24231.jpg (54 KB, 500x500) Image search: [Google]
24231.jpg
54 KB, 500x500
>>52998648
>he fell for the STEM meme
>>
>>52998648

where do you live
>>
>>52998648
You forgot to be good looking and charismatic
>>
>>52998583
because memes
>>
class maybe:
def __bool__(self):
from random import randint
return randint(1, 2) == 1
Maybe = maybe()

for _ in range(100):
print(bool(Maybe))
>>
>>52998553
http://stackoverflow.com/questions/3082324/foldl-versus-foldr-behavior-with-infinite-lists#3085516

it also becomes obvious from that picture posted: for example consider f = const. no need to evaluate the rest of the fold
>>
>>52998704
>>52998628
>>
How does functional programming compare to OOP?
I hear that Java is one of the most used languages, does that also mean that it's one of the best?
>>
>>52998723
>How does functional programming compare to OOP?

Immensely.

>I hear that Java is one of the most used languages, does that also mean that it's one of the best?

By definition, yes.
>>
>>52998722
and how often do you need to use those meme operations?
>>
File: haskell.png (12 KB, 225x321) Image search: [Google]
haskell.png
12 KB, 225x321
>>52998723
functional programming is a fringe meme. it's useless

java is indeed one of the best if not THE best language regardless of what some of these epic memers will tell you
>>
>>52998717
s state = init;
for (size_t i = 0; i < v.length(); i++)
state = func(state, v[i]);
return state;


>backwards
>stack overflow
>>
>>52998723
>How does functional programming compare to OOP?
It doesn't.
OOP is basically the opposite of FP.
In OOP everything is structured, static, mutable, and copyable.
In FP everything is fluid, dynamic, immutable, and concise.
>>
>>52998748
Do you even program?
>>
>>52998342
>>52998353
STFU cancerous faggots
>>52998327
stay ever vigil, brother
cancer is spreading
>>
>>52998800
where the fuck do you keep getting all these lists from that you have to sum or multiply or whatever

and how is this a common enough occurrence that you need to have it built into your language instead of just iterating through the list like a normal person
>>
>>52998798
>fluid
>copyable
wat

>OOP everything is ... static
>FP everything is ... dynamic
I hope you don't mean the typing.
>>
>>52998798
>static, mutable
>dynamic, immutable
huh?
>>
>>52998779
(by use on infinite data structures I mean you can fold the first N elements - you can't fold the last N elements of an infinite data structure)
>>
>>52998410
>>52998440
Dow Jones Transportation Average?
>>
>>52998661
> Still not sure why it is called foldr.
The generic term for the operation is "folding" or "a fold" (sometimes the terms reduce or accumulate are used).

The "r" is because it's right-associative, i.e.
> foldr (+) 0 [1,2,3,4]
evaluates as
> 1+(2+(3+(4+0)))
whereas
> foldl (+) 0 [1,2,3,4]
would evaluate as
> (((0+1)+2)+3)+4

If the operation isn't commutative, the distinction affects the result. If the arguments have different types, it affects whether the expression is even valid.

Also, if the function is a type constructor, foldr can be applied to an infinite list to yield an infinite list (or other structure) which will be generated lazily.
>>
>>52998800

cool double dubs.

I'm not the anon you just responded to but I have a question.

I can see how functional programming would be very useful when dealing with processing large amounts of data, but that isn't what my normal programming usually entails. I do embedded systems programming where pretty much all of my code is either having an affect on the real world, doing some IO, changing some state, or quickly deciding whether to do any of these things. Do you know of any resources that could explain how functional programming could fit into this scenario? Or does it not really?
>>
>>52998568
where to now?
>>
>>52998779
nice Haskell you've got there
https://wiki.haskell.org/Foldr_Foldl_Foldl'
in Haskell foldr can work with infinite list if you chose your f correctly while foldl can never work with infinite lists.
>>
>>52998571
chances are, you ARE talking to a pajeet
>>
>>52998894
it's useless for everything besides perhaps computational programs that are essentially just glorified math expressions
>>
>>52998894
The main advantage is reducing the code you need to write. Ignore all the FP people who talk about immutability - that's a separate argument entirely.

Key points of FP:
First class functions
Higher order functions (functions operating on functions)
Function operators (composition, currying, etc)
Algebraic data types and a strong type system
>>
>>52998828
No no no, not the typing.
>>
>>52998913
>Haskell
I don't care about Haskell

and my point is you can do a foldl of N elements, like taking from an infinite list

How can you foldr an infinite list? You start with the infinite-th item
>>
>>52998942
>The main advantage is reducing the code you need to write
less code != better. short stories != better than novels
>>
>>52998672
nah, just a whiny bitch
>>
>>52998821
> and how is this a common enough occurrence that you need to have it built into your language instead of just iterating through the list like a normal person
It isn't built into the language, it's a library function.

It's trivial enough to write it yourself, but given that most iteration is either a map or a fold, it makes more sense to just use an existing function rather than explicit recursion.

Similarly, generalised iteration is a library function, rather than a language construct:
iterate :: (a -> a) -> a -> [a]
iterate f x = x : iterate f (f x)
>>
>>52998955
so memes
>>
>>52998863
I suggest you venture to the land of /a/ for the source of this mysterious word.
>>
>>52998962
see
>>52998887
>>
>>52998595
Anyone know of any way to style an ASP.NET form? I'm creatively bereft and have no ability or interest in making a web page look good.

I did a cursory Google and didn't find shit, so I assume there either is a specific thing I'm looking for, or nothing exists.
>>
>>52998987
you still haven't explained why you would commonly encounter situations where you have to use foldl/foldr
>>
>>52998942
>Key points of FP:
it's not quite clear how these points translate into advantages in the real world - for one, "reducing the code you need to write", which would be a win for sure
>>
>>52998987
>most iteration is either a map or a fold
no fucking way what kind of software are you even writing you fucking retard

are you still stuck on one of babby's first programs, summing a list of ints?
>>
What's the best way to add unit testing to legacy code? I've got this bit project with lots of classes and barely any idea of what does what.
>>
>currying
It's shit
int add1(int a) { return a + 1; }
int add(int a, int b) { return a + b; }

Here! "Currying" in a normal language.
>>
>>52999069
How are you THIS retarded.
>>
>>52999069
FP in general is shit

no one has ever demonstrated any advantage in using functional programming over imperative programming
>>
>>52999096
it's useful in parallel programming, since it's easier to guarantee thread safety when everything is functional
>>
>>52998661
>I hate when functional fags make stuff sound more complicated than it actually is
You can't write papers about simple things, so they invent nonsense like zygohistomorphic prepromorphisms because it makes them sound smart.

It's like when people sound "clever" for saying "x = x + 1" doesn't make sense.

Here, "x" is something like "the temperature."
The temperature is 90 degrees.
The temperature is rising.

Is being able to refer to the temperature as a concept separate from its current value meaningless? Of course not.

The key is understanding that both uses of "temperature" and both uses of "x" are different.
>>
>>52998962
> How can you foldr an infinite list? You start with the infinite-th item
A right fold starts with the first item, with the recursive case on the right.

Note that for an infinite list, the base case never gets invoked.

Given:
 foldr :: (a -> b -> b) -> b -> [a] -> b
foldr f z [] = z
foldr f z (x:xs) = f x (foldr f z xs)


Consider
foldr f undefined [1,2,3,4,....]
= f 1 (foldr f undefined [2,3,4,...])
= f 1 (f 2 (foldr f undefined [3,4,...]))
= f 1 (f 2 (f 3 (foldr f undefined [4,...])))
...


In order for this to be of any use, the function needs to be non-strict in its second argument (which is true for any type constructor unless it has a strictness annotation, but not for e.g. primitive arithmetic operators).
>>
>>52999113
>everything is functional
no such thing
>>
>>52999113
>what is a mutex
k tard
>>
>>52999069
>>52999084
I meant to say
int add1(int a) { return add(a, 1); }
but whatever, you get my point.
>>
>>52999136
That's also wrong. Currying uses the arguments in hand, not recursively calling the same thing.
>>
>>52999133
A pain, message passing is better.
>>
>>52999122
please kill yourself
>>
>>52999096
> no one has ever demonstrated any advantage in using functional programming over imperative programming
You mean other than letting you just tell the computer what to do rather than having to spell it out in minute detail in a language that's one notch above assembly?

If you think that imperative programming is actually easier, then you've been mentally crippled beyond hope and should probably just top yourself.
>>
>>52998942
>>52999049
I'd say that reduction (or elimination) of mutable state actually is one of the key points to functional programming, because without that, why would people bother with the overhead in memory usage and all those "weird" (to non-fp programmers at least) idioms in the first place?
>>
>>52999039
Algebraic data types:
// | is "or"
// * is "and"
type Message =
| msg1 of (int * int) // a pair of ints
| msg2 of (string * int) // an int and a string
| msg3 // a single value
| msg4 of char


This is equivalent to:

struct msg1 { int first, second; };
struct msg2 { string first; int second; };
struct msg3 {};
typedef char msg4;

struct Message
{
union {
msg1 m1;
msg2 m2;
msg3 m3;
msg4 m4;
};
enum { emsg1, emsg2, emsg3, emsg4 } tag;
}
// and constructors for each union case



>>52999001
Explain
>>
File: fuck.jpg (16 KB, 293x253) Image search: [Google]
fuck.jpg
16 KB, 293x253
What question would you ask someone to test if they are actually a programmer or not?
>>
>>52999184
write a function in C that swaps the values of two integer parameters
>>
>>52999177
whoops, that second citation was wrong, I meant >>52999039
>>
>>52999184
are you actually a programmer or not?
>>
>>52999177
you can reduce/eliminate mutable state in imperative programming just fine. just that people don't like to use const correctness and do needless copying
>>
>>52999156
It's not recursive, read again, add1 calls add with two arguments.
>>
>>52999202
and the solution
>>
>>52999180
>Algebraic data types:
aka tagged unions, they are not a property of FP.
>>
>>52999113
This claim was proven wrong more than 30 years ago.

All of the fastest parallel systems, like those massive supercomputers and distributed computing projects, use imperative languages.

You can also use the "no side effects" style of programming in any imperative language. Some imperative languages like PL/I, Fortran, and Ada have attributes for saying a function/procedure has no side effects.

The hard part is getting information to and from different local memories (computers, address spaces, caches), which imperative programming is better at doing.
>>
>>52999122
this guy does it better >>52999180
>>
>>52999170
>just tell the computer
bwahahahahaha, fpcucks actually believe the cpu is not imperative; they "tell" the computer to curry that shit! hey, x86, just foldr this for me, don't bother looping! yeah, use the foldr instruction!
wake up you fucking asswipes
>>
>>52999184
average 2 ints in c
>>
>>52999228
if we're comparing languages on LOC:
a, b = b, a
>>
asked this in /sqt/ and /wdg/, but I think this thread might be able to help me out more...

can anyone help me fix my script? Im trying to create and integer_to_word script, but when I give the script 100,000 it returns One-Hundred as opposed to One-Hundred-Thousand. Code here: http://pastebin.com/HaMGgM2f
>>
>>52999278
this. clueless spergs will fuck off by allowing overflow or returning a fucking float or rounding away from zero or whatever hilarious shit they come up with
>>
>>52999180
>>52999232
The syntax for the second example comes from FP.

Pattern matching:

sequel
string messageToString(Message m)
{
switch (m.tag)
{
case emsg1: return tostring(m.m1.first) + "," + tostring(m.m1.second);
case emsg2: return m.m2.first + ": " + tostring(m.m2.second);
case emsg3: return "exit";
case emsg4: return "[" + tostring(m.m4) + "]";
}


string messageToString msg = 
match msg with
| msg1 first second -> tostring(first) + "," + tostring(second)
| msg2 s i -> s + ": " + tostring(i);
| msg3 -> "exit"
| msg4 c -> "[" + tostring(c) + "]"
// an ADT implicitly provides "reverse constructor" patterns
// expression based - imagine if C was written entirely using commas rather than semicolons
>>
>>52999288
you can do it in one line in almost any language
>>
>>52999320
>fuck off
*fuck up

>>52999325
not in any good language
>>
>>52999323
first example*

(also there's a missing }, and the FP examples could use semicolons and braces instead of indentation, or just keywords, depending on the language)
>>
>>52997764
>BSD, MIT, * are cuck licenses

GPL is the biggest cuckery of all.

>Y-you can jizz in my wife as long as you attach this license and make sure other people can freely jizz in her, too!

Get out
>>
>>52999339
>can't swap 2 values in one line
>a good language
pick one
>>
>>52999351
>says that interracial cuckold
>>
>>52999351
>GPL is the biggest cuckery of all.
Your defense on BSD is the biggest cuckery of all.
>>
>>52999363
kill yourself pythonbabby

less code != better
>>
>>52999376
well, he got cucked Tim Cuck himself, so...
>>
>>52999376

BSD is liberty. GPL is communism.

>>52999373
>cuckold

Absolutely not. I may love darkies, but I will never be involved in any sort of cuckoldry.. ever.
>>
>>52999385
>programs in shit language
>popping a vein about it
you do know you can change that at any time, right, webshit?
>>
>>52997986
You need motivation to start disciplining yourself, no? This is the problem I'm having.
>>
>>52999413
projecting
>>
>>52999400
>BSD is liberty. GPL is communism.
BSD is cuckery, GPL is fair trade. Stop sponsor monopoly.
>>
>cucks discussing cuck licenses
>no clue about superior eula that lets you be boss and fuck anyone in the ass
that's why you're cucks and will always be
>>
>>52999202
How'd I do?
// write a function in C that swaps the values of two integer parameters
void swap( int *i, int *x ){

int holder = *i;
*i = *x;
*x = holder;

};
>>
>>52999441
>fair trade

Just like Stalin's purges were "fair trade"
>>
>>52999430
>rekt hard
>maximum damage control
m8, you're embarrassing yourself too much
>>
>>52999441
>GPL is fair trade
top fucking kek commie
>>
>>52999458
those are not integer parameters
>>
#define swap(a,b) b, a
>>
>>52999463
>>52999472
Your fallacy is not going to prove you right. Your idiocy already proved your lack of arguments.

Stop promoting communism by accusing of communism. Monopoly is guaranteed by anything less than GPL.
>>
>>52999472

I love commies pretend that everything they're doing is "for the proletariat" and that their subjects are in total agreement with them because:

1. The only people left are those who agree with the plan, those who opposed communist takeover have been slaughtered

2. The only reason the remaining people are working together is because they'd rather be pushing bodies into ditches than be the bodies IN the ditches.
>>
>>52999502
/thread
>>
>>52998187
That is some top quality bait, and actually quite a good interview question.

If they take more than 30 seconds to question the task, the interview is over.
>>
>>52999518
>Monopoly is guaranteed by anything less than GPL.

Natural monopolies are fine.
>>
>>52999528
>bait
can you do it, fgt?
>>
>>52999502
struct {int a, b;} swap(int a, int b){return (struct {int a, b;}){b, a};}[/code]
>>
>>52999518
>GPL is fair trade
Fair trade means people are paid
>>
>>52999565
doesn't compile
>>
>>52999311
On line 14, you either need to create a new array for hundred-thousands, or you need to append

+ '-Thousand' +


after the "hundreds" array
>>
>>52999577
yes, it does
>>
>>52999543
>Natural monopolies are fine.
Who is this cuck again? And why is he defending big corporations over entrepreneurs?
>>
>>52999566
exactly
>>
>>52999468
kill yourself you aren't convincing anyone that python isn't absolutely disgusting
>>
>>52999556
You literally just print every integer from 1 to the given value.

Bad news buddy, you didn't get the job.
>>
>>52999595
GPL means it's free
>>
>>52999603
fizz on 3 and buzz on 5 you retard
>>
>>52999320
Is this sperg tier?
// average of 2 ints
double avg( int i, int x ){

return (double)(i+x) / 2;
};
>>
>>52999603
I'm sorry, pajeet, you forgot to print Fizz and Buzz for 3 and 5.
>>
>>52999594
>big corporations

The next time you come up with a novel software technique, you have an inherently monopoly on it unless you intend to publish it for free.

I'm sure there are plenty of things you've failed to publish.

I can't wait for Bernie Sanders to put you in jail when you refuse to have your thought-publisher installed.
>>
>>52999589
But that'd break it for numbers over 100000
>>
File: dpt fails again.png (37 KB, 743x610) Image search: [Google]
dpt fails again.png
37 KB, 743x610
>>52999603
Bad news buddy

1
2
3 -> Fizz
4
5 -> Buzz
6
..
100

You didn't get the job
>>
>>52999622
yes you're obviously supposed to return an int
>>
>>52999615
of course, it's free software
>>
>>52999646
which means nobody gets paid for it
it isn't fair trade
>>
>>52999633
Why are fucking arguing against GPL and in favor of BSD then? Are you stupid?
>>
>>52999667
i'm not even a freetard but it's free as in """"""""freedom"""""""" not free as in beer
>>
>>52999682

I'm being ironic. I hope Bernie Sanders doesn't become president. I wouldn't even wish him on Somalia.
>>
>>52999667
who's not paid? redhat employees? are you dumb or what? of course they get paid to write gpl software
>>
>>52999641
So like this?
// average of 2 ints
int avg( int i, int x ){

return (i+x) / 2;
};
>>
>>52999694
FAIR trade is not FREE
>b-but it's not fair that it's not free!
fucking millenial scum
>>
>>52999700
Does not return the correct value for all values of i and x and might cause undefined behaviour in some cases.
>>
>>52999695
if it came down to trump vs sanders who would you vote for
>>
>>52999700
Overflow error, anon.
Next.
>>
>>52999626
>>52999617
Realistically, what would be worse: failing to print fizz on 3 and buzz on 5, or actually writing the mod 3 and 5 checkers without realising there are only 2 numbers that wont be printed in decimal?

If you got asked this sort of thing they're just making sure you don't waste time on the general case for something that should be hard coded.
>>
>>52999699
not through the product
>>
>>52999720

Neither. I'd go innawoods to prepare for the 2nd American Revolution.
>>
>>52999603
>literally just print every integer from 1 to the given value
>literally
>LITERALLY
FAGGOT GOT #REKT HARD
>>52999603
>>52999626
>>52999637
>>
>>52999278
Has anyone posted this on stackoverflow?
>>
>>52999730
it's pretty bad that you fail to print fizz and buzz because you should think it through before you start writing code
>>
>>52999730
>I got my ass handed to me but let's see if I can backpedal out of this rektfest
just fucking end yourself already, you're done
>>
>>52999695
Changing the subject only shows you lack competence. Just call it a day and think how much wrong you were.
>>52999704
>FAIR trade is not FREE
Getting paid for software, getting paid to provide software and service for the software, etc etc etc
>>
>>52999730

One way passes the test and provides re-usable code

One doesn't
>>
>>52999732
>not through the product
what does that mean?
the claim was
>nobody gets paid for it
that's provably wrong; redhat employees ARE PAID FOR IT
>>
>>52999746
Yeah it's been done to death there.

The 'common solution' /g/ trumps is actually FROM there.

int avg(int a, int b) {
return (a / 2 + b / 2 + (a % 2 + b % 2) / 2);
}
>>
File: 1454278106082.jpg (36 KB, 400x460) Image search: [Google]
1454278106082.jpg
36 KB, 400x460
>>52998187
kek
>>
>>52999784
it's not correct for all values of a and b. you have to do something like

int avg(int a, int b)
{
if(a > 0 != b > 0) {
return (a + b) / 2;
}
return a / 2 + b / 2 + (a % 2 + b % 2) / 2;
}
>>
Does anyone have that list of programming tasks for beginners? It was quite long and the projects gradually escalated from simple to difficult. I saw it floating around awhile ago.
>>
>>52999641
>obviously supposed to return an int
>50% of use cases, int cannot store required accuracy.

Sure thing m8. Without first defining which rounding method you want to use, the question should only ever be interpreted to mean return a FP type.
Returning the average of 2 ints as an int, without further details about what to do with odd sums, is meaningless.
>>
>>52999784

let average a b = <@ (a + b) / 2 @>
>>
>>52999784
Do you happen to have the SO page?
>>
>>52999813
ask me how I know you don't have a clue about programming
>>
>>52999813
>FP type
No, FP types are not accurate. A rational type maybe.
>>
>>52999813
>What question would you ask someone to test if they are actually a programmer or not?
>>
File: 1445292024436.png (378 KB, 1450x1080) Image search: [Google]
1445292024436.png
378 KB, 1450x1080
>>52999812
Here is one version...
>>
>>52999815
fail
>>
File: fucking-image.png (302 KB, 1920x1080) Image search: [Google]
fucking-image.png
302 KB, 1920x1080
>>52999812
>>
>>52999757
>Changing the subject only shows you lack competence

I didn't change the subject. I was using some literary devices to illustrate what a complete moron you are.

I bet you're voting for Bernie Sanders you commie fuckstain.
>>
>>52999832
The same way you just know that your religion is the right one?

Badly specified modules are worse than poorly implemented ones.
>>
>>52999815
kill yourself
>>
>>52999863
how
>>
>>52999874
if someone casually asks you to average two ints in C you should be able to infer the specs if you are even a half-decent programmer

FUCKING SPERG I HATE YOUR GUTS FUCKING DIE
>>
File: 06f.jpg (30 KB, 494x584) Image search: [Google]
06f.jpg
30 KB, 494x584
>>52999865
>I didn't change the subject
>I bet you're voting for Bernie Sanders you commie fuckstain
>>
>>52999874
>The same way you just know
hahahaha, this cuck got called and now's backpedaling
>>
>>52998187
I can't remember anything post elementary school arithmetic, but wouldn't be it a prime if It can be divided by 3 and 5, right?

>inb4 that's the joke
sorry, english is not my first language.
>>
>>52999763
>>52999756
>>52999752
If you spend more than 30 seconds writing a for loop with exceptions for 3 and 5, you still fail.

Missing 3 and 5 is a bad slip, but at least it's not full-blown Prajeet mode.
>>
>>52999922
3 and 5 are primes and they are still multiples of 3 and 5

every prime is divisible by itself and 1
>>
File: oij.png (474 KB, 1500x2050) Image search: [Google]
oij.png
474 KB, 1500x2050
How do I learn JavaScript senpai?
>>
>>52999922
A prime only has 2 factors - 1 and itself
So if it can be divided by 3 and 5, it is not a prime

The only prime divisible by 5 is 5
The only prime divisible by 3 is 3
>>
>>52999938
>Missing 3 and 5 is a bad slip
>slip
nah, this is pajeet tier incompetence
>>
>>52999938
keep telling yourself that
>>
>>52999938
>fail
>succeed

>failing is better
>>
File: Untitled25098.png (54 KB, 1920x1030) Image search: [Google]
Untitled25098.png
54 KB, 1920x1030
After a weekend with the gf I started working on this again.
I just finished some testing with RADIUS and Samba from LDAP, two functions I also want to build into the interface.
I want to build the entry forms as soon as possible.
Shame I don't have a lot of free time and I have to do it all on my own.
>>
>>52999903

Just admit that it's true.
>>
>>52999942
npm install gentoo
>>
>>52999860
>>52999864

Okay guys thanks, this should keep me busy
>>
>>52999877
>>52999863

seriously what the fuck is wrong
>>
>>52999938
in real software, you don't write a bunch of garbage code on a whim. you think about what you are doing, unless you're a pajeet.
>>
File: 1453291587181.jpg (145 KB, 393x391) Image search: [Google]
1453291587181.jpg
145 KB, 393x391
>>52999963
>Just admit that it's true.
Cry me a river but you are still wrong.
>>
>>52999942
try to make something from the projects list using javascript, google for help when you get stuck, ask here if google doesn't help
>>
>>52999979
>gay functional programming syntax with generics/type inference
>a + b can overflow
>>
>>52999893
>infer the specs
Please never contribute to any meaningful open-source project.

>>52999919
>If I say REKT enough times, everyone will believe me!
If you ask someone to make a function and don't tell them what the returned type should be, there is no way they can return the "wrong" type.
>B-but it's obvious
Now who's the sperg who expects everyone to live inside their head
>>
>>53000024
>automatic generalisation is a bad thing
>a + b can overflow
No it can't
Thread replies: 255
Thread images: 24

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

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.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com, send takedown notices to them.
This is a 4chan archive - all of the content originated from them. If you need IP information for a Poster - you need to contact them. This website shows only archived content.