/dpt/ - Daily Programming Thread

Why haven't you learned Smalltalk yet, Jow Forums?

Previous thread:

Attached: functionaltards_BTFO.jpg (1450x975, 493K)

Other urls found in this thread:

stackoverflow.com/questions/14956313/why-is-dictionary-ordering-non-deterministic
arxiv.org/abs/cs/0509027
people.csail.mit.edu/gregs/ll1-discuss-archive-html/msg03277.html
wiki.c2.com/?ClosuresAndObjectsAreEquivalent
twitter.com/NSFWRedditImage

Linear and ordered types will save systems programming

Let the circle jerk begin after this post.

>linear types
non-linear too difficult for you? l m a o

that's a nice head of hair, and beard too. i like this guy

data Auto a b =
Auto { runAuto :: a -> (b, Auto a b) }

Who needs objects?

>objects and functional programming are exclusive to each other.

this is how you recognize a plt illiterate, user.

Attached: gmode.jpg (1280x720, 68K)

>SmallPenis talk about lisp

Attached: 1319666402_850215_0000000000_sumario_normal.jpg (400x268, 25K)

No. It's the other way round

matrix[N][M]

1: M chars
2: M chars
...
N: M chars

And actually, the N lines of M characters are stored contiguously, so that explains why scanf overwrites the previously stored strings.

>objects are OOP
This is how you recognize genetic deficiencies.

I'm doing pic related on HackerRank, and came up with the following code:
numAmount = int(input())
numbers = [int(i) for i in input().split()]
numbers.sort()
numOccurance = dict.fromkeys(numbers)

mean = sum(numbers) / numAmount

if numAmount % 2 == 0:
median = numbers[int(numAmount / 2) - 1]
median += numbers[int(numAmount / 2)]
median /= 2
else:
median = numbers[int(numAmount / 2)]

for i in numbers:
numOccurance[i] = numbers.count(i)

mode = max(numOccurance, key=numOccurance.get)

print('%0.1f' % mean)
print('%0.1f' % median)
print('%s' % mode)


The test case uses this as the input:
10
64630 11735 14216 99233 14470 4978 73429 38120 51135 67060


And expects this as the output:
43900.6
44627.5
4978


I've tested it using the normal Python interpreter and PyPy and get the correct result, but when I try running it on the HackerRank site I get 38120 as the mode instead of 4978. Is it a bug on their end or am I missing something?

Attached: 1500749744388.png (720x675, 61K)

Fuck I'll never stop confusing it.
I have to write it down a few times.

I have a list of parameters in text file:
parameter INT a0 = 1000;
parameter INT a1 = 10;
parament STRING s0 = "MDL";
// ...


How do I use regular expressions to extract values to tuple, like [a0, 1000], etc? Using Java.

for one you are converting your median to an int so you might get rounding errors there

>How do I use regular expressions to extract values to tuple, like [a0, 1000], etc?
Oh, it's easy, just-
>Using Java.
FUCK MY SHIT UP

>regular expressions
but why?

max(numOccurance, key=numOccurance.get) will not necessarily return the smallest mode if multiple exist.

Also, you can use numAmount//2 instead of int(numAmount/2)

project euler problem 3 states:
The prime factors of 13195 are 5, 7, 13 and 29.

What is the largest prime factor of the number 600851475143 ?
----------------------------------------------------

As an intermediate, what should I need to know before dealing with such large numbers in C

Pure functional objects exist in the form of open recursion

It's only converting the number being used as an index for the numbers list, not the median itself.

>max(numOccurance, key=numOccurance.get) will not necessarily return the smallest mode if multiple exist.
What causes it to return a different value on the site than when I run it with the same inputs?

>dealing with such large numbers in C
pro-tip: use strings

>use strings
dumb nigger, use GMP or an equivalent library

>in c
You're basically fucked m8

The term "object" doesn't mean anything in and of itself. It tells you absolutely nothing about how programs should be structured. OOP, as a paradigm, has nothing at all to do with FP. It has completely different basic of program structure and a completely different approach to managing state.

