gregorni,
@gregorni@fosstodon.org avatar
camelCaseNick,
@camelCaseNick@floss.social avatar

@gregorni bold statement 🤨️

gregorni,
@gregorni@fosstodon.org avatar

@camelCaseNick Yes, quite, I know😅

fkinoshita,

@gregorni It can be pretty hard to understand recursion thinking about the same function calling itself or recreating the call stack in your head, the way I think about it is "am I covering all the cases?" that being does it work for the base case and for the n + 1 case.

Some example in python

def fact(n):  
 if n == 0: # base case  
 return 1  
 return n * fact (n - 1) # n + 1 case  

It's important to note that the n + 1 case converges to the base case with each call to fact()

gregorni,
@gregorni@fosstodon.org avatar

@fkinoshita Okay, I'll try to think about it like that next time, that might help. Thanks :)

kramo,
@kramo@fosstodon.org avatar

@fkinoshita @gregorni Isn't Python specifically kind of terrible for recursion by the way?

http://neopythonic.blogspot.com/2009/04/final-words-on-tail-calls.html

fkinoshita,

@kramo @gregorni Yes, just wanted to use a language Gregor was familiar with!

gregorni,
@gregorni@fosstodon.org avatar

@fkinoshita @kramo Some context: I'm doing this because I'm writing OCaml.

Also, for future, reference, I recently got to a stage where I feel I understand Rust.

fkinoshita,

@gregorni What are you using OCaml for?! Gave it a try some time ago but didn't really like it

gregorni,
@gregorni@fosstodon.org avatar

@fkinoshita Just learning it for the experience, no real plans with it.

gregorni,
@gregorni@fosstodon.org avatar

@fkinoshita I'm also kind of confused, because I don't really know what area of coding OCaml is targetting. Their website says it's memory-safe, fast, and industry-leading, but nowhere does it say what usecase it's intended for.

apinsard,

@gregorni @fkinoshita Honestly I feel like ocaml is mainly used by French students because it is in the official program of a popular course. It is quite good for theoretical computer science actually, I've heard it's also used a bit in research works

gregorni,
@gregorni@fosstodon.org avatar

@apinsard @fkinoshita Yeah, that's what I thought. OCaml seems like a very theoretical language, good for studying CS and programming concepts, but less widely used.

boggle,

@gregorni Why? Explicit tail recursion can be quite readable.

gregorni,
@gregorni@fosstodon.org avatar
user8e8f87c,
@user8e8f87c@berlin.social avatar

@gregorni Never use explicit recursion, we have map and fold.

gregorni,
@gregorni@fosstodon.org avatar

@user8e8f87c Oh, wait, I think you just solved my problem.

And yes, I love map() so much (haven't used fold() yet.)

bragefuglseth,
@bragefuglseth@fosstodon.org avatar

@gregorni Recursion is an antipattern.

bragefuglseth,
@bragefuglseth@fosstodon.org avatar

@gregorni Recursion is an antipattern.

bragefuglseth,
@bragefuglseth@fosstodon.org avatar

@gregorni Recursion is an antipattern.

bragefuglseth,
@bragefuglseth@fosstodon.org avatar

@gregorni Recursion is an antipattern.

bragefuglseth,
@bragefuglseth@fosstodon.org avatar

@gregorni Recursion is an antipattern.

kramo,
@kramo@fosstodon.org avatar

@bragefuglseth @gregorni

⚠️ "Brage Fuglseth" was killed because it ran out of memory.

gregorni,
@gregorni@fosstodon.org avatar

@kramo @bragefuglseth Oh, no 😨

stphrolland,
@stphrolland@mathstodon.xyz avatar

@gregorni

Is it humour, your misunderstanding, or my misunderstanding ?

gregorni,
@gregorni@fosstodon.org avatar

@stphrolland It's me not being a 100% functional bro yet 😂️

lulu_powerful,
@lulu_powerful@fosstodon.org avatar

@gregorni Nooooo! But I really like it! It's so elegant, like a swan. But I guess swans don't have much utility. :P

gregorni,
@gregorni@fosstodon.org avatar

@lulu_powerful I mainly just find it hard to follow from a logic perspective… 🤔️

localstatic,

@gregorni @lulu_powerful My take would probably be more nuanced than what you started with, but I’m curious about how you get from you finding it difficult to outright calling it an anti pattern. Can you elaborate?

gregorni,
@gregorni@fosstodon.org avatar

@localstatic @lulu_powerful Of course, I was exaggerating in a moment of annoyed frustration when I didn't manage to solve a proble with recursion. I actually find it easy to follow in some cases (for instance, I'm reading a book about writing a compiler, and there, it's clear as day.) But I do think in most scenarios (like iterating over a list), simple loops (or a map function, which is recursive) are easier to follow.

  • All
  • Subscribed
  • Moderated
  • Favorites
  • FunctionalProgramming
  • DreamBathrooms
  • mdbf
  • ethstaker
  • magazineikmin
  • GTA5RPClips
  • rosin
  • thenastyranch
  • Youngstown
  • InstantRegret
  • slotface
  • osvaldo12
  • kavyap
  • khanakhh
  • Durango
  • megavids
  • everett
  • cisconetworking
  • normalnudes
  • tester
  • ngwrru68w68
  • cubers
  • modclub
  • tacticalgear
  • provamag3
  • Leos
  • anitta
  • JUstTest
  • lostlight
  • All magazines