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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:33:06+00:00 2026-05-28T00:33:06+00:00

A simple best practices question that I haven’t seen addressed in the introductory programming

  • 0

A simple best practices question that I haven’t seen addressed in the introductory programming books I’ve read…

If a function or method does an action but does not return real data, an example being a function that increments a class property or a database value, should it always return a boolean success value?

Part of me says “of course, duh”, and then part of me says my code would quickly overflow with boolean success checks on every little operation.

Currently I check success on critical functions, but not on cascading functions that run if the critical check is passed, on the assumption that the success of the first ensures valid data/success of the following ones.

But I’m just a hobbyist. What do the pros do?

  • 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-28T00:33:07+00:00Added an answer on May 28, 2026 at 12:33 am

    Returning success values when you don’t expect something to fail is generally bad design. You can forget to check the return values or check them in the wrong way, and if you start to use different values for different errors, things quickly get out of hand. (-1: success or failiure? It depends on the writer!)

    Instead, you should use exceptions for exceptional circumstances. When exceptions are unhandled, they usually cause the termination of the application, which certainly makes you remember to check them. Their syntax is clear and you don’t litter your code with checks.

    You haven’t specified a language, so here’s a VB.NET example that divides a number:

    Function FloorDivide(ByVal a As Integer, ByVal b As Integer) As Integer
        Dim result As Boolean = a / b
    
        If Double.IsNaN(result) Then Throw New DivideByZeroException()
    
        Return CInt(Math.Floor(result))
    End Function
    

    You can use it without checking the success value, but you can still handle errors using Try...Catch statements:

    Try
        FloorDivide(1, 0)
    Catch ex As DivideByZeroException
        MessageBox.Show("Something went terribly wrong! :D")
        'Exit, maybe?
    End Try
    

    (Not that I’m saying you should guard against divide-by-zero in this way; filter your input!)

    If you do forget to make that check, you’ll soon be reminded in the testing phase instead of having your code silently fail. It’s also much cleaner, and the scope of a Try...Catch can be as large as you want, perhaps handling any error occurring in a particular error-prone method and throwing them away. Who knows?

    So, generally, use exceptions. If you find yourself planning to handle them, though, you need to do validation.

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

Sidebar

Related Questions

I have a simple question regarding best practices in programming. I have a DB
Yesterday, I asked this question regarding best practices for a simple information retrieval system
Simple question on best practice. Say I have: public class Product { public string
Ok so again my question is kind of a best practices/techniques question so I'm
Just a question about best-practices when upgrading an existing database. Assuming there will be
I have a question about best practices related to de-normalization or table hierarchy relationships.
I have a question about best practices regarding how one should approach storing complex
This is more of a best practices question. I have a few email templates,
I have a best practices/performance question. I am creating an ASP.NET MVC 2 project,
Pretty simple question. Its just some advice based on personal opinion and best practice.

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.