Choosing programming language lazarus / 21-General ---------------------------------------------------------------------- amir.eng · 2023-06-13 11:06 Hello everyone, I have been working C# programming language for many years, actually my first programming language was C# .Net, In two recent years that I have known Lazarus, I designed some softwares with it (Lazarus)  because of Native forms, Standard DLLs or code's safety. In my new project which will be involved "Cad tools", "Database", "advanced reports", I've decided to design it with Lazarus but as you know "QT C++" is so popular and powerful nowadays . In fact I have a few exprience with QT, in this respect I'm curios to know your advice and comments about : - In terms of speed of codes which one is fast ? Lazarus or C++ ? - GUI and Native forms are so important in my program, which one do you prefer ? ---------------------------------------------------------------------- VisualLab · 2023-06-13 17:18 Quote from: amir.eng on June 13, 2023, 01:06:48 pm- In terms of speed of codes which one is fast ? Lazarus or C++ ? Lazarus is not a programming language, but a RAD IDE. Its programming language is ObjectPascal. So if you want to compare Lazarus, compare it with: - Visual Studio - behemoth-sized commercial RAD from Microsoft, for C++ (not RAD!), C#, VisualBasic, - Qt Creator - commercial (and limited open source) RAD from Qt for C++, - C++ Builder - commercial RAD from Embarcadero for C++, - Delphi - commercial RAD from Embarcadero for Object Pascal, - Lazarus - open source RAD for Object Pascal, - NetBeans - open source RAD for Java. Quote from: amir.eng on June 13, 2023, 01:06:48 pm- GUI and Native forms are so important in my program, which one do you prefer ? If you want native ones (i.e. those that generate machine code and not byte-code), then you have: - C++ Builder (C++), - Qt Creator (C++), - Delphi (Object Pascal), - Lazarus (Object Pascal). C++Builder and Delphi are built on common foundations (but they also have differences due to programming languages). I have been using Delphi for many years (since 1999) and it is very convenient. I've been using Lazarus less than Delphi. It doesn't have the convenience of working like in Delphi, but it's comfortable enough. In any case, it beats the open source IDE available for C++ or Java. In my opinion, Delphi (and C++ Builder) and Lazarus are a bit more convenient than Qt Creator (but the difference is not so big, and it's probably also a matter of how often you use it). Visual Studio for C++ is just a powerful IDE, not RAD. ---------------------------------------------------------------------- Thaddy · 2023-06-13 18:55 A real programmer just chooses the programming language for the job at hand. Programming may be a profession, a programming language is just a tool. professionals and interested amateurs therefor are proficient in more than one language. If you know how to program, the language does not matter too much. Abstact away any language dependency and when you know how to solve a job THEN choose the language, ---------------------------------------------------------------------- Peter H · 2023-06-14 10:16 Quote from: amir.eng on June 13, 2023, 01:06:48 pm- In terms of speed of codes which one is fast ? Lazarus or C++ ? - GUI and Native forms are so important in my program, which one do you prefer ? I did a quick and unscientific comparison of FPC, Delphi and CLANG. Consider this code: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i function crossSum1(n: integer): integer;//Optimized version, which avoids one divisionvar  n2: integer;begin  Result := 0;  while n > 0 do  begin  n2 := n;    n := n div 10;    Inc(Result, n2 - n * 10);  end;end; function crossSum2(n: integer): integer;//Non optimized version, but easier to code and easier to read//It does the same division twice.begin  Result := 0;  while n > 0 do  begin    Inc(Result, n mod 10);    n := n div 10;  end;end;   In the non-optimized version, (compiled with -O1) FPC was the fastest. However, if the equivalent CLANG code is optimized with -O3, then it will eliminate the double division from the routine "CrossSum2". With CLANG and -O3 both routines are equally fast. Neither FPC nor Delphi can do this. Then however, the correspondence between source and machine code is lost. You cannot singlestep it in the debugger, or if you do, it will be very confusing. The routine "CrossSum1" was equally fast in C++ and in FPC, because it is coded in an optimized way. Delphi was with this test code the slowest. It could not reach FPC or C++ speed. ---------------------------------------------------------------------- SymbolicFrank · 2023-06-14 11:53 Generally, 1% of your code takes 99% of the CPU cycles. Sometimes it's just a single loop, more often it's a few different actions, spread throughout the code. And most of the time, that code is waiting on something external, like the GPU, a socket or a disk drive. So, speeding your program up is normally a question of finding the bottlenecks and coming up with an alternative way to handle them. It is rare that processing power is the bottleneck. ---------------------------------------------------------------------- Peter H · 2023-06-14 13:45 Yes, this is true for interactive code (GUI code) or code which reads data from slower devices and must wait for them. Not so for number chrunshing, equation solving, FFT, AI, image processing, Graphics and so on. Edit: It should be added, FPC and Delphi are MUCH faster than script languages, and unlike these have full access to the OS API. It is however nearby equally comfortable and easy to use. A Beginner or casual programmer with some solid basic knowledge can write impressive programs. Unfortunately Delphi is too expensive for casual use. ;-) ---------------------------------------------------------------------- Warfley · 2023-06-14 13:59 First on a general note, I quite like C++, algorithmicly it has a lot of really nice features (the containers and algorithm library of the STL are really good and one of the major things I find lacking in pascal), and I also have used QT creator in the past, and we'll... It works, but convince looks different to me. Personally I wouldn't write any GUI application in C++ if not necessary. About performance, C++ allows you to easier write efficient code than Pascal does. It also allows the programmer to give more hints in the code that can be used by the optimizer. e.g. C++ has references which are like pointers but can't be null and are unchangeable during their lifetime, making them better optimizable than regular pointer that may be changed or nulled at any time. Another great example is in the RTL, as well as in the C++ STL many functionality is part of classes, but while c++ classes are located on the stack and often the class structure will be completely optimized away by the compiler, fpc classes live on the heap, require always (really slow) memory allocations and have a lot of virtual methods that cannot be easiely inlined. That said, you often just need to optimize your hot paths through the application (unless you write massive batch jobs), and then you can manually optimize your code which while being less convenient in Pascal is still possible (in the end you can even just use ASM). With your example above, have you tried the LLVM backend for fpc? You can get a lot of the optimizations you get with clang also for fpc through the usage of the same LLVM backend. I haven't used it in quite a while (last time it was still considered very early in development) but this may give you results closer to what clang spits out ---------------------------------------------------------------------- SymbolicFrank · 2023-06-15 07:24 Quote from: Peter H on June 14, 2023, 03:45:51 pmYes, this is true for interactive code (GUI code) or code which reads data from slower devices and must wait for them. Not so for number chrunshing, equation solving, FFT, AI, image processing, Graphics and so on. Generally, it's much faster to run all those things on a GPU. Then again, not all GPUs are created equal, but that goes for the CPU as well. Most modern CPUs have one or more vector/SIMD unit(s) to speed such things up. In most other cases, using DMA and threads can speed things up. Again, the maximum amount of threads depends on the CPU. And it's hard to do, because you have to avoid sharing memory and other resources. Compared to those things, the improvement a faster compiler brings are rather small. ---------------------------------------------------------------------- SymbolicFrank · 2023-06-15 07:28 Quote from: Warfley on June 14, 2023, 03:59:12 pmFirst on a general note, I quite like C++, algorithmicly it has a lot of really nice features (the containers and algorithm library of the STL are really good and one of the major things I find lacking in pascal), and I also have used QT creator in the past, and we'll... It works, but convince looks different to me. Personally I wouldn't write any GUI application in C++ if not necessary. About performance, C++ allows you to easier write efficient code than Pascal does. It also allows the programmer to give more hints in the code that can be used by the optimizer. e.g. C++ has references which are like pointers but can't be null and are unchangeable during their lifetime, making them better optimizable than regular pointer that may be changed or nulled at any time. Another great example is in the RTL, as well as in the C++ STL many functionality is part of classes, but while c++ classes are located on the stack and often the class structure will be completely optimized away by the compiler, fpc classes live on the heap, require always (really slow) memory allocations and have a lot of virtual methods that cannot be easiely inlined. That said, you often just need to optimize your hot paths through the application (unless you write massive batch jobs), and then you can manually optimize your code which while being less convenient in Pascal is still possible (in the end you can even just use ASM). With your example above, have you tried the LLVM backend for fpc? You can get a lot of the optimizations you get with clang also for fpc through the usage of the same LLVM backend. I haven't used it in quite a while (last time it was still considered very early in development) but this may give you results closer to what clang spits out Then again, C++ has no finalizers. If you use exceptions, memory leaks are unavoidable. And while everything goes in C++, the trick is in learning what not to do. Although the latest version is better with that. But the code is still context sensitive, if you use macros and templates. It's my least favorite programming language because of those things. ---------------------------------------------------------------------- mercurhyo · 2023-06-15 07:55 Quote from: amir.eng on June 13, 2023, 01:06:48 pm but as you know "QT C++" is so popular and powerful nowadays . hmm my 2 cents here. I believe that if someone chooses/evaluates tools with "popularity" and not efficiency, then this someone is a kind newbie. That said, if you aren't a "newbie" you can afford to build projects with the tool of YOUR choice, using the "no newbies' tricks" of THAT tool and be as competitive as others. So, to me, such a post trying to compare a bottle with another is sort of nonsense I call such Posts "trolls engines". my bad  *smartass mode off* cheers ---------------------------------------------------------------------- Warfley · 2023-06-15 08:19 Quote from: SymbolicFrank on June 15, 2023, 09:28:51 amThen again, C++ has no finalizers. If you use exceptions, memory leaks are unavoidable. And while everything goes in C++, the trick is in learning what not to do. Although the latest version is better with that. But the code is still context sensitive, if you use macros and templates. It's my least favorite programming language because of those things. Thats actually a common misconception from people new to C++. Yes C++ has no try-finally, but thats because it have destructors which take over this job. They are also effectively more powerful than try- finally, because you can simply emulate try-finally with them and a simple macro: Code: C  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i #include  #define begin_try_finally {struct __try_finally_helper_t{ \      ~__try_finally_helper_t()#define finally void operator()()#define end_try_finally } __try_finally_helper; \    __try_finally_helper(); \    } int main() {    begin_try_finally {      std::cout << "Try Block\n";        std::string("abc").substr(10); // will throw an out of range error    } finally {        std::cout << "Finally Block\n";    } end_try_finally    return 0;}As you can see the finally block will be executed when the exception is raised. C++ is not Pascal, it's a different language, and while you can emulate pascal behavior (as you see above), you won't see any of that in any production code. What you see instead is the use of C++ classes directly whose destructor does the cleanup. For example a FileStream that must close the file: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i fs := TFileStream.Create(FileName, fmOpenWrite);try  fs.WriteByte(42);finally  fs.Free; // Does not just free memory, but also closes the fileend;In C++ uses the destructor: Code: C  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i { // Scope for fs  std::ofstream fs(filename)  fs << 42;}As you can see I encapsulated it in its own scope (the { }) because at the end of each scope all variables of that scope will be finalized. This means as soon as } is hit, or an exception is raised, the destructor of fs will be called, closing the filestream. Because you mentioned memory leaks, this can also be done using std::uniqueptr: Pascal Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i var  p: PInteger;...New(p);try  p^ := 42;  // Exception can be raised herefinally  Dispose(p);end;C++: Code: C  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i { // Again scope to limit lifetime  std::unique_ptr p = std::make_unique();  *p = 42;  // Exception can be raised here} You don't need try-finally in C++ because you have destructors, which are always called, whether there is an exception, a return, continue or break. ---------------------------------------------------------------------- mercurhyo · 2023-06-15 08:23 have a nice Trap  dear trolls ---------------------------------------------------------------------- SymbolicFrank · 2023-06-15 08:30 @Warfley: Yes, that's why effective programming in C++ requires that you know al the "don'ts" and how to fix them with Black Magic (the stuff you didn't learn with "C++ programming for dummies"). And it makes your program unreadable. ---------------------------------------------------------------------- Warfley · 2023-06-15 08:38 Quote from: SymbolicFrank on June 15, 2023, 10:30:25 am@Warfley: Yes, that's why effective programming in C++ requires that you know al the "don'ts" and how to fix them with Black Magic (the stuff you didn't learn with "C++ programming for dummies"). And it makes your program unreadable. But isn't that the same with Pascal? It's not like using try-finally is something natural, you must also learn that. In C++ you need to know how scoping works, while in Pascal you need to know how try- finally works. It's quite analogous. And I contest that this: Code: C  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i     {      std::ofstream fs(filename)      fs.write(data, sizeof(data));    }is less readable than this: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i     fs := TFileStream.Create(FileName, fmOpenWrite);    try      fs.Write(Data, SizeOf(data);    finally      fs.Free;    end;Maybe to you the second is more readable, but I would say thats because you are a pascal programmer. Someone who is completely new to both languages, will not know what this weird scope in C++ does, but they will also not know what try-finally-end does. Hell there are still people in this forum using Pascal for years who misunderstand try-finally and believe it's only because of exceptions. Both languages have their tricks to learn. C++ has a lot of stuff thats hard to understand, but I would argue that scoping and destructors makes more intuitive sense than try-finally-free, because destructors allow to simply throw the objects away, meaning you have less to think about. ---------------------------------------------------------------------- mercurhyo · 2023-06-15 08:38 @SymbolicFrank +10 if we were on a C++ forum LoOoL ---------------------------------------------------------------------- mercurhyo · 2023-06-15 08:48 @Warfley exceptions blocks in pascal directly rely/descent from setjump and longjump invented in the 85-90 years https://www.freepascal.org/docs-html/rtl/system/setjmp.html knowing that, and havng to work it out in these heroic years would have avoid your current headache hahahaha ---------------------------------------------------------------------- SymbolicFrank · 2023-06-15 09:17 Quote from: Warfley on June 15, 2023, 10:38:21 amMaybe to you the second is more readable, but I would say thats because you are a pascal programmer. Unfortunately, I wrote more commercial software in C++ then in ObjectPascal. And you can make everything readable with macros that are hard to understand themselves. That's why John Carmack didn't like STD and Boost: he complained that sometimes he had to press "next" in the debugger for more than 50 times, while the cursor stayed on the same line and the next macro was expanded. ---------------------------------------------------------------------- Warfley · 2023-06-15 09:37 It's not macros it's template programming, but yeah this is one of the major issues I also have with the STL, that the source is not really understandable for new programmers. Just as an example this is the source for std::make_unique in LLVM: Code: C  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i template inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 typename __unique_if<_Tp>::__unique_singlemake_unique(_Args&&... __args) {  return unique_ptr<_Tp>(new _Tp(_VSTD::forward<_Args>(__args)...));} The reason for this is that to get the maximum possible performance the STL is mostly header only, with template programming to resolve as much as possible during compiletime. This has the effect that C++ programs using the STL produce very efficient and fast code, but on the downside, looking at this stuff makes your head spin, and all does is basically just call the constructors. That said, I think looking inside the types you use is something that you actually shouldn't do in C++, because C++ is a standardized language, so you should only rely on the information of the standard and not on the implementation used. Otherwise you may rely on undefined behavior that does not translate between different compiler (versions). E.g. std::set could be an AVL tree, an RBT or literal magic, for you as the programmer that shouldn't matter, all that matters is what is written in the standard. And when you follow this line of thinking you can write actually really simple and readable code in C++. Sure if you look inside the definition of the STL classes and functions it gets really complicated, but you don't need to, you must just assume that they do what the standard says it does. That said, when you have a shared codebase with different levels of experience between the programmers, it can get really messy, because while you can write really simple C++ code, an advanced C++ programmer can write really unintuitive code, that then the others may not understand. For C++ you must give yourself constraints. C++ can do nearly anything, and no matter what you are tying to do there is probably a really slim, easy or efficient way for doing that in C++, in a way that is not possible in other languages. But that does not mean that you should do everything at once. My top 3 favourite imperative languages are actually Pascal, C++ and Java, C++ because it allows so much that you can very quickly archive a goal and still write very efficient code (and just reasoning about and finding the best solution can be really fun). Java because it is so simple in it's feature set that there is barely anything you can do wrong, and it hasn't changed to much over the past few years, and Pascal because it is quite a unique in-between between a high level language like java and a low level language like C, allowing you to experiment on all ranges of abstraction. ---------------------------------------------------------------------- VisualLab · 2023-06-15 10:34 Quote from: SymbolicFrank on June 15, 2023, 10:30:25 am@Warfley: Yes, that's why effective programming in C++ requires that you know al the "don'ts" and how to fix them with Black Magic (the stuff you didn't learn with "C++ programming for dummies"). And it makes your program unreadable. Something for something. Some programmers praise such "advanced" automation. Others swear at it, call it "black magic" and prefer to write more readable code (although it is a matter of convention what is readable and what is not). Notable critics include Torvalds saying that C++ "does too many tricks behind the scenes". A matter of choice. Unfortunately, in addition to the useful things, C++ has a lot of different nasty features. Many of these "automations" are based on juggling code as plain text (macros). A good example is the Qt library. Macros may have been useful in the 1970-1980s. But more than 40 years have passed since then! It's as if people were insisting that various variants of horse-drawn carriages are still widely used today instead of cars. Yes, it can be done, because the old technology still works. But something more efficient and more convenient is definitely needed. ---------------------------------------------------------------------- SymbolicFrank · 2023-06-15 10:40 Java is fine for classes and threads, but things like not having unsigned integers and that everything has to be a class makes it hard to write tools and low-level stuff. In that sense, it's the opposite of C++  I think that the programming language I used most is probably C (the old-fashioned kind, where everything is a pointer). It's hard to express complex concepts and data structures in that. It's ok-ish for micro-controllers, but they almost always have an extension for bit manipulation. And strings are best done yourself. But overall, it's quite straightforward and easy to understand. The trick is in encapsulating stuff. And I'm not convinced that C++ has that nailed down. That also uses a different syntax for each extension. C++ Builder was an interesting, and very usable variant, albeit sometimes with a strange syntax and never really finished. It didn't work very well without the accompanying Delphi, for the classes and tools. But it did allow C++ RAD. The first versions of C# were just like Java, where you didn't even had 8-bit ASCII. Very hard to write network libraries with that. And things like Windows Communication and Presentation Foundation weren't improvements. Especially WPF was a major pain. .NET Core is about what it should have been from the start. So, overall, a very useful programming language (and environment), if you can ignore all the cruft. But the amount of general purpose programming languages isn't that large. There's only a handful. Or, put differently: there are very many of those, but the usability is mostly severely limited. It's not the language that makes or breaks it, but the libraries and the flexibility in which you can integrate them. Yet another thing where C++ scores quite badly. On the one hand, it's really great with Linux or MacOS, that the SDK has header files for just about everything, and that there is a lot of source as well. But on the other hand, it's really hard to get the right versions of all the dependencies of any C++ project. So, in short: FPS + Lazarus are great because of all the easy to use libraries and components, the centralized development and the community. Much of those libraries might not be finished, but they're very usable and the community can help you add the missing bits. ---------------------------------------------------------------------- Warfley · 2023-06-15 11:08 Quote from: SymbolicFrank on June 15, 2023, 12:40:35 pmJava is fine for classes and threads, but things like not having unsigned integers and that everything has to be a class makes it hard to write tools and low-level stuff. In that sense, it's the opposite of C++  I think that the programming language I used most is probably C (the old-fashioned kind, where everything is a pointer). It's hard to express complex concepts and data structures in that. It's ok-ish for micro-controllers, but they almost always have an extension for bit manipulation. And strings are best done yourself. But overall, it's quite straightforward and easy to understand. The trick is in encapsulating stuff. And I'm not convinced that C++ has that nailed down. That also uses a different syntax for each extension.This simplicity of Java is what I really like about it, there are classes and a hand full of atomic datatypes and thats it. While in C++ and to a certain extend also Pascal (and modern day C#) you always think whats the best way to do something, in Java, there ususally is just one way. This strangely lets you focus on the macroscopic flow of the program rather than having to think about how to do each step individually. This is also quite similar in C, but where Java just allows for a few high level concepts, C just allows for a few low level constructs, with which you have to do everything. So similarly you often not think whats the best way to do something, but more on whats the way to do something at all. In that regard C is a bit like Java, just if you would constantly get whiped while typing because C hates you. Quote from: SymbolicFrank on June 15, 2023, 12:40:35 pmC++ Builder was an interesting, and very usable variant, albeit sometimes with a strange syntax and never really finished. It didn't work very well without the accompanying Delphi, for the classes and tools. But it did allow C++ RAD. I think also the .Net C++ variant from Visual Studio is quite interesting, because it also gives you a RAD C++ environment. That said, I think due to the rather high feature space of C++, it simply does not fit well for RAD development. The reason why GUI development in .Net or Lazarus is so good is because all the types are classes which are just pointers forming a tree structure, that is automatically managed (through GC in .Net and Owners in Lazarus). When you go to C++ and you start thinking: do I create this on the stack, as a shared or unique pointer, etc. you are soon at the point where you aren't just clicking things together, but every single step on the way must be thought through with all it's implications. This is why the .Net C++ RAD environment also made all the components be heap allocated classes. The thing is, that this makes the C++ developers unhappy that, because it artifically restricts and barrs all the features the language could provide, but you can't use. If you want to automate processes, what RAD does to a certain extend, you are limiting yourself to the capabilities of that automation process, and then you can ask yourself the question, if I have to write code like it's C#, whats the reason for using C++ instead of C#. About C#, I've never been a big fan of .Net. Visual Basic was actually the first language I learned (I had contact with Delphi before, but never really started learning it), and it was great for starting with programming, because you can quickly get something that works, and it is really tolerant of bad programming, but when I then later learned Pascal I for the first time had the feeling of actually learning on how a computer actually works due to it being low level while also providing high level constructs making it easy to still get things done. This is why I still believe that it's a great language for beginners. With modern C# I must say it's like Java desperately trying to not be Java. It has the same "everythings a class" design and all the same limitations that come with that, but tries with new and fancy language features to hide it. And I don't like languages trying to hide their inherent limitations ---------------------------------------------------------------------- VisualLab · 2023-06-15 11:13 Quote from: Warfley on June 15, 2023, 11:37:53 amIt's not macros it's template programming, but yeah this is one of the major issues I also have with the STL, that the source is not really understandable for new programmers. Just as an example this is the source for std::make_unique in LLVM: Code: C  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i template inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 typename __unique_if<_Tp>::__unique_singlemake_unique(_Args&&... __args) {  return unique_ptr<_Tp>(new _Tp(_VSTD::forward<_Args>(__args)...));} First of all, this code is unreadable. Perhaps it would be more understandable if it wasn't based on oversimplified (primitive?) C syntax. If this continues, in another 10 years "advanced" C++ code will look like a mixture of Brainfuck and Malbolge Readability always loses when it competes against conciseness and high abstraction (both at the same time). Quote from: Warfley on June 15, 2023, 11:37:53 amE.g. std::set could be an AVL tree, an RBT or literal magic, for you as the programmer that shouldn't matter, all that matters is what is written in the standard. And when you follow this line of thinking you can write actually really simple and readable code in C++. Sure if you look inside the definition of the STL classes and functions it gets really complicated, but you don't need to, you must just assume that they do what the standard says it does. Either way, it's better to know how things work. ---------------------------------------------------------------------- Peter H · 2023-06-15 11:54 Quote from: Warfley on June 15, 2023, 11:37:53 amIt's not macros it's template programming, but yeah this is one of the major issues I also have with the STL, that the source is not really understandable for new programmers. Just as an example this is the source for std::make_unique in LLVM: Code: C  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i template inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 typename __unique_if<_Tp>::__unique_singlemake_unique(_Args&&... __args) {  return unique_ptr<_Tp>(new _Tp(_VSTD::forward<_Args>(__args)...));} First of all, this code is unreadable. Perhaps it would be more understandable if it wasn't based on oversimplified (primitive?) C syntax. If this continues, in another 10 years "advanced" C++ code will look like a mixture of Brainfuck and Malbolge The code of the STL is highly optimized and made by trained specialists and heavily peer reviewed and can use undocumented or proprietary Compiler features, so far I know. It requires knowledge of the compiler internals and is not meant as an example for normal programming. Only compiler specialists can write and read and fully understand such code. Somewhere on Youtube there is a 1 hour CPPCON conference video about it. ---------------------------------------------------------------------- Warfley · 2023-06-15 12:20 Quote from: VisualLab on June 15, 2023, 01:13:44 pmEither way, it's better to know how things work. Thats the thing about standardized programming languages, while of course it's interesting to know how something works (a typical exercise for many C++ developers is to write their own STL, for exampe I did once a subset for microcontrollers), you should never use that knowledge. The thing is C++ compiler developers do not consider backwards compatibility or other things not written in the standard, or documented as official language extensions from the compiler manufacturer and may break things. This is completely different in Quasi Standard langauges like Java or Delphi (and FreePascal), where how it is implemented is the defined behavior and any future version must be backwards compatible with that. The best example someone showed me once was with the following test for overflow: Code: C  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i int x;...if (x + 1 < x) {  print("Overflow Detected");} else {  x += 1;}On the machine this code was used int is a 32 bit 2nd complement integer. But thats not defined for int, int is actually defined by a minimum number range it must cover from -2^15+1..2^15-1. With neither over nor underflow being defined. So what did the optimizer do? It just saw adding a positive number, so a number that gets a positive number added can never get smaller, so the whole overflowdetection was optimized away, resulting in the code being optimized to: Code: C  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i int x;...x += 1;Note that since recently (C++17 or C++20) int was finally defined in the standard as 2nd complement with defined over and underflow, making this example not work anymore. In a standardized language like C++ you should never make any assumptions about how something works internally. This may change on different compiler versions, or even different compiler settings. Especially for C and C++ the optimizer is very aggressive and makes full use of undefined behavior as seen above, meaning you can't assume anything thats not written in the standard ---------------------------------------------------------------------- SymbolicFrank · 2023-06-15 12:35 The best compiler for x86(-64) is the Intel one, but only as long as the target CPU is produced by Intel. Not only has this widely been used as a benchmark, but also to learn how to generate the most optimized code. Would this be a useful feat for FPC? On the one hand, most software produced with it probably runs on one of those. On the other hand, in the long run, adding new platforms (especially micro-controllers) is almost certainly much better for the growth and/or survivability. I'll wager, that implementing the bit addressing extensions and on-board peripherals of ARM32 micro-controllers makes a bigger difference in the long run. ---------------------------------------------------------------------- PascalDragon · 2023-06-15 20:17 Quote from: mercurhyo on June 15, 2023, 10:48:55 amexceptions blocks in pascal directly rely/descent from setjump and longjump invented in the 85-90 years This depends on the used operating system. On Windows the SetJump/LongJump-based exception handling is no longer used as instead the operating system mechanisms are used (FS register based chain on i386-win32 and metadata in the PE binary on x86_64-win64 and aarch64-win64). Other operating systems simply have no other mechanisms than SetJump/LongJump and even GCC/Clang use that internally. Quote from: SymbolicFrank on June 15, 2023, 02:35:29 pmWould this be a useful feat for FPC? On the one hand, most software produced with it probably runs on one of those. I have no clue what you mean here. FPC can not use ICC. Also the world no longer circles solely around x86, as essentially all smartphones are ARM or Aarch64 and macOS systems are Aarch64 now as well. So while CPU-specific optimizations should be improved (and e.g. Kit is working on that for the x86 platforms), it's no longer only x86 that should be considered ---------------------------------------------------------------------- SymbolicFrank · 2023-06-15 21:16 Quote from: PascalDragon on June 15, 2023, 10:17:09 pmQuote from: SymbolicFrank on June 15, 2023, 02:35:29 pmWould this be a useful feat for FPC? On the one hand, most software produced with it probably runs on one of those. I have no clue what you mean here. FPC can not use ICC. Also the world no longer circles solely around x86, as essentially all smartphones are ARM or Aarch64 and macOS systems are Aarch64 now as well. So while CPU-specific optimizations should be improved (and e.g. Kit is working on that for the x86 platforms), it's no longer only x86 that should be considered Yes, that was my point. Trying to copy the Intel compiler just for the (smallish) improvements for Intel CPUs only is probably not worth it, especially because the rising star is ARM. ---------------------------------------------------------------------- Raf20076 · 2023-06-16 04:23 GOLDEN RULE IN PROGRAMMING What is better? A hammer or screwdriver? Tell me what do you want to do and I will tell you which you should choose. C#, C++, Python, ObjectPascal? What do you want to do? Database?Artificial Intelligence?To program microchip? THERE IS NO UNIVERSAL PROGRAMMING LANGUAGE FOR EVERYTHING YET ---------------------------------------------------------------------- Thaddy · 2023-06-16 12:21 Fully agree. See my previous post. ---------------------------------------------------------------------- Peter H · 2023-06-16 12:39 Now I think, the OP has declared what he wants in his initial post. However, Qt is VERY expensive if he doesnt want to go opensource and if he wants static linking. There is an option to get a small business license from Qt, which is much cheaper than Delphi. This is not promoted, but if you search for it, you find it. So far I remember, you must be below 100000$ revenue and they will check if you are entitled. He also said, he has used C# for years now. He could use Delphi Community instead, if he is below 5000$. Other alternatives: Stay with C#, he did not say why this is not sufficient. Its Windows only. If this is not sufficient he can use C++ CLI or a combination of C# and C++ CLI. Or Wxwidgets or Ultimate++. These are all RAD systems with their advantages and disadvantages. If he has some  money, he can use what he likes the most. ;-) ---------------------------------------------------------------------- Mr.Madguy · 2023-06-16 12:45 After trying to use C++ to make my universal Win-DOS project (as GCC has -nostartfiles -nodefaultlibs -nostdlib options to do it) I can say, that may be C++ is more powerful, but it's less friendly. Weird type system - int and long are the same, while it would be better for long to be "NativeInt". Being unable to use enumerable types as array indexes. I.e. const BoolToStr:array[boolean] as String = ['False', 'True'] isn't possible there. Typedefs are way too overcomplicated. Like function types for example. Types not being memory-compatible. Like being unable to assign arrays. Interface declaration isn't built-in. Some strange type conversion behavior. Like being unable to do (char*)Str+=1, when Str is void*. And many other similar things. P.S. And while Code::Blocks isn't better in comparison to Lazarus, I actually like how project groups and switchable configurations are implemented there. Yeah, this feature doesn't work well out of box, but after some tuning I was able to achieve Delphi-like quality of life. ---------------------------------------------------------------------- VisualLab · 2023-06-16 22:22 Quote from: Peter H on June 16, 2023, 02:39:42 pmNow I think, the OP has declared what he wants in his initial post. However, Qt is VERY expensive if he doesnt want to go opensource and if he wants static linking. There is an option to get a small business license from Qt, which is much cheaper than Delphi. This is not promoted, but if you search for it, you find it. So far I remember, you must be below 100000$ revenue and they will check if you are entitled. He also said, he has used C# for years now. He could use Delphi Community instead, if he is below 5000$. Other alternatives: Stay with C#, he did not say why this is not sufficient. Its Windows only. If this is not sufficient he can use C++ CLI or a combination of C# and C++ CLI. Or Wxwidgets or Ultimate++. These are all RAD systems with their advantages and disadvantages. If he has some  money, he can use what he likes the most. ;-) The comfort of working with C# in VisualStudio is higher than with C++ in Qt Creator. Both in terms of the language (Qt heavily uses macros and C++ quirks) and the IDE (here the differences are smaller in favor of VS). However, Delphi is more convenient than the two. Wxwidgets or Ultimate++ still do not provide such comfort of work as Visual Studio (C#), Qt Creator, Delphi or C++ Builder. The OP has clearly indicated that he wants native apps. And C++ CLI is .NET (or VM) though. Maybe he should try Delphi or Lazarus (after all, malicious languages say that C# is Object Pascal disguised as C++) so he should have no trouble learning the language. Differences in working with VS (C#) and Delphi are not big (designing forms, etc.). Or maybe use C++Builder. It's also RAD, very similar to Delphi (except for the programming language) and generates machine code, not byte code. ---------------------------------------------------------------------- amir.eng · 2023-06-23 09:53 Thank you all for replying and explanation, honestly some replies are specialized. I mean from QT was free version of QT c++ and not commericial version. I like Lazarus because it's free and simple and also for a great community with kind people , but I think it lacks of a big libreries in contrast to C++, for example there are LibreDWG or LibreOffice for C++, while I could find just SpreadSheet for Lazarus. Another issue with Lazarus, GUI is simple and not modern like QT, for example I'm willing to design ribbon tab like Autocad or Excel. C# is based on .Net, as I said at the first I have to provide a native app with modern GUI, while c++ CLR is not completely native. I haven't had any exprience with Java nad I'm not sure if java apps are native or not, I guess it has dependency like C#. ---------------------------------------------------------------------- Warfley · 2023-06-23 10:48 Quote from: amir.eng on June 23, 2023, 11:53:44 amI haven't had any exprience with Java nad I'm not sure if java apps are native or not, I guess it has dependency like C#. What do you mean with native? Because I read that statement as if you mean dependency free. In that case C++ with QT would not be native, because you are relying on the QT Library as a dependency. While you could consider QT to be native to linux, on windows this requires shipping QT with your application. For example looking at the installtion of KeePassXC on my Computer, it installed the following libs in it's installation folder: Code: Text  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Qt5Concurre nt.dll*Qt5Core.dll*Qt5Gui.dll*Qt5Network.dll*Qt5Svg.dll*Qt5Widgets.dll * If you are focusing on Windows on the other hand, .Net will be pre- installed (at least on modern windows machines), meaning even though C++ is "native" in the sense that it compiles to native machine code, and C# is a VM language, with C++ you require more external dependencies than with C#. On linux this is flipped, because QT is most often already pre installed as many linux applications require QT, your app will probably not need to ship anything in addition, but if you wanted to use C#, you would need to ship Xamarin Forms (Windows Forms are not implemented in Mono for C#). This is actually the strength of Lazarus, through the widgetset abstraction you can build your application to what is locally available, i.e. Win32 Forms API on Windows, Cocoa on Mac, QT or GTK on Linux. Quote from: amir.eng on June 23, 2023, 11:53:44 amAnother issue with Lazarus, GUI is simple and not modern like QT, for example I'm willing to design ribbon tab like Autocad or Excel. You are right that the default pallete for Lazarus is a bit old fashioned, and that the design system due to it's mapping to all those widgetsets can be a bit static sometimes. But you may take a look at BGRA Controls, which provide a bit more graphical UI elements, for example a Ribbon: https://raw.githubusercontent.com/bgrabitmap/bgracontrols/dev- bgracontrols/docs/img/bgraribbon.png And this completely native without external dependencies. ---------------------------------------------------------------------- metis · 2023-06-24 11:24 @amir.eng Quotewhile I could find just SpreadSheet for LazarusNot quite, see: https://forum.lazarus.freepascal.org/index.php/topic,63628.msg482225.h tml#msg482225 ---------------------------------------------------------------------- amir.eng · 2023-07-01 16:16 I created a test project and compiled an exe with QT 6.5, as a friend told that QT apps not completely native, it needs some DLLs to run, while Lazarus provide only an exe without any depencies. (idk which one is fast) I realized that we can improve Lazarus old UI to some degree with components. (not as much as QT)