1. Hey! Guest! The 33rd GMC Jam will take place between May 23rd, 12:00 UTC (Friday noon) and May 27th, 12:00 UTC (Monday noon). Why not join in! Click here to find out more!
    Dismiss Notice

Discussion Renaming functions "string" -> "to_string" and "string_format" -> "to_string_format"""

Discussion in 'GameMaker Studio 2 Community Tech Support' started by xDGameStudios, May 17, 2019 at 11:28 AM.

Tags:
  1. xDGameStudios

    xDGameStudios Member

    Joined:
    Sep 15, 2016
    Posts:
    574
    Right now there are a couple of function naming conventions that are not working for me (wanted to read what you guys think on the matter).

    Code:
    string(number)
    takes a number and converts it to a string. Even though it seems logical to have the function be named "string" I do think the best option would be to have a "to_string(number)". This might not seem too obvious at first but makes sense when you look at the
    Code:
    string_format(val, tot, dec)
    function. This last one does exactly the same as the first but formats the result (decimal places and stuff). if you look to other naming conventions on GMS2 you see that
    Code:
    array_*
    functions are functions that are applied to arrays and
    Code:
    ds_list_*
    applies to lists (and so on), you get the point.
    So one would expect that string_format would apply to a string (and that is not true).

    Now imagine you want to actually make a function that formats strings like C# (String.Format()) there would be a name collision and you would need to name your function something less obvious.

    My alternative for naming conventions would be "to_string" (as a more general, convert number to string, convert arrays to string, maps to string, ....) or "num_to_string"
     
  2. TsukaYuriko

    TsukaYuriko Q&A Spawn Camper Forum Staff Moderator

    Joined:
    Apr 21, 2016
    Posts:
    1,253
    Just in case: You can already manually do this by writing a wrapper script which only calls the original function and passes the arguments on to it for functions, and with macros for variables/constants (probably also for functions, but syntax check might give you a suspicious look).

    While I agree that some stuff isn't named appropriately (game_save_id and *_secure_* family, I'm looking at you), at this point, it would be ill-advised to rename it. Doing so would break backwards compatibility for hundreds of thousands of projects.

    I wouldn't be opposed to adding aliases for these by default, though, similarly to how we already have both randomize and randomise. It would ease the transition from other engines and languages to GML as well as promoting consistency.
     
  3. YellowAfterlife

    YellowAfterlife ᴏɴʟɪɴᴇ ᴍᴜʟᴛɪᴘʟᴀʏᴇʀ Forum Staff Moderator

    Joined:
    Apr 21, 2016
    Posts:
    2,249
    GML uses somewhat AS3-styled names for conversion functions, where type_name(value) converts value to type_name (or throws an error). See real(_), int64(_), ptr(_), etc.
     
  4. stainedofmind

    stainedofmind Member

    Joined:
    Jun 20, 2016
    Posts:
    693
    You could just use macros to create aliases as well. I have one in all my projects to shorten "show_message" to just "msg".
     
  5. xDGameStudios

    xDGameStudios Member

    Joined:
    Sep 15, 2016
    Posts:
    574
    Got you there, and I understand it but.. when you get to
    Code:
    string_format()
    it really sounds like you are formatting a string and that is not the case.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice