Notifications
Clear all

[Closed] MXS coding standards: fn vs function

I ALWAYS use fn.

After learning a little bit of dotnet, I realised a few years ago that my maxscript code was a mess. So I made some changes to make sure things were as consistent as possible. I camelCase everything, (function names and variables). I know some people like to PascalCase function names and camelCase variables but I cC both. I still feel my standards are sloppy compared to some but they are better than they were 5 years ago.

use the shortest one…

many c++ programmers coming in mxs coding bring a ‘c++’ styling. like
leaving left bracket on a line of code, or finishing a line with semi-colon, or using brackets in place where they are not necessary:

for k=1 to 10 do (
 	print("help");
 );

that’s ok, but it tells me that the maxscript is a foreign language for this coder.

http://www.scriptspot.com/bobo/ this is basically the reason why I use fn since I started doing Maxscript

Regarding standards and best practices, that was basically my talk at EUE this year. I will post the slides online Soon™!

not many of new mxs coders know what the semi-colon (“;”) was really designed for. many years ago mxs was not a language, it was a way to do something by using a command line commands.
it was used in the single line listener (probably no one is using it now and know where it is :)). the “;” gave a way to type several commands in one line:

select (box()); move $ [0,0,10]; scale $ [1,2,3]; converttomesh $  
 lo1

It’s not just ‘use the shortest one’, it should be ‘use the shortest one that’s readable’.

This is what my code looked like when I started:

if a==5 or a==2 then b=if c==3 then 4 else 2 else b=1

This is what my code looks like today:

if (a == 5 or a == 2) then
(
    b = if (c==3) then 4 else 2
)
else
(
    b = 1
)

As a result, I can barely read any tool I’ve written at the beginning. It looks like I tried to obfuscate it from myself.

1 Reply
(@denist)
Joined: 11 months ago

Posts: 0

i would write this code exactly the same. that’s what a standard is about.

ps. … not exatcly the same. i would write:

if (a == 2 or a == 5) then  

many c++ programmers coming in mxs coding bring a ‘c++’ styling. like
leaving left bracket on a line of code, or finishing a line with semi-colon, or using brackets in place where they are not necessary:

many c++ coders don’t use that ‘c++’ styling even when coding c++ I don’t like it, I don’t like the way it scans, the semi-colon thing at the end of every line whether it’s needed or not is because you like to keep in the habit of adding it so when you return to c/c++ you don’t start forgetting to add it where it is necessary.

1 Reply
(@denist)
Joined: 11 months ago

Posts: 0

i’m jumping all the time between c++, MXS, c#, Python, and MEL. sometimes i write on all five languages at the same day. would it be better for some habits to put semi-colon at the end of a python line as well?

 lo1

Only if you:
    also start indenting;
    MAXScript code;

they can all use “;” including Python which is a completely different case in many different ways as with no code block braces (which forces a certain formating on the code whether you like it or not )

i don’t want to say ‘this is right’ and ‘that is wrong’. i just like to know what the most popular mxs coding styles are now.
personally i don’t want to change my style. it’s too late.
it might look sometimes outmoded but i like to keep this vintage look
but for new mxs coders who are just begging the journey it might be good to know what the current practices are.

Page 2 / 4