OSDev.org

The Place to Start for Operating System Developers
It is currently Mon Mar 18, 2024 9:05 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 19 posts ]  Go to page Previous  1, 2
Author Message
 Post subject: Re: Imperative vs. Functional programming
PostPosted: Tue Sep 28, 2021 12:12 am 
Offline

Joined: Sun Sep 26, 2021 2:20 pm
Posts: 1
Imperative programming, which is used by the majority of programming languages today, is a sort of recipe - a series of steps. Put ingredients in a bowl, mix, bake. Put a toothpick in it, if the toothpick isn't dry, wait another 5 minutes, repeat, let cool, cut into slices.

Functional programming describes what something is. You can accomplish the same things, but the wording is very different: brownies are a baked batter mix whose toothpick comes out dry. Batter mix is a combination of the ingredients.

_________________
minotaurfightstore


Top
 Profile  
 
 Post subject: Re: Imperative vs. Functional programming
PostPosted: Tue Sep 28, 2021 6:25 am 
Offline
Member
Member

Joined: Tue Feb 18, 2020 3:29 pm
Posts: 1071
For me, using functional languages makes it more about the language then the particular problem your trying to solve. I use languages that I notice the least. For example, C, Go, and Perl. I wouldn't learn Lisp (save for Emacs / Vim), as I don't think functional programming would help me solve a real-world problem.

_________________
"How did you do this?"
"It's very simple — you read the protocol and write the code." - Bill Joy
Projects: NexNix | libnex | nnpkg


Top
 Profile  
 
 Post subject: Re: Imperative vs. Functional programming
PostPosted: Tue Sep 28, 2021 1:27 pm 
Offline
Member
Member

Joined: Fri May 11, 2018 6:51 am
Posts: 274
nexos wrote:
For me, using functional languages makes it more about the language then the particular problem your trying to solve.
I don't completely agree on that, but there is some truth in your statement: often people don't use functional programming just to solve a problem, but because of the way it's possible to solve that problem with that paradigm. A trivial example is recursive vs iterative algorithms: some problems like in-order visit of a BST have a super simple and elegant recursive solution, while the iterative algorithm is not so simple to read, write and maintain (suppose you might need some tweaks). Note that recrusive solutions are generally much closer to the FP world compared to the iterative ones.

nexos wrote:
I use languages that I notice the least. For example, C, Go, and Perl.
I consider C my "native" language as I've been using it since I was very young and it probably feels more natural to me than any other language, but... do I notice it? Hell, yeah. I mean, it's great and it feels completely natural to me, but I can still compare it to other languages as well. It's the same for human natural languages: at the beginning, you speak only your own native language and don't notice its properties/pros/cons, but after you learn a few other languages, you start comprehending your own language at a different level.

So, briefly, IMHO every language is noticeable and inevitabily affects our thinking model.

nexos wrote:
I don't think functional programming would help me solve a real-world problem.
Imperative solutions typically perform much better than FP ones, but some people might find it comfortable to do some prototyping or writing scripts with FP-like code. It depends a lot on the problem you're trying to solve. FP is very bad for system code where side-effects are the key, but it might offer simpler/nicer solutions when dealing with some purely computational (algoritmic) problems. Don't get me wrong: I'm a C/UNIX guy and I'd prefer people to write highly optimized imperative code for production instead of "wasting" CPU cycles to do extra object copies as it happens with FP techniques: I hate when people try to force FP everywhere. I just wanted to point out that understanding something about FP and its benefits could be useful for a SW engineer, in general. Even if pure FP is not widely used, some FP ideas have been adopted by many OO or multi-paradigm languages like C++, Java and Python: things like map(), filter(), reduce() and stateful lambdas (closures) came from the FP world.

For kernel development, FP won't help not so much I guess but, hey, you don't know for sure what you'll going to do for the next 30 years :-)

_________________
Tilck, a Tiny Linux-Compatible Kernel: https://github.com/vvaltchev/tilck


Last edited by vvaltchev on Tue Sep 28, 2021 2:56 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Imperative vs. Functional programming
PostPosted: Tue Sep 28, 2021 1:51 pm 
Offline
Member
Member

Joined: Wed Aug 21, 2013 7:08 am
Posts: 240
I wanted to post something like this but didn't want to get too much in troll argument :)

But yes sometime also the how matter, it's why we have type system, and proof of correctness etc :) Sometime the noticeable part is to help structuring the program, avoiding bugs, and facilitate proof of correctness.

I'm not that much into full functional langage because i tend to find them obtuse for many things, for me this paradigm really works well for computation, like if you only deal with first class value its fine, the copying doesn't cost much, and the paradigm works well.

but even using imperative langages, i often find myself leaning toward functional style, because it avoid states management, and programs are easier to prove correct. Imperative / OOP can quickly become a mess and hard to really understand and make some bugs hard to spot.

Even carmack made a good case for pure functions :)

_________________
https://gitlab.com/h0bby1/micro-kernel


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 19 posts ]  Go to page Previous  1, 2

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 8 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group