Git Product home page Git Product logo

igor-pro-coding-conventions's People

Contributors

garados007 avatar michaelhuth avatar t-b avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

ryotako

igor-pro-coding-conventions's Issues

No user code before the first case in a switch statement

Igor Pro allows code before the first case in a switch statement but this code is never executed.

switch(i)
	print "this would never be executed", i
	case 1:
		print "one"
		break
endswitch

Similarly to #35, I would get rid of such code as it only confuses the reader.

Think about mandating wave types `Make`

It is pretty easy to choose the wrong wave type in IP as the default is FP32. Maybe it is worth always requiring that the wave type is specified? Think about that.

Correct evaluation of xop error codes

After some testing it turns out that the following way is working properly:

	variable err

	// for first loaded XOP -> xop error codes returned are in the range 10000+ upto max. 10999; error codes -1 to 9999 are Igor Pro error codes
	// for second+ loaded XOP -> xop error codes returned are offsetted by n x 0x10000 per XOP instead of 10000.
	// Therefore, returning the code through RTE and directly through V_flag (SetOperationReturnValue):
	err = err < 0xFFFF ? err : (err & 0xFFFF) + 10000
	// Note: Getting the error message through GetRTErrMessage, GetErrMessage(code) requires the original RTE code (does not work with directly return through  V_flag).

based partly on https://www.wavemetrics.com/forum/general/querying-xop-error-codes

Edited: Added (...) as + has higher precendence than &

No code outside of functions

Igor ignores all invalid code outside of functions and doesn't report this. I have seen many code examples of function or operation calls outside of functions like this:

Function Test(string a)
    print a
End

Test("this is never executed")
print "this is also never executed"

Function Test2()
End

I would suggest getting rid of such invalid code outside of functions, as it is ignored by Igor and only confuses the reader.

I think this is a known issue for WM, but they can't fix it because it would have a too big impact on their compiler.

Function definition

Should there be a ws directly after the function keyword?

Function /S customFunction()

or

Function/S customFunction()

Separate all operation arguments by commas

Igor Pro allows omitting the comma at certain argument positions for operations and does allow extraneous commas before the first argument. For example:

// omitting a comma
printf "x=%d, y=%d" 1, 2
sprintf msg, "x=%d, y=%d" 1, 2
// extraneous comma
printf , "text"

I would consider this as bad coding style and propose that all arguments must be separated by exactly one comma and no commas are allowed before or after the argument list.

printf "x=%d, y=%d", 1, 2
sprintf msg, "x=%d, y=%d", 1, 2
printf "text"

Impact

There is a large code base with lots of these coding style errors, so I wouldn't suggest reporting this to WM and fixing their compiler. I couldn't find any case for which fixing the comma leads to a compile error in Igor Pro.

Avoid generic routines like exists and use the specific ones

Window MMEdisplayWindow() : Graph

EndMacro

Function dostuff()

	string/g MMEdisplayWindow

	print exists("MMEdisplayWindow")
End

this does return 5 (macro) but if the macro is not present it returns 2 for the global string. Use the fainer grained functions instead.

Comma placement in function signatures

If the function signature contains required and optional arguments, Igor Pro does allow the following four cases of comma placement:

Function Case1(string reqArg, [string optArg])
Function Case2(string reqArg[, string optArg])
Function Case3(string reqArg [string optArg])
Function Case4(string reqArg, [, string optArg])

I would allow only case 1 as good coding style and also looks cleaner.

Impact

I have seen case 2 and case 3 in many different repositories, so I wouldn't report this to WM for compatibility reasons.

No code outside switch cases in GUI control procedures

commit 3e7306c621dce1dc5cb5dfa7dd52938d162e5551 (HEAD -> feature/add-remove-support-for-graphs-v2)
Author: Thomas Braun <[email protected]>
Date:   Tue Jul 14 21:52:50 2020 +0200

    Make GUI control procedures faster

    GUI control procedures can act on mouse over events. So the code outside
    the switch cases should be fast.

    But we had quite some cases where we started setting some variables.

    Move these into each case.

Require function prefixes for static and global functions

Thomas requested this in byte-physics/igortest#327 (comment) but I need more clarification:

  • Do we really want a function prefix for static functions as well? These are only accessible inside the module and therefore is no benefit using a function prefix. I support requiring a function prefix for global functions as they can clash with other user functions.
  • How do we determine the name of the function prefix? There should be a rule.

Currently, function prefixes are only mentioned once in the coding convention and that is that they may be used before the name of a function.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.