Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6192509
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T02:57:19+00:00 2026-05-24T02:57:19+00:00

I often see Erlang functions return ok , or {ok, <some value>} , or

  • 0

I often see Erlang functions return ok, or {ok, <some value>}, or {error, <some problem>}.

Suppose my function returns an integer N. Should my function return just N, or {ok, N}?

Or suppose my function includes the call io:function("Yada yada"). Should it return ok or nothing at all?

Or suppose I’m making a record or fun. Should I return {ok, R} or (ok, F}?

Thanks,

LRP

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T02:57:20+00:00Added an answer on May 24, 2026 at 2:57 am

    It’s a matter of style, but making reasonable choices goes a long way toward making your code more readable and maintainable. Here are some thoughts based on my own preferences and what I see in the standard library:

    • If the function can return with both a success and a recoverable failure case, you may want the success case to look like {ok, _} or ok. Good examples are: orddict:find/2 and application:start/1. We do this so both cases can be easily pattern matched when making the call.
    • If the function has only a success case with a meaningful result, then just return the result as there is no need to add additional information. In fact if you were to wrap the result in a tuple, then you can’t easily chain calls together e.g. foo(bar(N)) may not work if bar/1 returns {ok, _}. Good examples are: lists:nth/2 and math:cos/1.
    • If the function has only a success case without a meaningful result, the common idiom is to return ok or true as opposed to whatever the last returned value in the function happened to be. Good examples are: ets:delete/1 and io:format/1.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I often see constructor functions that just call an init() function. Why have an
I often see code like int hashCode(){ return a^b; } Why XOR?
Do you often see in API documentation (as in 'javadoc of public functions' for
I often see java SourceCode where a null as value for a method or
I often see this idiom when reading php code: public function __construct($config) { if
I often see it mentioned that Thread.Sleep(); should not be used, but I can't
I often see the following code: (function () { // init part })(); but
I often see this error message in my logs and it is pretty cryptic.
I often see this in ajax function function(event, data, status, xhr) . I'm wondering
Quite often see in JavaScript libraries code like this: setTimeout(function() { ... }, 0);

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.