a completely different basic unit of program structure*

>needing external libraries

Use python then to deal with large numbers

get out faggot

Reminder that all strongly typed languages with no type variance are object oriented, because it's data types owning functions as slaves. All languages with type variance, strongly typed or otherwise, are also object oriented, because it's inheritance. To truly escape POO, you need TinyScheme.

>Reminder that all strongly typed languages with no type variance are object oriented

Attached: cFRDcC1jVrLJqgFEkx46cs0eZEGd3SOD-ShqOMqQqWU.png (320x256, 45K)

all talk and no action

I have a very weird task where I need to parse code from modelling language and convert it into the OWL ontology, then use a query later to filter it, but the thing is that there's only one library which would allow to create it, and only in Java.

>because it's data types owning functions as slaves.

object is a well known data abstraction technique where the data (the attributes) are hidden behind a set of operations (the interface). nothing prevent you to make that interface either functional or procedural. see python's integers for an example of functional objects. an alternative to objects are abstract data types.

Wrong, I exclusively use TinyScheme

i too watch rick and Morty

According to
stackoverflow.com/questions/14956313/why-is-dictionary-ordering-non-deterministic
python only preserves the insertion order for dicts since version 3.6, so maybe they're running an older version. max() actually returns the first item it encounters, so other than that, it should work with sorted input.

>because it's data types owning functions as slaves.

Attached: (You).png (645x773, 71K)

yeah and do you have a window in your basement, NEET?

The term "object" doesn't mean anything in and of itself. It tells you absolutely nothing about how programs should be structured. OOP, as a paradigm, has nothing at all to do with FP. It has a completely different basic unit of program structure and a completely different approach to managing state.

How would you do it in other languages?

>doesn't see functions in reality
what a brainlet

Thanks for the link. I'm using 3.6 so that must be why it's only working on my end. I figured that's how max() worked but thought it would be fine since the dictionary was ordered sequentially whenever I checked it.

OK, I think I found a viable Python library. How would I do that in Python then?

Currently learning C
I have a simple struct, declared as

struct Song() (
char title[40];
char artist[40];
int year_published;
}


and I have an array of those songs, 1024 big, declared.

However, I am having hugeeee issues reading values from a file and inputting them into the song.
the format of the .txt im reading from is
year,title,artist
so
1995,Blink 182,Small Things

thats the only line in the file but I can't even get the stuff appropriately with this line of code:

while (fscanf(f, "%i%*c %s%*c %s%*c", &music_library[i].year_published, music_library[i].title, music_library[i].artist != EOF)


I have i initially at 0 and I increment up as more lines in the file are read(again, I only have 1 because I can't even get the most simple case to work) but basically the array will be filled with songs from a .txt file in the above format.

However, I get either infinite looping or segfaults when I try and make it work.

I have used gdb but I still cant figure it out.


Any help? I am trying to ignore the commas and basically only get the relevant data.

So autos which maintain their own local state and can easily dispatch methods based on messages passed are not at all like objects? There's also the part where objects themselves are just structures referencing themselves which I do believe resembles functions quite a bit.

arxiv.org/abs/cs/0509027

1)
return status code
have lookup table for error messages
2)
return bool and error string
3)
return status code / bool and log errors. User can supply custom logging function and change log level.

1)

5. no status code, just log the error, and default to whatever to keep the program running.

operation :: Either Error Value

How do I get a job if I graduated 4 years ago and have lived as a NEET since?

Attached: 3d2f17a94f93d9ddd58796b4b3e65e4a00070aeb_hq.jpg (784x439, 34K)

This Haskell code:

data MyType = consMyType Int Int
f :: MyType -> MyType
g :: MyType -> Int -> MyType

Is not very different from this C++ code:

class MyType {
public:
int ints[2];
void f();
void g(int);
};

The differences:
* C++'s f and g are stored in a vtable associated with the type MyType. Haskell's are not. This gives the superficial appearance that in Haskell, the data type MyType does not own the functions f and g as slaves, a la OOP, but rather that they are "free functions" for all intents and purposes.
* In Haskell, the functions f and g are defined outside the definition of the data type MyType. Same superficial appearance.
* In Haskell, you can just do f or g; you don't need to qualify it with MyType::f or MyType::g.

