Login Page - Create Account

Support Board


Date/Time: Sat, 01 Mar 2025 04:12:48 +0000



[Programming Help] - Code Organization Patterns

View Count: 475

[2021-09-17 16:53:34]
silvereagle - Posts: 23
Hello fellow engineers, Sierra and otherwise :)

It's been a long time since I coded in C++ but I'm getting back into the swing of things, kinda. I'm getting better at understanding sierra and the acs api, however, I've come to the point where having all the code in one file is just draining my productivity with all the scrolling and hunting and pecking. I've got visual studio up and running, and am able to build studies and debug by attaching the sierra chart process, however, I'm scratching my head on how best to organize my code to make life easier. Does anyone have a strategy for organizing their Sierra code? Perhaps breaking apart logical blocks or persistent variables into their own files (headers/cpps) to make the code more manageable than one big honkin' file?

I've read in a few places on the support board here where the sierra folks say, "just use one cpp file to make life easier." But there are two sides to the coin, 1. on one side, a single file makes things easier to build by having everything in one place, but 2. on the flip side, boy when it gets big is it a bugger to work with and I'd like to make things a little more manageable and maintainable. The more manageable and maintainable, the less bugs I will write.

Does anyone have any suggestions or a strategy on how they separate/organize their code into manageable files/chunks?

Much Thanks! :)
[2021-09-17 17:12:01]
ForgivingComputers.com - Posts: 1015
On big projects, I create header files that have all the repeatable stuff like declarations, inputs, and subgraphs. Then I use #INCLUDE to place a copy of the header file in each function that needs something from it. I don't think it creates any significant overhead if the compiler sees variables that aren't being used in the function. This also cuts down on errors, as there is only one place where these things are defined.

I also use Ctrl-Shift-F a lot in order to find all occurrences of a search string in the files. I often have Notepad++ open so I can use the same Ctrl-Shift-F to search through all files, *.cpp, *.h or both. Notepad++ also is better at replacing random strings, as VS wants it to be a defined name to do global replace. There may be an easier way, but I haven't found it.

To post a message in this thread, you need to log in with your Sierra Chart account:

Login

Login Page - Create Account