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 7429333
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T08:57:14+00:00 2026-05-29T08:57:14+00:00

Function calculate_attribute does not return a value; it only works through side effects. Often

  • 0

Function calculate_attribute does not return a value; it only works through side effects.

Often within that function I have to write these few lines:

print('some message')
set_attribute(value)
return

So I decided to put this into a different function:

def report_and_set(value, message):
  print(message)
  set_attribute(value)

Is it ok to now do the following:

   def calculate_attribute(params):
     #...
     if something:
       return report_and_set(value, message)
     #...
     if another_condition:
       return report_and_set(value, message)
     #...     

It feels kinda weird to write this since report_and_set has no return value. But if I don’t, I’d have to repeatedly type return after every call to report_and_set.

  • 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-29T08:57:15+00:00Added an answer on May 29, 2026 at 8:57 am

    Many programmers, myself included, prefer a single return per function.

    Occasionally, I may insert a return in the first few lines of a function to bail if some sanity check fails.

    I wouldn’t in this case.

    In this case, I would simply do…

       def calculate_attribute(params):
         #...
         if something:
           report_and_set(value, message)
         #...
         elif another_condition:
           report_and_set(value, message)
         #...     
    

    But also consider the Single Responsibility Principle (it applies equally to functions and classes). If your function is long and contains lots of conditional function invocations,
    it’s probably time to refactor!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

pure is a function attribute which says that a function does not modify any
I have this function which calculates some value based on multiple slots of multiple
I have a function that performs a Luhn check on a card entry when
i have a function to calculate several different values: int ASPfile::get_dimensions(int* Lat, int* Lon,
I'm trying to calculate the number of success cases within a recursive function in
I have a function which calculates distance from database records. This function is called
I've got a Moose class with a lazy_build attribute. The value of that attribute
I have this response.write on my page function roundthecon() { document.write(Math.round(exchRate*Math.pow(10,2))/Math.pow(10,2)); } But it
Here's my problem I have this javascript if (exchRate != ) { function roundthecon()
I have a function to calculate the inverse of a quadratic equation. By default

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.