The SIMILARITY:
Both versions of f and g require an instance of MyType. They cannot be called without such an instance. Therefore, they are second class citizens, inextricably bound to the type MyType, existing in service to it, and serving no useful purpose without it. It is true that in Haskell, overloads of f and g may exist, so the NAMES f and g may not be bound in servitude to MyType, but the FUNCTIONS f and g are nonetheless, since the OTHER functions f and g which may exist are indeed separate functions, and which one is meant for any given case is decided at compile time using type inference, thus ruling out the possibility of passing around at runtime any kind of bundle of references to all overloads of any given name. So, since no single callable datum ever exists that's free of servitude to any specific type, all functions in Haskell are STILL slaves to data.

In TinyScheme, functions are truly free. There is no OOP, for data types can never own functions or hold them down.

Lie on your resume. Say you just graduated.

What if they do a background check?

The term "object" doesn't mean anything in and of itself. It tells you absolutely nothing about how programs should be structured. OOP, as a paradigm, has nothing at all to do with FP. It has a completely different basic unit of program structure and a completely different approach to managing state. I'll just keep repeating it until you actually address it, because your basic premise is invalid.

interview #5 tomorrow please pray for me

>The term "object" doesn't mean anything in and of itself.
it does; simula defined the concept which was then taken up by smalltalk.

I did. Hope you get the job user.

Object oriented programming is just message passing, local state, and late binding which can be captured in any functional language we've ever had. Heck, erlang is better OOP than most.

Hope they don't. Besides, aren't background checks usually for stuff like criminal history

>still not actually addressing anything i said
I accept your concession.

Because smalltalk is futile

What the fuck?
Smalltalk is a programming language, not a flute.
Did you somehow come to the wrong board?
Were you looking for ?
This is the technology board. Unless perhaps you're interested in the technology of musical instruments?

>Not taking advantage of both oo and fp

