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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T02:15:06+00:00 2026-05-31T02:15:06+00:00

Which of the following is more readable and preferable? This, where the default value

  • 0

Which of the following is more readable and preferable?

This, where the default value is assigned in the declaration:

    Dim isLastWeekOfPeriod As Boolean = False
    If periodInfo.WeekCount = weekInfo.Week Then
        isLastWeekOfPeriod = True
    End If

Or this, where the value is set in the else clause:

    Dim isLastWeekOfPeriod As Boolean
    If periodInfo.WeekCount = weekInfo.Week Then
        isLastWeekOfPeriod = True
    Else
        isLastWeekOfPeriod = False
    End If
  • 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-31T02:15:07+00:00Added an answer on May 31, 2026 at 2:15 am

    Neither.

    Write the assignment directly in the initialisation, don’t use If here at all:

    Dim isLastWeekOfPeriod As Boolean = (periodInfo.WeekCount = weekInfo.Week)
    

    The parentheses are not necessary but make the assignment-vs.-comparison more readable. By the way, with Option Infer On you can also safely remove the type name, it’s obvious from the initialisation expression and the variable name prefix is:

    Dim isLastWeekOfPeriod = (periodInfo.WeekCount = weekInfo.Week)
    

    Remember: Short is good (as long as it doesn’t negatively affect readability).

    Rationale

    Your first code is acceptable but it does more or less the same as my above code and has four times more lines of code, without any benefit whatsoever.

    The second code does the initialisation twice: once in the declaration, since every variable is implicitly default-initialised in VB (thus isLastWeekOfPeriod takes on the value False in the first line). And once in the conditional block after that. Oh, and finally this code is five times as long as mine.

    Furthermore, writing If a Then result = True Else result = False is always doing redundant work. There is no reason not just to write result = a directly.

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

Sidebar

Related Questions

Which of the following would be more efficient and better to use? value.replaceAll(['‘’`],) value.replaceAll(['‘’`]+,)
please help me to identify which of these following is more optimized code? for(int
I have following query which take more than a minute to execute, how can
I have the following problem: http://jsfiddle.net/DerNa/12/ Which is demonstrated more clearly the jump here:
I have the following code in a c++ listener class (more or less), which
Consider a typical social networking website, which has more or less the following models:
Out of curiousty which of the following code is more efficient (if neither, what
which of the following is more efficient? Using a get function on a token
Is is possible to convert following into a simpler more readable linq or lambda
I run into following code in my project: html: <input type=button id=addmore value=Add more

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.