Ditch your Favorite Programming Paradigm

Ditch your Favorite Programming Paradigm

Code Persist

1 год назад

155,865 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

Capuccino Pintucciono
Capuccino Pintucciono - 19.09.2023 12:25

I love that you say "FP if well written, can be extremely elegant" and proceed to show an example of non-FP program where Python's sorted function has a side effect, as it changes the list in-place :D

All good, though, the points are the same, and you did give the disclaimer

Ответить
Flame of the Phoenix
Flame of the Phoenix - 11.09.2023 23:15

Structured imperative is the most fun to use.

Ответить
Neun MalElf
Neun MalElf - 27.08.2023 16:37

You explained it very well. I just don't know for WHOM the explanation is. A beginner can't make heads and toes from the acronyms. Let alone understand the complexity of the problem itself. An experienced programmer is mostly defined by the language he uses (or is 'forced' to use). Maybe a reminder to think about the whole thematic? Well done, either way.👍👍👍

Ответить
starc0w
starc0w - 11.08.2023 12:31

It is.

Ответить
Ian Joyner
Ian Joyner - 25.07.2023 15:18

The multi-paradigm approach just ends up with a confused mess, especially on multi-programmer projects. The term multi-paradigm was introduced as a sorry excuse for the mess of C++ that did not remove the old from C that OO made unnecessary.

Alan Kay (who coined OO): “This is the most pernicious thing about C++ and Java in that they think they’re helping the programmer by looking as much like the old thing as possible but in fact they’re hurting the programmer terribly by making it difficult for the programmer to understand what is really powerful about this new metaphor.”

Ken Thompson (originator of B/C from BCPL): “[C++] certainly has its good points. But by and large I think it's a bad language. It does a lot of things half well and it’s just a garbage heap of ideas that are mutually exclusive.”

Now other languages are adopting multi-paradigm because C++ is supposedly MP. It is insanity. Not that FP and OO can't be mixed in a sane way, but MP is an excuse for messes.

And Java is not a particularly good OO language either. Too many things mixed in afterwards (indicated by '@'). Even generics were an afterthought and never right. Cleaner than C++, but it would be hard not to be.

Ответить
imaad Haq
imaad Haq - 13.07.2023 00:19

You can essentially model functions the same way as classes. The car maintenance example can be done functionally by having a createCar function which can be passed into driveCar. driveCar can then return the new state of the car, including whether or not it needs maintainance. Additionally, you could model it closer to how you did it, but have whatever function be used to drive the car return if it needs maintainence.

Ответить
laughingvampire
laughingvampire - 06.07.2023 06:04

Ok, I will solve you this dilemma, simple
Alan Kay invented OOP & he said OOP is about message passing, encapsulation and late biding.

now, think about this, in Functional Programming:
Functions receive and send parameters to other Functions.
Every time you send a parameter list to a Function, this Function guarantees is going to return an answer.
Functions are encapsulated, their local data is encapsulated from everyone around, it can only accessed by an api that is given by the same function AKA returning a closure.
With closure you have late binding
so, FP is a type of Object Oriented programming, different to class-based & prototype based.

The difference is that OOP in languages like in C++, C#, Java, Python, Ruby, etc, OOP is just procedural programming organized within modules around single dispatch. classes are a Frankenstein of modules wrapping a type and wrapping an api for that type.

Ответить
Alexander Feterman
Alexander Feterman - 11.06.2023 19:32

"[Functional Programming] can be considerably harder to scale up". I've found the opposite to be true after almost 30 years of coding, but you do have to switch mental models and use different code organization techniques.

Ответить
Yonas
Yonas - 08.06.2023 21:58

Good video, but your mic 🎤 is not the best

Ответить
Khải Hoàng
Khải Hoàng - 13.05.2023 18:28

FP would be "hard to scale" as you said if it contains only functions. But most FP languages offer types and traits (called typeclasses in Haskell). I prefer them to OOP classes.

Ответить
Cheeba Digga
Cheeba Digga - 13.05.2023 01:26

dat indentation tho lmao wtf

Ответить
AURORA FIELDS
AURORA FIELDS - 10.05.2023 23:50

I find myself just loving JavaScript's weird oop/procedural/functional style mix actually the best. can take advantage of the best points from both worlds and use some fairly simple syntax to do it. and yet, classes are just syntactic sugar for functions... but with the help of typescript, instead of having strong types/classes like many oop and procedural languages, you actually have rather freeform and if you want, complex and intricate types that model the problem accurately and much more freely.

like I get the hate for JavaScript, but a lot of its faults are fixed by typescript and linters. When you don't need super fast performance its a godsend

Ответить
NUS MUS
NUS MUS - 09.05.2023 04:07

Do we know which font was used in the code examples?

Ответить
Bert Rodgers
Bert Rodgers - 07.05.2023 22:03