>tfw when hasklets see this and go REEEEEEEEE
Just accept it, your inferior """""""""""""""""""""functional"""""""""""""""""""""""" ((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((language))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))
is object oriented and therefore a shitlang.

Attached: Smugwojak4v2.png (640x400, 32K)

Maybe you'll understand how to correctly take advantage of both when you understand why they're incompatible.

>>>>he uses sepples

Attached: 1424136314538.png (1000x768, 389K)

They aren't though, you can just have some functions that belong to objects as message responses and some that don't.

>Haskell is OOP because functions have types and it kinda reminds me of C++
Solid argument right there, monkey.

Attached: camelhead-wojack.png (485x443, 22K)

That wasn't the argument though. The argument was that Haskell is OOP because when functions have types, the functions are necessarily owned by those types as slaves, in exactly the same manner as if the function had been declared within a declaration of that type as a class.

functional programming is when you reason and build your program with functions.
object oriented programming is when you reason and build your program with objects.
if you implement objects with functions, then you are doing both.

Where does a dude have to go to learn about algorithms?

And I'll continue to reply with FP as we already have several places where object oriented programming is used (NixOs) in pure functional languages.

>X uses a different basic unit of abstraction from Y
>X uses a different basic unit of program structure from Y
>X has a different way of putting the basic units together from Y
>X has a different approach to handling state from Y
>X and Y are obviously compatible, though
Mental illness.

>functional programming is when you reason and build your program with functions.
>object oriented programming is when you reason and build your program with objects.

Attached: Untitled.png (485x443, 34K)

>i can't address your refutation
>so i'll continue my mindless denial
Mental illness.

>if you implement objects with functions, then you are doing both.

>not knowing what the basic unit of abstraction is in FP and OOP

Mental illness.

struct foo {
int bar;
};

int f(foo fuuu) {
return fuuu.bar;
}

Nice, so C is object oriented as well!

Objects are a poor man's closures

people.csail.mit.edu/gregs/ll1-discuss-archive-html/msg03277.html

wiki.c2.com/?ClosuresAndObjectsAreEquivalent

Sure they are. They're compatible in the sense that you can use them together. If you mean compatible in the sense that you SHOULD use them together, then I accept that they're not """""compatible""""" by that piss poor definition.

Consider, for example, a virtualization program written in Java.
Try using such a program to run Debian.
Then, within that Debian, do:
sudo apt install tinyscheme
tinyscheme
There ya go, you've got OOP working together with FP.

Yes! Yes, it is! And no, it's not nice at all, it's a fucking awful cancer.

This is low quality bait.

Arguing that Haskell is object oriented due to f : Constraint ty => ty -> ty is only well defined for the type ty is absurd. Even forth which has no types will have words which are defined over a subset of all possible inputs (thus could be represented as types). If that's your reasoning then all languages are object oriented as all procedures/functions/relations written are only well defined for a subset of all possible inputs.

Even lambda calculus and the turing machine are bound by the same rules so using your logic they must fall under object oriented too. Thus by your definition TinyScheme is object oriented thus a shitlang like all the rest. Well done.

And by the way, this example demonstrates just as aptly that C is object oriented:
int intIdentity(int n) {
return n;
}

In this case, n is the object, int is the class, and intIdentity is OWNED by the "class" of int, in EXACTLY the same manner as if it had been written as follows:
class MyInt {
public:
void identity();
};

>an A is not a B
>you can build something up from As
>but at the same time you can build it up from Bs
Mental illness.

>Even forth which has no types will have words which are defined over a subset of all possible inputs (thus could be represented as types). If that's your reasoning then all languages are object oriented as all procedures/functions/relations written are only well defined for a subset of all possible inputs.
That's different because not all subsets of all possible inputs are types. All types are subsets of possible inputs, but not all subsets of possible inputs are types, and you cannot and will never devise a sufficiently sophisticated static type system to make it so.
So, indeed, all functions are exclusively compatible with some subsets of possible input. This is unavoidable. It's when you try to reify these subsets as types that you really solidify that relationship of slavery.

>>such a piss poor strawman that it literally has nothing whatsoever to do with what I just said
>Mental illness.
Mental illness.

>the basic unit of abstraction a paradigm uses has nothing to do with its compatibility with a different paradigm
Classic /dpt/. I come here purely to feel superior to you "people"...

R5RS, R6RS, or R7RS?

Attached: 20180312_025645.jpg (275x347, 61K)

>>such a piss poor strawman that it literally has nothing whatsoever to do with what I just said
Classic /dpt/. I come here purely to shitpost, just like you're doing now. It really is so much fun isn't it brother

CL YOU FOOL

R8RS
gr8 r8rs m8 r8 8/8 no h8 2 db8

CL a shit

>if i label arguments i can't address as strawmen, i win
Reminder that if:
- paradigm X tells you to structure your program using units of A
- paradigm Y tells you to structure your program using units of B
- an A is not a B
- a B is not an B
Then paradigm X tells you to structure your program in a different way from paradigm Y, so they are incompatible. I know your parents are siblings, but it shouldn't be that hard to understand even for a quasi-human animal.

>let's use scheme where every implementation ends up providing same shit as CL but in non portable way
damn dude

a B is not an A*

call-cc
:^)

Closures are a poor man's objects. Closures can be trivially emulated with objects, objects are difficult to emulate with closures.

feature most scheme implementations don't even implement because it would be slow as fuck

So is hardware inherently object-oriented?

what is the basic unit of abstraction in oop?

Objects can be trivially implemented using closures. Closures are impossible to implement using objects. No, fucktard; manually storing every relevant piece of state isn't the same as having closures.

>Then paradigm X tells you to structure your program in a different way from paradigm Y,
Yes, I agree with everything up to and including this part.
>so they are incompatible.
I disagree with this, however. You can literally just structure some parts of your program in accordance with paradigm X and some parts in accordance with paradigm Y. Your entire program is then in accordance with neither, and no part of it is in accordance with both, but that doesn't change the fact that certain isolated segments of it are in accordance with either.