2

I want to know the good practices when developing applications utilizing GWAN.

I have starter small app (but crucial part of big project) which will be utilizing C++ OOP. At least that means I have classes to get initialized on HTTP requests.

How I am supposed to structure the sources in order to use them in effective and practical manner while developing for GWAN? Do I have to develop the application separately and link it like a shared/static library? Or can I include them and GWAN do the build as it's doing for the scripts in the CSP folder? I found that if I put them in the CSP folder the result is failure to startup the server as it fails with error for missing main function in the cpp files which are holding classes implementations. Because of this I accepted that putting sources in CSP is not the way to do the work and there should only be initial script which will route all requests to the application.

Another thing which is related is that I am struggling to find out practical working environment to allow me to build and test faster in the case I'd have to build a library to be utilized trough CSP. Maybe I will create a way to test the app separately, however testing fast in GWAN environment is a non-visible solution for me at this time, which I believe is there.

The deployment of updated version of the APP under GWAN should happens as easy and fast as possible - what is the way? I do know that this question will likely clear by acknowledging answers to the above but let me leave it just in case I am very wrong with my current understandings on this whole topic.

kanevbgbe
  • 113
  • 5
  • 12

1 Answers1

2

The /csp directory should only contain entry point servlets - that is, a source code file with a main() that can be invoked by a remote client.

You can have functions (called from several servlets) in source code form (or in compiled form) placed in the /includes (.h) and /libraries directories (.c, *.obj, *.a, *.lib).

Quick development and testing can be done with a servlet used to test your code until it is mature enough to be stored in /includes or /libraries.

For huge projects, it makes a lot of sense to use pre-compiled libraries as this will speed-up on-the-fly servlet compilation (as compared to a large collection of include files).

Last but not least, G-WAN being designed for lean coding, C++ might not be as optimal as plain C for this purpose - just think of the hidden cost of constructors, their order, their sometimes redundant actions, hidden memory allocations, etc. - on the top of the huge C++ runtime overhead, high compilation times, blackbox standard libraries, etc.

At TWD, for Global-WAN (relying on G-WAN), we have spent quite a lot of time at rewritting C++ (non-standard) libraries in plain C, with very tangible gains in terms of performance, bug and deadlock cleanup, and memory usage.

What you don't see might hurt - and hurt badly because, well, you don't see it until it's too late.

Hope this helps.

Gil
  • 3,279
  • 1
  • 15
  • 25
  • Can you please make this clear to me - is it possible that GWAN to build sources (.h and .cpp) or each cpp will require `main()` function and if so I'd have to put them in `/includes`, I guess only .h will be supported and it's fine to have implementation in them? I will be able to check it tonight. This is the time when I will open the project and re-read your answer, after that I will come back to discuss again or accept the question/answer. Overall you are confirming my point of view. Thanks for the C lang information. I will invest time to try the minimum version of the APP in C and C++ – kanevbgbe Apr 30 '18 at 11:58
  • First, *.c files can be included from /includes just as *.h files. Second, *.c files can be used as libraries in the /libraries folder. Third, many (but not all) C++ programs cause concurrency (runtime-based) issues. Hidden memory allocations do (sbrk() lock) just as rand() and many other primitives but things get quickly nasty with large C++ libraries - that's why rewritting in plain C lets you discover and face these problems (far less of the code is hidden - and you can easily rewrite C standard library calls - an almost impossible task with C++). – Gil May 01 '18 at 11:53