what colour scheme is that please?

Ответить
Lorenzo Jojoba
Lorenzo Jojoba - 07.05.2023 00:52

What software is udmsed for the animations?

Ответить
ashrasmun
ashrasmun - 06.05.2023 20:18

The way you indent the code angers me immensely. I don't believe you prepared these examples.

Ответить
edgeeffect
edgeeffect - 29.04.2023 21:01

Composition Over Inheritance

Ответить
Hamid Bluri
Hamid Bluri - 21.04.2023 06:41

what is the presentation software that you use?

Ответить
Arthur V. BABAYAN
Arthur V. BABAYAN - 20.04.2023 08:00

Which paradigm use, depends on task what you should solve !!!

Ответить
Dune 2 - The Maker
Dune 2 - The Maker - 17.04.2023 20:56

The more I code the more the paradigms are language agnostic to me. You can accomplish a lot of FP’s paradigm in a non-fp language.

Ответить
MorTobXD
MorTobXD - 17.04.2023 02:26

I like to tell my computer exactly what to do to maximize cache performance, minimize space usage, ...

For example, if I want an integer array with values from 0 to 15, I'm not gonna use an u8 array, or even worse, an i32 or u32 array, nooo, I'm gonna implement a damn bitset ^^

Ответить
David Alsh
David Alsh - 16.04.2023 02:59

I recently had to maintain a script written using the functional programming paradigm (in a multi paradigm language) to handle some basic operations. There was a bug occurring somewhere and I wanted to inspect the values in the circuit. Went something like:

"array = (startArray || []) |> dedupe(flatmap(foo(bar(baz))))"

It took me 30 minutes to reason about the control flow. To unwrap the steps in my head, I had to hold a imagined stack of all the steps in reverse. Sure I could run unit tests to probe - but sometimes you just want to glance at code - particularly if you don't have the environment set up and it's a quick fix.

It is certainly concise and clever keeping all of that logic on one line, but it's exhausting unwrapping it to find a bug or change.

So I rewrote it, expanding it into a verbose, boring, procedural control flow - using a Set to deduplicate entries, nested for loops to mimic the flatMap, etc. I added additional logging and safety guards then found the bug.

Though it probably looks offensive and old fashioned to anyone reading it, it's impossible to get lost because all of the behaviours are explicit and self documenting. Regardless of whether you come from a JavaScript or C background - you would understand the procedural control flow. Lastly, when emulating the circuit in your head, you don't need to hold as many steps so it's harder to get lost in thought.

IMO I'm open to FP and I do think it has its merits, but in my experience, it's sort of a meme and not suitable for most use cases.

Ответить
freedmen123
freedmen123 - 15.04.2023 09:49

OO code in Lisp is both functional and shorter than Java equivalent. Please ditch your favourite language while you're at it.

Ответить
MAMBA OP
MAMBA OP - 14.04.2023 04:37

I mean how you guys edit these videos can someone explain me how to edit videoes like these

Ответить
Kasun Vithanage
Kasun Vithanage - 14.04.2023 00:49

Yes you used the wrong language for FP

Use something like Elixir and your car example is very easy to implement with a GenServer

Ответить
Leukocyte The Blood Cell
Leukocyte The Blood Cell - 13.04.2023 18:59

A small suggestion to make sound in your videos better. You have quite noticeable reverberation in it (echo like in church). To decreade it and make your voice clearer 1) Hold mic closer to your mouth. This way you will increase the difference in the voice/room noise ratio and you voice will be more dominant. 2) Reverb is just a reflection of sound (mainly from walls), so to prevent it from appearing, the sound wave has to not hit the walls. Having something front of you (like blanket) will help a lot. The room you record in sounds quite empty in general, so having a lot of items in it will also help, but recording under a blamket would help the most :D

Ответить
ibrahim koz
ibrahim koz - 13.04.2023 01:15

Your understanding lacks some essentials of OOP. OOP is not about inheritance. Its power comes from encapsulation, dependency inversion and abstraction. Interfaces are cornerstone of this paradigm. Encapsulation is about enforcing the always valid domain model. It's the best paradigm to design your domain model.

Ответить
Zxmon
Zxmon - 12.04.2023 23:25

What did you use to display the code? It looks really good. Also really great video.

Ответить
Steven Sun
Steven Sun - 12.04.2023 19:28

Easily modeling a domain is absolutely one of the strong suits of FP - most FP languages have algebraic data types which make modeling a much more straightforward task than figuring out a complicated object hierarchy, especially in languages which don't support multiple inheritance. Learn about modeling a domain with product and sum types.

Ответить
Philip M
Philip M - 12.04.2023 09:43

