Blog
Ryan Moscoe
Software Engineer | AI Prompt Engineer | Ninja
- Blog
- Software Engineering
- Will Hunting Challenge
-
Many Happy Returns
Many Happy Returns
Oops! Something went wrong. Please try again later.
I took a few days off from my #WillHuntingChallenge in honor of my wife’s birthday. I’m back at it now though, and working my way through Introduction to Computation and Programming Using Python. I’m currently working through the material on functions, and speaking of happy returns, today I learned that all Python functions return a value, even without a return statement. In the absence of a return statement, the function returns None.
That may seem basic and obvious, but it is hardly a fundamental or universal law of programming in all languages. For example, Elixir doesn't even have a return keyword. Elixir functions automatically return the value computed by the last executed line in the function.
Nevertheless, I think I’ll stick with explicit return statements even when returning None for now. Yes, that might add a line of code here or there, but I’m willing to trade a bit of elegance for additional clarity that could help other developers (or my future self) with maintenance and debugging.
Oops! Something went wrong. Please try again later.