sketchucation logo sketchucation
    • Login
    ⚠️ Attention | Having issues with Sketchucation Tools 5? Report Here

    Programming in C, C++ for Mac and Windows?

    Scheduled Pinned Locked Moved Developers' Forum
    51 Posts 9 Posters 8.4k Views 9 Watching
    Loading More Posts
    • 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.
    • C Offline
      Chris_at_Twilight
      last edited by

      Most of what I would add has been said already.
      I'm a proponent of C++. For me, it's a much more natural programming structure than C (being object oriented), but you should probably pick what you are more comfortable with. If you use a lot of modules and classes in Ruby, I think you'll find the transition to C++ much more logical, with namespaces, classes, etc.

      Visual Studio Express 2008 is great for windows machines. I've had years of experience with VS so I can't really say how easy it is to just jump into, but I think it's as easy as most other IDE or compile environments.

      As far as cross-platform, if you are planning on any kind of GUI, I strongly suggest a good cross-platform framework, like wxWidgets. Not only does it add tons of GUI support but there is a lot of stuff you may not think about being cross-platform, file io, networking, images, etc.
      But even with a cross-platform framework, switching from Win to Mac is rarely straightforward. Be prepared to make some specialization.

      Last, don't underestimate the garbage-collection issue. If you have a single C/C++ method in which you make many ruby calls:

      
      void my_method(VALUE something)
      {
          VALUE val_a = rb_funcall(something, rb_intern("blah_blah"), 0);
          VALUE val_b = rb_funcall(something, rb_intern("blah_blah2"), 0);
          VALUE val_c = rb_funcall(something, rb_intern("blah_blah3"), 0);
      
      

      At any point, ruby can "collect" and delete the ruby objects, regardless of whether you are still in your C method. Ruby doesn't know that you are still in the function you were in when you asked for the object. So if these are transforms, and you go to multiply val_c by val_a, you may very well find that val_a has been deleted before you even get to val_c. I suggest understanding how Ruby does it's mark-and-sweep garbage collection and work with it.

      http://www.TwilightRender.com

      1 Reply Last reply Reply Quote 0
      • AdamBA Offline
        AdamB
        last edited by

        FWIW I've used in anger most languages over the years and my problem with C++ has always been it gives you a ton of opportunities to really screw yourself over. I've seen it happen with inexperienced programmers countless times, so to that degree I'd suggest that sticking with C and keeping it simple is sound advice.

        @chris_at_twilight said:

        Last, don't underestimate the garbage-collection issue. If you have a single C/C++ method in which you make many ruby calls:

        +10000

        All the Ruby docs claim that the GC searches down your stack frame and ensures that anything referencing a Ruby VALUE will not be garbage collected. But my experience is that is simply not true.

        What is true, is that as long as you don't call Ruby functions, it cannot run its Garbage Collector. So grab your info from Ruby, turn it into C data and then process without any calls to Ruby and you'll be good. The moment you call Ruby, you run (as said above) the possibility of the GC running (I believe it actually gets run every 256 internal opcodes Ruby executes - scary huh!).

        Adam

        Developer of LightUp Click for website

        1 Reply Last reply Reply Quote 0
        • tbdT Offline
          tbd
          last edited by

          it all depends on how much time and brain power do you want to allocate to it πŸ˜‰

          for myself I always love that my first language learned was assembler (Z80 to be more exact), so I can easily understand what happens inside the CPU - be that x86 (Win and Mac) or ARM (iphone) and can debug at the lowest level.

          another advantage in learning C is that you can look inside Ruby source code and see where the problem in your code comes from.

          everyone has a favorite language and each one comes with pros and cons.

          in the end it is your decision anyway πŸ˜„ - so take a look on all and see what fits you better. if you don't love it at first sight it will be harder in the future. and don't waste time choosing one, just start experimenting.

          SketchUp Ruby Consultant | Podium 1.x developer
          http://plugins.ro

          1 Reply Last reply Reply Quote 0
          • T Offline
            toxicvoxel
            last edited by

            I think this thread may create the impression that the C variant languages are the only serious options if you wish to learn a mainstream programming language to do 3D/graphics work. C/C++ is the AutoCAD of the programming world. There are simpler entry points for those who wish to take a step up from just using a scripting API. If you wish to spend a substantial time learning about using a violin instead of getting to a point where you actually create music with the tool, then by all means : go off and learn C/C++.

            But unfortunately as with Sketchup and the die-hard AutoCAD users in the early days, you may have to bear the brunt of half-researched abuse from the C-club if you go for something modern and simple like C#,- or dare I even say it: VB.NET.

            1 Reply Last reply Reply Quote 0
            • tbdT Offline
              tbd
              last edited by

              @toxicvoxel said:

              if you go for something modern and simple like C#,- or dare I even say it: VB.NET.

              if you want to do simple things go with "simple" languages but after running the simple examples you will have problems that need knowledge of the things that run under the hood.

              SketchUp Ruby Consultant | Podium 1.x developer
              http://plugins.ro

              1 Reply Last reply Reply Quote 0
              • M Offline
                MartinRinehart
                last edited by

                @toxicvoxel said:

                ... if you go for something modern and simple like C#, ...

                Simple? Nothing about .NET is simple. C# is an argument for bariatric language surgery.

                When MSFT created Windows, it deliberately pessimized the programming interface. You could tell when you tried to use it that a) the people in Redmond were idiots (you knew this was not the case), or b) the people in Redmond wanted to make it as hard as possible to create Windows programs. (Subsequent MSFT documents, dug out at trial, confirmed that the answer was b).)

                MSFT did not change with .NET. It is simply a way to get anyone who uses it locked into a Windows-only future. Use C# if you want a language more bloated than Ada and you want your code to never run on a Mac and ...

                Oh dear. Gotta do something to lower my heart rate.

                Author, Edges to Rubies - The Complete SketchUp Tutorial at http://www.MartinRinehart.com/models/tutorial.

                1 Reply Last reply Reply Quote 0
                • T Offline
                  toxicvoxel
                  last edited by

                  @unknownuser said:

                  and you want your code to never run on a Mac and ...

                  • An good example of a half-researched comment. Ever heard of the Mono Project? http://www.mono-project.com/Main_Page

                  @unknownuser said:

                  If you want to do simple things go with "simple" languages but after running the simple examples you will have problems that need knowledge of the things that run under the hood.

                  TBD, that comment reminds me of the silly remarks you made a while back on the old @Last forum relating to the Gelato rendering system until the NVIDIA development team put you in your place. These languages have been used on projects of far greater complexity than anything you will ever code in C.

                  If you like C/C++ then fine, but don't mislead the youngsters who are contemplating first steps into choosing a programming language. I have personally used .NET for more than 10 years on a range of design automation projects, some for one of the largest engineering firms in the world, and I do not recognise any of the characteristics either of you assign to these languages in your posts.

                  1 Reply Last reply Reply Quote 0
                  • AdamBA Offline
                    AdamB
                    last edited by

                    I realise this is all set for a flame war..

                    The thread is about producing Extensions for Ruby (which is written in C). So TBD comment about keeping it simple and using C/C++ is pretty reasonable.

                    Its all well saying Mono, but the reality is that on a Mac, Xcode has great support for C/C++ and not Mono/C#.

                    Developer of LightUp Click for website

                    1 Reply Last reply Reply Quote 0
                    • tbdT Offline
                      tbd
                      last edited by

                      toxic: create a simple .NET ruby extension example that works inside Sketchup or quit babbling around

                      SketchUp Ruby Consultant | Podium 1.x developer
                      http://plugins.ro

                      1 Reply Last reply Reply Quote 0
                      • tbdT Offline
                        tbd
                        last edited by

                        a ruby extension - create a new ruby class with one simple method in .NET. compile, copy .so in SU Plugins and ready to use in .rb code

                        SketchUp Ruby Consultant | Podium 1.x developer
                        http://plugins.ro

                        1 Reply Last reply Reply Quote 0
                        • T Offline
                          toxicvoxel
                          last edited by

                          TBD, How is this relevant in the context of the thread and specifically my post, - unless you wish to narrow the scope of the discussion in order to make your point?

                          I can remember an AutoCAD guy in the office way back in SU V3 insisting that I show him how I was going to do a boolean intersection with SU. Like him you are missing the point and like him I don't think you will ever get the point.

                          1 Reply Last reply Reply Quote 0
                          • Chris FullmerC Offline
                            Chris Fullmer
                            last edited by

                            Sorry to get everyone so riled up around here. Lets not be bashful, dig out those old skeletons from the cloest.....oh wait, we already are!

                            The point of this thread is in fact SU based, and about how to write extensions for SU ruby. Or how to interface into SU from another program, or dll, etc. I really am not sure what my question is because I just don't know what is possible, and I don't have a specific task in mind that I am striving to find a solution for (yet!). I just want to broaden my horizons and I want to do it with a compiled language.

                            But I will say that I have installed a few compilers and such and I am reading up on C++ currently. But it gives a bit of background into C, C# and Java. Hopefully I'll be able to wrap my head around it.

                            Chris

                            Lately you've been tan, suspicious for the winter.
                            All my Plugins I've written

                            1 Reply Last reply Reply Quote 0
                            • T Offline
                              toxicvoxel
                              last edited by

                              @adamb said:

                              The thread is about producing Extensions for Ruby (which is written in C).
                              Really? I thought the opening line of the starter post was related to interfacing SU with external .dll's - which can be written with a variety of languages. Seen within that broader premise I think the comments would be misleading to novices looking for an unbiased opinion about selecting a language.

                              @unknownuser said:

                              It's all well saying Mono, but the reality is that on a Mac, Xcode has great support for C/C++ and not Mono/C#.

                              You may notice that my response was in context with the statement that .NET code cannot run cross platform, so I am at a loss to understand the logic of your point. Does XCode run on Windows platforms yet?, - I didn't know, nor does it matter as my design workflow is Windows based.

                              TBD, not sure what you want to know.- I have written a number of external .dlls that I interface with from Sketchup as part of my daily workflow, so I can assure you that it is possible, if you are suggesting that it can't be done.

                              1 Reply Last reply Reply Quote 0
                              • T Offline
                                toxicvoxel
                                last edited by

                                @unknownuser said:

                                and I am reading up on C++ currently.. But it gives a bit of background into C, C# and Java

                                That may take some time... πŸ˜‰
                                .

                                1 Reply Last reply Reply Quote 0
                                • T Offline
                                  toxicvoxel
                                  last edited by

                                  A positive idea that can be spun off from this thread would be to create a 'Ruby extendibily' subsection where developers could post sample 'How To..' code for linking SU to external applications, libraries, databases & web-services etc., through native extensions, Win32API, WIN32OLE, file IO, SOAP, and custom bridges etc. For example : Linking SU to Excel, SQL databases, XML, text files, connecting to a web services, linking to CAD. etc
                                  Starter code for interaction of SU Ruby with external libraries created with the plethora of languages in use could be posted over time by coders proficient in those languages. Such a code repository would be invaluable to existing developers proficient in other languages who wish to use Ruby to glue Sketchup to existing code and applications. This could also serve as a catalyst for seeing more plugins and extensions becoming available over time.
                                  [- And for novices the sample code could help to inform a choice for selection of a supporting coding language.)

                                  1 Reply Last reply Reply Quote 0
                                  • Chris FullmerC Offline
                                    Chris Fullmer
                                    last edited by

                                    I think that is a neat idea. If I ever make something usef-able I will post it. It looks to be a long ways off at the rate I am moving, but all things are possible. πŸ˜„

                                    Chris

                                    Lately you've been tan, suspicious for the winter.
                                    All my Plugins I've written

                                    1 Reply Last reply Reply Quote 0
                                    • T Offline
                                      toxicvoxel
                                      last edited by

                                      A summary of this topic should go onto that list for example:
                                      http://forums.sketchucation.com/viewtopic.php?f=180&t=25233

                                      1 Reply Last reply Reply Quote 0
                                      • thomthomT Offline
                                        thomthom
                                        last edited by

                                        I am extremely green to C/C++.
                                        Currently doing some very basic tests in C++ with VS2010.

                                        There is some number crunching that I'd like to do in C++. I did some comparisons and the Ruby version was 100 slower than the C++ version. So I am very interested in finding a way where I can create a set of number crushing methods in C++ which I can call from SU Ruby.

                                        What I am looking at at the moment is:

                                        • Sending two arrays of 3D co-ordinates to the C++ method (3D points can be simple array of three floats)
                                        • Have the C++ method do its thing
                                        • return a new array back to ruby

                                        Does it simplify much if the C++ never have to access any SU objects? Is it then possible to create a Windows and OSX solution? Would it be a DLL on Windows and ... what does OSX use...?

                                        The SUExt link in TDB's post (http://forums.sketchucation.com/viewtopic.php?f=180&t=25201#p216233) leads to a wiki page... ❓

                                        Thomas Thomassen β€” SketchUp Monkey & Coding addict
                                        List of my plugins and link to the CookieWare fund

                                        1 Reply Last reply Reply Quote 0
                                        • tbdT Offline
                                          tbd
                                          last edited by

                                          1. see remus response
                                          2. PellesC is my favourite - small, fast, free, doesn't install in all your machine, comes with all tools needed. it is C99 compliant

                                          I went via VStudio only when I complied some SU SDK programs - too many VS dependent crap to convert it to another compiler

                                          1. you need a compiler that creates Mac binaries and PellesC is not one of them 😞
                                            but on Mac you have IDE, compiler, debugging tools, Ruby by default so get one.

                                          my suggestion:

                                          • get a Mac - you can install Windows in bootcamp or virtualized if you want it
                                          • start with C, it is easier to debug ruby libraries problems (there are a lot, see Adam's comments)
                                          • compile my SUExt example and play with it for start

                                          SketchUp Ruby Consultant | Podium 1.x developer
                                          http://plugins.ro

                                          1 Reply Last reply Reply Quote 0
                                          • tbdT Offline
                                            tbd
                                            last edited by

                                            link updated in my original post to http://github.com/TBD/OpenSUP/tree/master/SUExt/

                                            SketchUp Ruby Consultant | Podium 1.x developer
                                            http://plugins.ro

                                            1 Reply Last reply Reply Quote 0
                                            • 1
                                            • 2
                                            • 3
                                            • 1 / 3
                                            • First post
                                              Last post
                                            Buy SketchPlus
                                            Buy SUbD
                                            Buy WrapR
                                            Buy eBook
                                            Buy Modelur
                                            Buy Vertex Tools
                                            Buy SketchCuisine
                                            Buy FormFonts

                                            Advertisement