Off Topic > Off Topic

Programming Megathread

Pages: << < (126/241) > >>

McJob:


--- Quote from: Foxscotch on May 03, 2016, 03:56:06 PM ---why?
return 1 + 1 will work just as well as return(1 + 1)
I don't really care what you use, but you should keep it consistent...

--- End quote ---
In several instances I've had to convert input parameters into a different type. This is an example from an old project of mine that demonstrates it perfectly:


--- Code: ---    /// <summary>
    /// Returns a single Float value based on Inspector-style values. Minimum value is "0" and maximum value is "255".
    /// </summary>
    /// <param name="s">The single number to convert.</param>
    /// <returns></returns>
    public static float ConvertInspectorColours(int s)
    {
        return (float)s / 255.0f;
    }

--- End code ---

EDIT: I couldn't find the example where I've done return (type)(formula);, but there was an example where I was working ints and floats and it was necessary. I'll keep looking for it.
EDIT: Actually, rather disappointed at that function that I didn't do any input checking to handle cases below 0 and above 255...

Foxscotch:

that's different
what everyone is talking about right now is if you did it like this
return((float)s / 255.0f);
not just whether or not there are parentheses somewhere in return statement

anyway, I think using parentheses for the return statement makes it look like a function, so I don't like using them (or seeing them)

also, that comment looks like a huge hassle :<
I like sphinx's autodoc format for python
"""
Description of whatever you're documenting.

:param int size: Description of size parameter
:return: Description of return value
:rtype: str
"""
I don't really know why there's a separate rtype role, instead of just like, ":return str: Description" or something. but whatevs

Ravencroft·:

Ok I was able to figure the program out. I was approaching it all wrong, as I thought the SUM function had to go in the middle of MAIN when it had to be after MAIN. It also took me a bit of time to figure out how the variables recognize eachother as copies.

Final result:
http://codepaste.net/n4ob5w

Pecon:

You didn't actually use the SUM function anywhere, though?

Ravencroft·:


--- Quote from: Pecon on May 03, 2016, 08:16:44 PM ---You didn't actually use the SUM function anywhere, though?

--- End quote ---
How do I fix that?

Pages: << < (126/241) > >>

Go to full version