With the language that shall not be named (Note: I do not represent THE RUST FOUNDATION - may they burn in New York/California) they have both great type abstraction (without f'**king OOP classes) and functional language features.
Sorry the Rust Foundation pissed off the entire the language that shall not be named community with their insane Trademark policy this week. They are as mentally ill as Budweiser.
It's too bad... their language is pretty good. Someone may have to fork it and come up with another name and rational/sane policies. Or just take their principles and start over.

Ответить
Danilo Bassi
Danilo Bassi - 12.04.2023 05:58

JavaScript/Typescript: yes

Ответить
أمان الله منجلي
أمان الله منجلي - 12.04.2023 00:39

Nice video, thank you for making it.
I learned a lot from it and I enjoyed watching it.

Ответить
I Eat Garbage
I Eat Garbage - 11.04.2023 21:05

“Encapsulation is about data safety” 🤮

Ответить
saultube44
saultube44 - 11.04.2023 15:39

Functional programming is BS, not everything can be reduce to functions, you need procedures and other logical structures; that's why Monads and other "auxiliary" "functional" procedures were invented in Haskell, so stop spreading this BS concept, OK?

Ответить
Mihail Mojsoski
Mihail Mojsoski - 11.04.2023 05:45

side effects and shared/global are sometimes the best way to do stuff if you are aware of threads (use thread-locals instead of proper globals)

Ответить
Ghi102
Ghi102 - 11.04.2023 05:32

I'm going to be quite harsh, but honestly, this sounds more like a beginner's view of OOP and FP. At best incomplete, at worst completely wrong.

private/public defines the scope in which the variables are accessible, it's not related at all to privacy or security. It would be completely normal to have the SSN be a public variable in a program that deals with SSN.

Polymorphism also isn't an OOP thing. It was first brought on by FP and was added to OOP later on. There are also many more types of polymorphism than the simple subtype polymorphism you mentioned. For example, parametric polymorphism, which is the main type of polymorphism used in FP

I also don't think talking about FP without having any experience using a FP language is a good idea. I am afraid that it is misleading more than helpful

Ответить
ala o
ala o - 11.04.2023 05:17

the thing about java i like, the new versions of java provide cool things for example records make u get rid of boilerplates, also stream API which opens the door of functional programming in java

Ответить
Ethan Standel
Ethan Standel - 11.04.2023 04:35

I get that the message here is: broaden your horizons. But the idea that you should mix and match programming paradigms is just wrong and will result in entirely inconsistent code. That is far harder to read and understand than just following the paradigms that your language or framework has set up for you.

Also, you seem a little too lost in how functional programming actually works to be speaking on it. You still have "objects" in functional programs, but they're more like structs. They're just the data. In functional programming, your data is data and your functions are functions and they don't mix. Your data doesn't have responsibility, it is just a representation of state. So if you need to check if your car object needs maintenance, you just check the maintenance property or you have an outside needsMaintenance function that will calculate if it needs maintenance based on the data you do have available.

The reason this is better is because no real program in the modern day owns it's own data. You're getting your car out of a database. It can't actually update itself, because a model class writing to a database would be a mess and horrible responsibility management. In the real world data is almost always treated as immutable. "If I change this thing in memory, I also have to sync the change with the outside source and probably update the UI." An object can't do that on its own.

The only place OOP works, imo, is game development because per animation frame, your framework is updating the UI based on the current state. There's no more magically efficient way to do this. So updating items state is fine because the UI is constantly syncing itself with the data. But in any other type of application, constantly writing back to another source would be horrifically inefficient.

Ответить
Jorge C. M.
Jorge C. M. - 11.04.2023 02:11

About Java's boilerplate, you can do 'void main() {print("Hi");}' in the latest preview, I think

Ответить
András Gyarmati
András Gyarmati - 11.04.2023 00:18

oops most important feature supposed to be messaging and not encapsulation

Ответить
Philip Popescu
Philip Popescu - 10.04.2023 23:16

Tell that to C... :)

Ответить
sichadeb
sichadeb - 10.04.2023 22:00

statically typed functional languages allow you to avoid the pitfall you mention -- here's an example of the car class using OCaml modules:

module Car = struct
type t = { name: string ; miles_driven: integer }

let drive t miles = { t with miles_driven = t.miles_driven + miles }
let needs_maintenance t = t.miles > 100
end

the module system and strong typing allows you to keep data together and act on data like you would with a class while maintaining immutability and functional guarantees. the problem with python is that you don't have a good way to group multiple bits of data together without using a class (maybe named tuples?)x

Ответить
Mike Watkins
Mike Watkins - 10.04.2023 16:30

literally just into 2nd module of MS Introduction to Python tutorial covering 'Introduction to object-oriented programming with Python ' so super noob at coding but already see the strengths of OOP as a paradigm but the OCD in me looks at Functional and goes 'so pretty'

thanks so much for the vid - really added to what I am covering at the moment with OOP also.

Ответить