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

  • Home
  • SEARCH
  • 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 501103
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T06:09:19+00:00 2026-05-13T06:09:19+00:00

I have never seen this being done anywhere in all the source code i’ve

  • 0

I have never seen this being done anywhere in all the source code i’ve read in my life. If it is considered bad programming practice, there has to be a reason for it which i fail to understand. Also, I think it sometimes improves readability rather than worsening it. Here are a few places i’ve done it in my ruby code.

@pushButton.connect(SIGNAL :clicked) do (@select_file ||= Qt::FileDialog.new).show end

and

(tmr=Qt::Timer.new).connect SIGNAL :timeout do 
  @label.text = Qt::Application.translate("MainWindow", "The time right now is #{Time.now}", nil, Qt::Application::UnicodeUTF8)
end 
tmr.start(1000)
  • 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-13T06:09:19+00:00Added an answer on May 13, 2026 at 6:09 am

    It’s always a good idea to strive for simplicity wherever possible, and to that end it’s best to state things in a straightforward manner. Declarations like that make it hard to determine where variables originate as they’re embedded rather thoroughly inside the statement.

    Declaring scoped variables within brackets is usually considered acceptable:

    if (found = MyModel.find_by_pigeon_id(params[:pigeon_id]))
      # Variable 'found' used only within this block
    end
    
    # Ruby variables will persist here, but in many languages they are out of scope
    

    A more verbose version actually has implications:

    found = MyModel.find_by_pigeon_id(params[:pigeon_id])
    if (found)
      # Variable 'found' can be used here
    end
    
    # Implies 'found' may be used here for whatever reason
    

    It’s always nice to be able to scan up through the program and see, quite clearly, all the variables as they’re declared. Hiding things serves no purpose other than to frustrate people.

    Ruby is a lot more relaxed than many other languages in terms of how much you can get away with. Some languages will punish you severely for complicating things because a tiny mistake in declaration or casting can have enormous ramifications. That doesn’t mean you should take full advantage of that at every opportunity.

    Here’s how I’d advocate implementing your first example:

    # Ensure that @select_file is defined
    @select_file ||= Qt::FileDialog.new
    
    @pushButton.connect(SIGNAL(:clicked)) do
      # Block is split out into multiple lines for clarity
      @select_file.show
    end
    

    The second:

    # Simple declaration, variable name inherited from class name, not truncated
    timer = Qt::Timer.new
    
    timer.connect(SIGNAL(:timeout)) do 
      # Long parameter list is broken out into separate lines to make it clear
      # what the ordering is. Useful for identifying accidentally missing parameters.
      @label.text = Qt::Application.translate(
        "MainWindow",
        "The time right now is #{Time.now}",
        nil,
        Qt::Application::UnicodeUTF8
      )
    end
    
    timer.start(1000)
    

    I’ve found that the most complicated programs often look the simplest, as they’re written by people with lots of experience who know how to express things in a straightforward manner.

    Interestingly enough, some of the simplest programs are often the most complicated as they’re written by novices who are either grandstanding and showing off or are digging themselves into a deep ditch and keep throwing code at the problem in the hopes of fixing it.

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

Sidebar

Ask A Question

Stats

  • Questions 357k
  • Answers 357k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The other answers are correct. Here is some code you… May 14, 2026 at 9:40 am
  • Editorial Team
    Editorial Team added an answer you ruin the noConflict concept by reassigning the jquery to… May 14, 2026 at 9:40 am
  • Editorial Team
    Editorial Team added an answer If you get that particular error, you don't actually have… May 14, 2026 at 9:40 am

Related Questions

No related questions found

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.