Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. It's bad practice to use JS for my software logic? should I use C++ instead?

It's bad practice to use JS for my software logic? should I use C++ instead?

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
11 Posts 5 Posters 1.1k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    efdiloreto
    wrote on last edited by
    #1

    I'm starting to learn QML. At this time, I reached a point where I have to decide between C++ or JS to programming the "model" or "non UI logic" part of my application. This part will consist of some apis queries to obtain information in JSON format or similar. For example weather, google api, news, etc.

    This article discourages the use of JS for the code that is not part of the UI.

    I am more familiar with Javascript than with C++, so it would be more comfortable to use JS.

    If I choose to use JS, is it good practice to put the modules separately or could they be integrated with the QML code?

    I have no problem learning C ++, I just ask what are the recommendations or good practices that are usually followed.

    KroMignonK 1 Reply Last reply
    0
    • stackprogramerS Offline
      stackprogramerS Offline
      stackprogramer
      wrote on last edited by stackprogramer
      #2

      I only shared my QML experience. According your goal and situation , you should elect best option...For real time project only use C++, never use JS in your logic and conditional parts. For RAD develop application you can use JS, but you should consider that you will had a little delay. I developed a mini game (with JS and QML) named Qspiral 3 years ago, you can see it's video from this link.

      In windows, little delay didn't cause problem in playing game...
      but for cross platform in android we had crashes...
      Finally for android we had struggle on improve performance and reducing delay...So be careful in choosing the route.

      1 Reply Last reply
      1
      • E Offline
        E Offline
        efdiloreto
        wrote on last edited by
        #3

        Thanks for the response. My application will be a dashboard that will notify new emails, the weather and will be used on desktop.

        ODБOïO 1 Reply Last reply
        0
        • E efdiloreto

          Thanks for the response. My application will be a dashboard that will notify new emails, the weather and will be used on desktop.

          ODБOïO Offline
          ODБOïO Offline
          ODБOï
          wrote on last edited by
          #4

          @efdiloreto
          qmlweather example uses unly qml/js

          E 1 Reply Last reply
          0
          • E efdiloreto

            I'm starting to learn QML. At this time, I reached a point where I have to decide between C++ or JS to programming the "model" or "non UI logic" part of my application. This part will consist of some apis queries to obtain information in JSON format or similar. For example weather, google api, news, etc.

            This article discourages the use of JS for the code that is not part of the UI.

            I am more familiar with Javascript than with C++, so it would be more comfortable to use JS.

            If I choose to use JS, is it good practice to put the modules separately or could they be integrated with the QML code?

            I have no problem learning C ++, I just ask what are the recommendations or good practices that are usually followed.

            KroMignonK Offline
            KroMignonK Offline
            KroMignon
            wrote on last edited by
            #5

            @efdiloreto Hello and welcome to the Qt Community ;)

            My advice would be to reduce JS usage to strict minimum and to use C++ to implement business logic.
            I known that JS is an attractive language for beginners, but it is also a very error prone language. You will never know if don't have done typo errors until all the code has been executed and it is between 10 and 100 time slower as C++.
            I've learn it on the hard way, and I have rewritten big parts of my application to move JS logic to C++. This has solve many side effects, like memory management and performances issues.

            To resume my point of view:

            • if you want to do it right, use C++ to business logic,
            • if you want to do something in "quick&dirty style", try to chance with JS

            my 2 cts.

            It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

            1 Reply Last reply
            1
            • E Offline
              E Offline
              efdiloreto
              wrote on last edited by
              #6

              Thanks all for the responses. I will try with C++, I think it is a good opportunity to learn, even though the application can be easily resolved with JS.

              1 Reply Last reply
              0
              • fcarneyF Offline
                fcarneyF Offline
                fcarney
                wrote on last edited by
                #7

                @KroMignon said in It's bad practice to use JS for my software logic? should I use C++ instead?:

                10 and 100 time slower as C++

                Is this really true? Is there a benchmark for this? I looked at JSEngine and cannot tell if it is JIT compiled. I know a JIT compiled engine is not that much slower.

                C++ is a perfectly valid school of magic.

                ODБOïO KroMignonK 2 Replies Last reply
                0
                • fcarneyF fcarney

                  @KroMignon said in It's bad practice to use JS for my software logic? should I use C++ instead?:

                  10 and 100 time slower as C++

                  Is this really true? Is there a benchmark for this? I looked at JSEngine and cannot tell if it is JIT compiled. I know a JIT compiled engine is not that much slower.

                  ODБOïO Offline
                  ODБOïO Offline
                  ODБOï
                  wrote on last edited by
                  #8

                  @fcarney hi
                  Benchmarks:
                  https://woboq.com/blog/qml-vs-cpp-for-application-startup-time.html

                  1 Reply Last reply
                  1
                  • fcarneyF Offline
                    fcarneyF Offline
                    fcarney
                    wrote on last edited by
                    #9

                    @fcarney said in It's bad practice to use JS for my software logic? should I use C++ instead?:

                    cannot tell if it is JIT compiled

                    JIT Compiled?

                    C++ is a perfectly valid school of magic.

                    1 Reply Last reply
                    0
                    • fcarneyF fcarney

                      @KroMignon said in It's bad practice to use JS for my software logic? should I use C++ instead?:

                      10 and 100 time slower as C++

                      Is this really true? Is there a benchmark for this? I looked at JSEngine and cannot tell if it is JIT compiled. I know a JIT compiled engine is not that much slower.

                      KroMignonK Offline
                      KroMignonK Offline
                      KroMignon
                      wrote on last edited by
                      #10

                      @fcarney said in It's bad practice to use JS for my software logic? should I use C++ instead?:

                      Is this really true? Is there a benchmark for this? I looked at JSEngine and cannot tell if it is JIT compiled. I know a JIT compiled engine is not that much slower.

                      Yes, this is really true, according to my experience with QML/C++.
                      In fact, it was with Qt 5.4.2 and Qt 5.7.1, precompiled QML was not available at this time (at least not for open source licence version).

                      I do not tell you cannot do it with JS, I just share my experience. JS is a performance killer (execution time and memory usage).
                      For me, JS/QML should be used only to handle the user interface logic and C++ should be the "business logic" language.
                      This is also the recommendation from Qt, and interfacing QML and C++ is so easy to do!

                      It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

                      1 Reply Last reply
                      1
                      • ODБOïO ODБOï

                        @efdiloreto
                        qmlweather example uses unly qml/js

                        E Offline
                        E Offline
                        efdiloreto
                        wrote on last edited by
                        #11

                        @LeLev Yes, you're right. For make http requests I think that JS is enough.

                        1 Reply Last reply
                        0

                        • Login

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • Users
                        • Groups
                        • Search
                        • Get Qt Extensions
                        • Unsolved