Thread: whats the next thing to learn

  1. #16
    Registered User
    Join Date
    May 2019
    Posts
    200
    First, polymorphism. When it was new (early in C++), it was the new toy everyone overused. I had programmers insist that every function should be virtual "just in case". It was a bad idea. Not that polymorphism was bad, but the "just in case" overuse when there was no plan to use polymorphism. You can do quite a lot without it.

    The classic classroom example is shapes. A base class, called shape, is itself a shape but has no shape. If used it would represent, at best, an invisible shape at some location. There would then be classes fashioned for triangles, circles, rectangles and various shapes one might want to draw, all derived from shape. Most particularly, in this classroom example, the draw function would be virtual. In a textbook fashion, the destructor of shape would be made virtual so the object destruction was complete (considered really bad to skip that step, but there are exceptions).

    The point here is that a container could be fashioned just to hold shapes. Imagine the difficulty of creating a container that can old all of the shape types. You'd be relegated to void pointers an casting, known to be a source of bugs. Instead, the container "knows" only the base type. It should store objects via pointer (suspicious in the early days), because an array of shape objects could not be coaxed into morphing into triangles, circles or the other derived types. Now, however, a draw function could merely loop through this container of shapes, and the virtual draw function of each shape would "automatically" choose the particular function in the derived object to draw the specific shape originally created. That is, a shape pointer would hold a "new triangle" or "new rectangle", but would only "know" those by the base class shape.

    That is the classic example, but I now show you a questionable yet common use case. In a rendering engine (games, CAD, whatever), one must contend with the various API types for drawing 3D graphics (OpenGL, DirectX, Vulkan, Metal, etc). One could fashion a base class renderer which doesn't care the specifics of the rendering API. It represents the common interface for drawing, configuring, etc. It would allow you to write a 3D graphics application which could, then, choose the rendering API at runtime. Indeed, many do this. It is questionable because in reality such applications are written specifically for an API by design (they're quite different from each other). However, there are some rendering engines which design their rendering class as a virtual base class, with derived specifics for each API they support, and the user can select which at runtime - usually at startup of the application. It is faster, however, to substitute the rendering API by FILES in the build, rather than by polymorphism. There is a small but measurable performance penalty for virtual function calls.

    With that questionable example, however, I do hasten to point out that when appropriate based on what you are modelling, polymorphism is a power mechanism.

    Now to your VB inquiry. Most of the good frameworks operate in a way that you've indicated. If you know the C level Windows API, you know it is a hassle to figure out which button fired a command. In most modern frameworks you can provide some kind of "pointer to function" paradigm, often using the std::bind library. Basically, you get "call this function if this button is clicked" convenience. This is true of WxWidgets and Qt, both of which I can recommend, though I'm partial to WxWidgets myself.

    So, since your question ended with "...this the same for c gui?" - I'd say, C++ GUI frameworks, not C. The Microsoft MFC framework, however, is no longer a good example. Qt & WxWidgets allow you to target MAC, Windows a Linux from a single body of code. MFC only targets Windows, and is still very much like the C API (they called it a thin wrapper, and it never was much leverage).

    GUI's operate on messages. These are merely numeric packages of data, which indicate the nature of the message and some parameters for it, like the mouse location or the Window ID. Modern interface techniques allow you to define responses to OS messages from the GUI with a "std::bind" style approach, that is an encapsulation of a pointer to a function. There will be a declarative section at the initialization of a window where the programmer lists all of the messages of interest and the functions to be called when they fire. The GUI framework unpacks the parameters into a comfortable representation (they are typically packed into two variables one must "bit fiddle" into something meaningful, in C). This means if you want the LButtonDown message from the mouse (anywhere on a custom display, for example), what you get isn't LPARAM and WPARAM that you must crack into pieces, you get the X, Y location of the mouse at the time the button was pressed (or released), routed to whatever object (usually a window, but not always) that should receive the message. That sounds trivial, but compared to what must be done in MFC or a C style application for Windows, it is wonderfully effective and simple.

    Also, as part of your question, you bring up "MsgBox("Hello")", and there, too, the frameworks offer rather simple creations for such purposes. There are classes to create frame windows, toolbars, client windows, controls of all types (including tabbed 'pages', tree controls, list controls with headings, etc). The raw C method for doing these things is daunting. The GUI frameworks make these tasks nearly trivial (well, some of them).
    Last edited by Niccolo; 05-31-2019 at 07:24 PM.

  2. #17
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,850
    Personally I use C# and WPF for anything UI based - This is because I target Windows 10.

    I never bothered learning C++ - I'll do it if I need it.

    If you wanted to do GUI programming I suggest that you don't use C: There is ways of doing it, but what will take you weeks will take seconds with, say, C#.
    I once went through this tutorial theForger's Win32 API Tutorial - It was interesting, but not very useful in the real world. You're better off with C#, VB.NET, Python, ...


    I suggest that you continue learning things with C - You've come a long way, and it would be a shame to leave it when you are just starting to walk through more advanced topics.

    Your next step is definitely double linked lists - This can then be used as a stepping stone for more things.


    When I got to the point that you were I asked a similar question - And of all people Salem suggested "C Unleashed" book by Lawrence Kirby and Richard Heathfield. It's an advanced book that covers so many advanced topics, like linked lists and b/trees...

    I bought it and read it cover to cover
    Fact - Beethoven wrote his first symphony in C

  3. #18
    Registered User
    Join Date
    Apr 2019
    Posts
    662
    i think the general advice is if i want to do gui stuff is forget c which i agree would be a shame as i have put a lot of effort into learning it. as i have said before my ultimate goal in all this is to program an arduino so i can use it in my classic car for things like courtesy light dimming lights on alarm etc etc. i know i can do each thing electronically with a couple of 555 chips for timing if need be however it would all be "fixed" with the appropriate resistors and capacitors and would require removal to change. where as if i used an arduino all i need do is plug the laptop in and away i go.

    before i do any of that though i want to learn what the hell im doing. i don't like all these "plug n play" type systems where you just tap in a few commands and it does all the heavy lifting its fine to start with but if something goes wrong your snookered.

    i will look for the book click here suggested and work my way through that.
    many thanks all
    coop

  4. #19
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,850
    Trust me when I say that you are already a better programmer than most Arduino uses!

    Arduino is not pure C - It has a little bit of C++. Nothing that you won't be able to handle.

    555 are a pain in the arse: always drifting with heat.

    I've recently got back into building some analogue circuits - I have been making a control for a servo that doesn't use any microcontrollers. I figured that I could probably do it in 30min with a PIC, but where is the challenge in that :P I made a ramp generator and fed it into a comparator for the PWM. It is very shaky, but I am slowly finding better ways to do it.

    I'd also recommend looking at other people's code on here and try to fix it. You'll get very good at finding faults which will help you debug your own code.

    For example, can you see the errors here...
    Code:
    scanf("%d", apple);
    
    if (checkForFail()) 
        goto fail;
        goto fail;
    
    for(i=0; i<MAX; i++);
    {
        buffer[i] = 0;
    } 
    
    if (grape = 0)
    {
        return -1;
    }

  5. #20
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,850
    Oh and here is a few FAQs
    comp.lang.c Frequently Asked Questions
    FAQ - Cprogramming.com

    They will help you answer questions by other people

  6. #21
    Registered User
    Join Date
    Apr 2019
    Posts
    662
    i would say the error was on line 1 no & (unless of course apple is a pointer) and no curley brackets on the if statement (line 3) and only one = in the if statement on line 12

    incidently on the book you recommended do you happen to know if its available to buy as an ebook

  7. #22
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,850
    Quote Originally Posted by cooper1200 View Post
    i would say the error was on line 1 no & (unless of course apple is a pointer) and no curley brackets on the if statement (line 3) and only one = in the if statement on line 12

    incidently on the book you recommended do you happen to know if its available to buy as an ebook
    You missed the error with the "for" statement :P

    That goto fail was a well known security bug: Have a look at this code from iOS -
    Reflections on Curly Braces - Apple's SSL Bug and What We Should Learn From It - codecentric AG Blog

    Here is one ebook - I'm sure that there is more...
    C Unleashed by Richard Heathfield (ebook)

  8. #23
    Old Fashioned
    Join Date
    Nov 2016
    Posts
    109
    Quote Originally Posted by Niccolo View Post
    The only other difference you can perceive is that the struct keyword was available in C, but of course there was no notion of private or public (everything was public) access, and, obviously, C had no member functions, constructors, destructors or operators.
    Wouldn't you say that defining static functions in a .c file and/or not placing function signatures/struct defs in .h files would make them "private?"

    I've always seen the ability to make things private as built-in to C but just not explicitly stated.

    Also, would you say that a struct could have member functions by means of containing an array or direct function pointers in the struct? One still must pass a reference to "self" but once that is passed, the self reference can operate on the struct's data of course.
    If I was homeless and jobless, I would take my laptop to a wifi source and write C for fun all day. It's the same thing I enjoy now!

  9. #24
    Registered User
    Join Date
    Apr 2019
    Posts
    65
    programming something new in itself is rewarding,math I find rewarding to combine with programming,from newbie that code a tiny program that do math calculation to very experienced find ways to optimise with math knowledge,make own math functions
    now getting experienced in C/C++
    How do you know when you are a Guru?
    When you can (code) C even blindfolded

  10. #25
    Registered User catacombs's Avatar
    Join Date
    May 2019
    Location
    /home/
    Posts
    71
    I always try to write a program that can make a task easier. I've rewritten a lot of scripts I wrote in Python as practice. One of them, for example, is a unit converter: I give it a starting unit (maybe 34km) and a miles flag, and the program converts it, all on the command line. It's pretty handy and saves me some time looking up the conversion online.

  11. #26
    Registered User
    Join Date
    Apr 2019
    Posts
    65
    Coop now I seen you spent much effort into tree's,so I was thinking suggest try Oct-tree too

    @catacombs, when I was a kid before I understood how programming a robot work,I wished for the paradox of having a robot that did my homework for me,but to program anything to do things for you,you need to first learn and understand your homework before be able to program it for example do homework with strings to translate your native language to a foreign language

    that is one of the advantages of programming,you get into trying problems from math,physics etc, using computer,that you shouldnt find so interesting doing as homework task,or in school without programming
    Last edited by I C everything; 06-13-2019 at 08:47 AM.
    How do you know when you are a Guru?
    When you can (code) C even blindfolded

  12. #27
    Registered User
    Join Date
    Jun 2019
    Posts
    4
    New here, Was OOP not necessary in c/c++?

  13. #28
    Registered User
    Join Date
    May 2019
    Posts
    200
    zalesG, sounds like a new thread worthy question, but first I'm not entirely sure what your question really is.

    C is not equipped to provide leverage in object oriented programming. C++ is, but C is basically still there in C++, so one could choose to avoid the leverage provided, which occasionally is even an optimization choice.

  14. #29
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,850
    It all depends on what you want to write programmes for...

    For anything PC related I use C#. For programming 8 bit microprocessors I use C.

    You'll need to work out what you want to do

  15. #30
    Registered User
    Join Date
    May 2012
    Location
    Arizona, USA
    Posts
    635
    Quote Originally Posted by zalesG View Post
    New here, Was OOP not necessary in c/c++?
    You can use OOP techniques in C, though it has to be done "manually". As one example, the stdio interface is OO--each method operates on a "FILE" object (either implicitly like "printf" or explicitly like "fprintf").

    As for the literal answer to your question, no, OOP is not necessary in C/C++. OOP is just a useful way to write software.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. I could learn a thing or to about Recursion
    By LAURENT* in forum C++ Programming
    Replies: 7
    Last Post: 11-21-2013, 09:36 AM
  2. Now whats wrong with this thing...
    By hubris in forum C++ Programming
    Replies: 5
    Last Post: 03-26-2011, 03:49 PM
  3. Replies: 7
    Last Post: 08-07-2007, 04:00 AM
  4. What's The Most Important Thing To Learn In C++?
    By DeanDemon in forum C++ Programming
    Replies: 3
    Last Post: 12-09-2002, 06:49 PM
  5. WHATS UP YALL....i want to learn
    By Unregistered in forum Game Programming
    Replies: 2
    Last Post: 02-23-2002, 04:20 PM

Tags for this Thread