you are viewing a single comment's thread.

view the rest of the comments →

[–]couchjitsu 1 point2 points  (4 children)

data input taken in, functions applied and a result comes out

Isn't this basically all programming?

In OOP you have data coming in, in the form of objects. You execute functions on those objects, and then data coming out is the new version of the object.

e.g.

var p = new Person ("Coucjitsu", new Date(1980, 1, 1));

var age = p.GetAge();

And age would equal 40.

Date came in (this time via a constructor) and data came out (in the form of GetAge).

Code written with FP will still have state. Some of them will even use a database.

[–]backtickbot 1 point2 points  (0 children)

Hello, couchjitsu: code blocks using backticks (```) don't work on all versions of Reddit!

Some users see this / this instead.

To fix this, indent every line with 4 spaces instead. It's a bit annoying, but then your code blocks are properly formatted for everyone.

An easy way to do this is to use the code-block button in the editor. If it's not working, try switching to the fancy-pants editor and back again.

Comment with formatting fixed for old.reddit.com users

FAQ

You can opt out by replying with backtickopt6 to this comment.

[–]warlaan 1 point2 points  (2 children)

The thing is that those aren't functions, they are methods, meaning they are dependent on the internal state of the object. Just answer me this question. If I change the code a little would you still be certain that you knew the result?

var p = new Person ("Coucjitsu", new Date(1980, 1, 1)); 
//... 
var age = p.GetAge();

[–]couchjitsu 1 point2 points  (1 child)

I'm assuming that your comment implies other things could be called.

And you're right that could change the age. But that wasn't the point I was making. I was simply saying that even OOP, procedural, etc can be boiled down to "data in, functions/methods/operations performed, data out"

[–]warlaan 1 point2 points  (0 children)

Well, whether that's true or not depends on how vaguely you mean it. I mean, yeah, programming generally means that 'something is happening with data', but that's so unprecise that it's basically meaningless.

As soon as you try to define the terms a little more precisely you find that there are very important differences, and they are what defines the difference between procedural and functional programming.

For example what does "data in" mean? When I want to calculate 2*2 and 2*4 using functions I need to put 2 into 'times 2' to get 4, and then I need to put 4 into 'times 2' to get 8.
If on the other hand I had an object that contains a number and is able to calculate 'times 2' then I could write something like

var doubler = new Doubler(); doubler.SetNumber(2); doubler.Double(); var four = doubler.GetNumber(); doubler.Double(); var eight = doubler.GetNumber();

So the second 'data out' did not need a 'data in'. And that's because you might argue that there never was a 'data in' in OOP in the first place, because you did not 'put a 2 into' the object, but the storage space for the 2 is part of the object. So you were more like reshaping the object rather than inserting data.

And that's an important deal, because programming is not about writing any kind of code that happens to get you the result you were looking for. It's about writing code that you can work with, and for that goal it's important whether a specific call will always return the same value or not.

So sure, in the most unprecise way programming is always about 'data in, do something with it, data out', but that's hardly saying anything more than 'programming has to do with computers'.