Write C++ in a graphical scratch-like way?

2020-06-06 04:46发布

I am considering the possibility of designing an application that would allow people to develop C++ code graphically. I was amazed when I discovered Scratch (see site and tutorial videos).

I believe most of C++ can be represented graphically, with the exceptions of preprocessor instructions and possibly function pointers.

What C++ features do you think could be (or not be) represented by graphical items? What would be the pros and cons of such an application ? How much simpler would it be than "plain" C++?

RECAP and MORE:

Pros:

  • intuitive
  • simple for small applications
  • helps avoid typos

Cons:

  • may become unreadable for large (medium?) - sized applications
  • manual coding is faster for experienced programmers
  • C++ is too complicated a language for such an approach

Considering that we -at my work- already have quite a bit of existing C++ code, I am not looking for a completely new way of programming. I am considering an alternate way of programming that is fully compatible with legacy code. Some kind of "viral language" that people would use for new code and, hopefully, would eventually use to replace existing code as well (where it could be useful).

How do you feel towards this viral approach?

When it comes to manual vs graphical programming, I tend to agree with your answers. This is why, ideally, I'll find a way to let the user always choose between typing and graphical programming. A line-by-line parser (+partial interpreter) might be able to convert typed code into graphical design. It is possible. Let's all cross our fingers.

Are there caveats to providing both typing and graphical programming capabilities that I should think about and analyze carefully?

I have already worked on template classes (and more generally type-level C++) and their graphical representation. See there for an example of graphical representation of template classes. Boxes represent classes or class templates. First top node is the class itself, the next ones (if any) are typedef instructions inside the class. Bottom nodes are template arguments. Edges, of course, connect classes to template arguments for instantiations. I already have a prototype for working on such type-level diagrams.

If you feel this way of representing template classes is plain wrong, don't hesitate to say so and why!

11条回答
再贱就再见
2楼-- · 2020-06-06 05:12

Writing code is the easiest part of a developers day. I don't think we need more help with that. Reading, understanding, maintaining, comparing, annotating, documenting, and validating is where - despite a gargantuan amount of tools and frameworks - we still are lacking.


To dissect your pros:

Intuitive and simple for small applications - replace that with "misleading". It makes it look simple, but it isn't: As long as it is simple, VB.NET is simpler. When it gets complicated, visual design would get in the way.

Help avoid typos - that's what a good style, consistency and last not least intellisense are for. The things you need anyway when things aren't simple anymore.


Wrong level

You are thinking on the wrong level: C++ statements are not reusable, robust components, they are more like a big bag of gears that need to be put together correctly. C++ with it's complexity and exceptions (to rules) isn't even particulary suited.

If you want to make things easy, you need reusable components at a much higher level. Even if you have these, plugging them together is not simple. Despite years of struggle, and many attempts in many environments, this sometimes works and often fails.


Viral - You are correct IMO about that requriement: allow incremental adoption. This is closely related to switching smoothly between source code and visual representation, which in turn probably means you must be able to generate the visual representation from modified source code.


IDE Support - here's where most language-centered approaches go astray. A modern IDE is more than just a text editor and a compiler. What about debugging your graph - with breakpoints, data inspection etc? Will profilers, leak detectors etc. highlight nodes in your graph? Will source control give me a Visual Diff of yesterday's graph vs. today's?


Maybe you are on to something, despite all my "no"s: a better way to visualize code, a way to put different filters on it so that I see just what I need to see.

查看更多
【Aperson】
3楼-- · 2020-06-06 05:14

I like the idea, but I suspect there comes a point where things get far too complicated to be represented graphically.

However, given recent experience at work; it would be useful to give such a graphical interface to a non-techie person to use to create basic drag-and-drop programs, leaving myself free to get on with some "proper" programming ;-) If it can do the job of allowing somebody non-skilled to build something functional it can be a very good thing (even if programming logic escapes them)

There comes a point in such a system where it becomes easier to define what you want to do using literal C++ code, rather than have a user interface getting in the way; it can get frustrating to the sessioned programmer knowing the precise code that needs to be written but then only being limited to the design GUI. I'm specifically thinking about a more common application, such as html editors/designers in which they allow newbies to build their websites without knowing any html at all.

It would be interesting to see how such a system would handle the dynamic allocation of memory, and the different states of a program as time progressed; I suspect that there are some very basic programming concepts that may be difficult to represent graphically.. Polymorphism..? Virtual Classes, LinkList, Stacks/Circular Queues. I wonder for a moment how you would explain an image compression algorithm (such as jpg) successfully too without the help of a gigantic display screen.

I also wonder if such a system would even go to such a low level, and whether you would be dealing with abstracted concepts and the compiler would be working out the best way to do something.

查看更多
放荡不羁爱自由
4楼-- · 2020-06-06 05:14

I think the major problem of this kind of IDEs are that the code generated becomes unmantainable easily.

This happened to Delphi. It's a really nice tool to develop some kind of applications, however, when we start adding complex relationships between the components, start adding Design Patterns, etc. the code grows to an unmantainable size.

I believe it's also because graphical tools don't apply the concept of MVC (or if they do, it's only in the way that the IDE understands).

It can be really helpful for prototypes and very small applications that don't tend to grow, otherwise it can become a mess for the developer(s)

查看更多
地球回转人心会变
5楼-- · 2020-06-06 05:18

The early versions of C++ were originally written so that they compiled to C, then the C was compiled as normal.

What it sounds like you are describing is a graphical language that is compiled to C++, which will then be compiled as normal.

So really you are not creating a graphical C++, you are creating a new language that happens to be graphical. Nothing wrong with that, but don't let C++ restrict what you do, because eventually you may want to compile the graphical language straight to machine code, or even to something like CIL, Java ByteCode, or whatever else tickles your fancy.

Other graphical languages you may want to check out are LabVIEW, and more generally the category of visual programming languages.

Good luck in your efforts.

查看更多
成全新的幸福
6楼-- · 2020-06-06 05:18

What C++ features do you think could be [...] represented by graphical items?

Object Oriented Design. Hence classes, inheritance, polymorphism, mutability, const-ness etc. And, templates.

What would be the pros and cons of such an application?

It may be easier for beginners to start writing programs. For the experienced, it may be get rid of the boring parts of programming.

Think of any other code generator. They create a framework for you to write the more involved portion(s). They also lead to bloated-code (think of any WYSIWYG HTML editor).

The biggest challenge, as I see it, is that any such UI necessarily hinders the user's imagination.

How much simpler would it be than "plain" c++ ?

It can be a real pain, when you wade through truckloads of errors which is typical of code generators.

Further, since a lot of code is generated, you have no idea of what is going on -- debugging becomes difficult.

Also, for the experienced there may be some irritation to find that the generated code is not per their preferred coding style.

查看更多
登录 后发表回答