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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T03:37:12+00:00 2026-06-14T03:37:12+00:00

I’m writting a C++ library for http clients. I don’t have much experience with

  • 0

I’m writting a C++ library for http clients. I don’t have much experience with programming, so please help me.

I have method named add. It gets two parameters. The first is name of type and second is parameter q. It is a number between 0 and 1 <0,1>. It should have 0 to 4 digits after dot.

I can write it but I don’t know what’s the better:

  1. void add(std::string type, double q) -> I must convert q to std::string in body of this method.

  2. void add(std::string type, std::string q) -> It’s ok, it’s faster but maybe less intuitive for user, because it’s a number (?)….

Is it a good idea, to have two methods: 1) and 2)?

Please help me. I don’t have an experience… I know that two of this methods works but what is better, more popular. What do You think? How would you write this?

  • 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-06-14T03:37:13+00:00Added an answer on June 14, 2026 at 3:37 am

    Normally you want to make it clear what is expected of the user simply by them taking a look at the method signature. Your code should provide helpful hits to the person who is using it (i.e. make it more obvious what your code is doing and what’s expected of them).

    Let’s start with the worst one:

    void add(std::string type, std::string q)
    
    • There is nothing making it clear that q is supposed to be a number.
    • q is not a very descriptive name.

    With the above example, the caller may get confused and call the method with reversed parameters: add("5.0123", "someType") There is nothing telling the user that they did something wrong, until the parameters have to be used. The worst part is that you don’t know where things will blow up now. This may result in some very difficult to track down bugs simply because the proper type wasn’t enforced.

    Slightly better:

    void add(std::string type, double q)
    
    • Now it’s clear that the user is adding a type and the double value of some sort.
    • q is still not a descriptive name

    I would recommend:

    void add(std::string type, double value)
    
    • Now it’s clear that the user is adding a type and the double value of some sort.
    • The parameter name of the double is now value (which is more descriptive than q).

    Now the user can’t call the method with the parameters out of order, i.e. add(5.0123, "someType"), as it would result in a compiler error. If it’s not obvious: it’s MUCH better to get a compiler error, because it can be fixed immediately. This way you’re making safer code from the ground up.

    This, of course, means that you’ll have to convert the double to a string, but for the most part it’s a small price to pay given all the benefits outlined above.

    I don’t know what the value represents, but the more closely you can name the parameter to the “real-world” entity it represents, the better it is.

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

Sidebar

Related Questions

I don't have much knowledge about the IPv6 protocol, so sorry if the question
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I have a small JavaScript validation script that validates inputs based on Regex. I
I have this code to decode numeric html entities to the UTF8 equivalent character.

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.