Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I\'m a college student and I have homework in C++. My professor wants separate h

ID: 655023 • Letter: I

Question

I'm a college student and I have homework in C++.

My professor wants separate hpp and cpp files for each C++ class. And it just didn't feel good how much I had to type, and how much I had to click to create two new files for every class.

I haphazardly put together a simple Python script that would read a single file and generate all the needed classes (the easy stuff like class name, list of members, and list of things to #include I sprinkled with syntactic sugar, but the hard stuff to parse like typenames and function bodies I copied and pasted for the most part, except my script pokes around in a very primitive way to qualify method signatures with the class name when it generates the implementation file).

And I felt pretty good about it.

But I realized, that if a lot of other people had worked on a similar problem in the past, they probably could have done it better.

I know that Chicken scheme translates to C, and so does vala and genie, but from what I understand, with these sorts of translators, you don't really have full control over the C output.

Do you know of any translators that output C++ that largely keeps the semantics of C++ intact, so that the output C++ files look handwritten, but the source language is just loaded with wonderful syntax that makes life easier? Maybe even have the language mess with the body of functions so that if I typed something like vector<int> v = [1,2,3,4,5] it would become vector<int> v; v.push_back(1); v.push_back(2); .. in the generated source? Maybe have braces automatically inserted based on indentation? Have newlines serve as semicolons?

Explanation / Answer

No, a language like you are looking for is unlikely to exist.

I vaguely remember a few efforts to create new languages that tried to remove such warts out of C++ as header files, but invariably they are either compiled directly (no translation to C++) or the C++ they generate has a distinct machine-generated look and feel, because producing readable C++ wasn't (enough of) a requirement.

In most cases, the duplication that you get from having separate declarations and definitions is taken care of to a sufficient degree by advanced editor features, like macros, wizards and refactoring tools.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote