Is it possible to compile a higher level language to readable C++? [closed]

C++ is a great language in many ways, but some things in particular are cumbersome to write without an IDE. As a VIM user, it would be very interesting if I had access to a higher level language which enabled me to write C++ with S-Expressions and possibly with Lisp-like macros, allowing for the generation of clean code while avoiding rewriting the same patters over and over again.

I’ve asked on freenode and tested several ideas, such as compiling Lisp->C with compilers such as ECL and Bigloo, but none of those generated particularly clean C code.

Are there any works on this issue?

16

Compiling higher level languages to lower level ones is cake. There’s countless examples of it being done. Without going off on much of a tangent, we can point to early C++ compilers that compiled down to C.

When you start throwing “clean” and “readable” into the mix, however, things get really tough. Clean, readable code expresses the meaning and intent of what you were writing. Computers are notoriously bad at interpreting & creating meaning. You’re more likely to end up with variables named int_147 than input_buffer_length. Sure, if you really wanted to make this project work, you could engage in a massive AI project to handle converting your Lisp to some sort of decently readable C++ but, to be perfectly honest, Common Lisp compilers are pretty fucking good at what they do.

More important than the difficulty of generating C++ from a Lisp is the usefulness of this. What purpose would it serve for the generated C++ to be readable? If the Lisp is your source code, intermediate representations should be irrelevant. If you want to be able to hand the C++ over to programmers that don’t understand your original Lisp, you’ve now got another problem. What happens when they want to modify your generated C++? What happens if they write things in C++ that don’t cleanly translate to your Lisp?

Let’s say we’ve solved that. It’s a decade later and, after burning through hundreds of millions of dollars of DoD grant money, we’ve build this massive, complex (but flawless) language translation engine that can turn Lisp into idiomatic C++ and vice versa. What have we really gained that wouldn’t be better accomplished by either teaching people a new programming language or just developing a new compiler that lets us link the two languages?

Oh, right. Your boss wants you to write C++ and you’d rather not. Update your resume & find a new job.

3

Short answer, there is nothing out there currently that will help you convert Lisp to READABLE C++. Sure you can convert anything to C++ or C but readable code is written by humans, not programs. Sure you can output C++ code with proper formatting, indents, nice class names, and maybe even somehow get perfect translation from Lisp class objects to C++ classes. Maybe you can get your library dependencies linked just right, and maybe you can compile binaries that are very close to what the C language would have produced had you written the whole thing in C. But ultimately, readable code is a beauty that is not understood by anyone, at least not just yet, and possibly never considering that the term readable is quite subjective to begin with and what might be considered readable among one group of developers may be considered atrocious by others.

To make C++ readable, you have to write in C++, not in Lisp. You also have to be able to change your coding style according to what the people who will read your code will best understand. Just like books, programs are written with a specific audience in mind and can be beautiful and touching if written well, and obfuscated and tedious if not. And if we can’t come up with a program to write beautiful fiction novels for us, then we won’t be able to come up with something to convert to readable C++.

1

ViM is a great IDE for C++. It has the best completion I’ve ever seen so far too, though it gets a little slow if you pull in a lot of headers, the clang complete. And for compilation I found all IDEs lacking anyway; you end up writing build system in CMake or something anyway. And I have not seen anything to provide any help for lisp, period.

True, C++ does not have lisp-style macros, but templates can do everything scheme’s hygienic macros can and some more, because you can implement them differently based on types and based on their capabilities. True, it’s lack of garbage collector makes closures a bit more tedious, but the RAII idiom used for resource management instead has it’s own advantages and interesting properties.

If you are a student, do you really know all the advanced C++? From algorithms library over writing templates with alternate implementations based on properties of argument types, compile time calculations using template meta-programming (using Boost.MPL) to understanding how Boost works under the hood? If not, I recommend taking this as opportunity to learn some advanced C++. School assignment won’t need to be maintained, so you can play with the language to see what the features are worth where in production code you’d have to be careful about readability.


And to answer the final direct question: C++ has so many more idioms under it’s belt that there is no way to generate idiomatic C++ from anything. Simply because there will be no way to express most of those idioms in anything else. Starting from the fact that anything will garbage collection will allocate everything on heap while in C++ it is idiomatic to take advantage of the stack.

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa

Is it possible to compile a higher level language to readable C++? [closed]

C++ is a great language in many ways, but some things in particular are cumbersome to write without an IDE. As a VIM user, it would be very interesting if I had access to a higher level language which enabled me to write C++ with S-Expressions and possibly with Lisp-like macros, allowing for the generation of clean code while avoiding rewriting the same patters over and over again.

I’ve asked on freenode and tested several ideas, such as compiling Lisp->C with compilers such as ECL and Bigloo, but none of those generated particularly clean C code.

Are there any works on this issue?

16

Compiling higher level languages to lower level ones is cake. There’s countless examples of it being done. Without going off on much of a tangent, we can point to early C++ compilers that compiled down to C.

When you start throwing “clean” and “readable” into the mix, however, things get really tough. Clean, readable code expresses the meaning and intent of what you were writing. Computers are notoriously bad at interpreting & creating meaning. You’re more likely to end up with variables named int_147 than input_buffer_length. Sure, if you really wanted to make this project work, you could engage in a massive AI project to handle converting your Lisp to some sort of decently readable C++ but, to be perfectly honest, Common Lisp compilers are pretty fucking good at what they do.

More important than the difficulty of generating C++ from a Lisp is the usefulness of this. What purpose would it serve for the generated C++ to be readable? If the Lisp is your source code, intermediate representations should be irrelevant. If you want to be able to hand the C++ over to programmers that don’t understand your original Lisp, you’ve now got another problem. What happens when they want to modify your generated C++? What happens if they write things in C++ that don’t cleanly translate to your Lisp?

Let’s say we’ve solved that. It’s a decade later and, after burning through hundreds of millions of dollars of DoD grant money, we’ve build this massive, complex (but flawless) language translation engine that can turn Lisp into idiomatic C++ and vice versa. What have we really gained that wouldn’t be better accomplished by either teaching people a new programming language or just developing a new compiler that lets us link the two languages?

Oh, right. Your boss wants you to write C++ and you’d rather not. Update your resume & find a new job.

3

Short answer, there is nothing out there currently that will help you convert Lisp to READABLE C++. Sure you can convert anything to C++ or C but readable code is written by humans, not programs. Sure you can output C++ code with proper formatting, indents, nice class names, and maybe even somehow get perfect translation from Lisp class objects to C++ classes. Maybe you can get your library dependencies linked just right, and maybe you can compile binaries that are very close to what the C language would have produced had you written the whole thing in C. But ultimately, readable code is a beauty that is not understood by anyone, at least not just yet, and possibly never considering that the term readable is quite subjective to begin with and what might be considered readable among one group of developers may be considered atrocious by others.

To make C++ readable, you have to write in C++, not in Lisp. You also have to be able to change your coding style according to what the people who will read your code will best understand. Just like books, programs are written with a specific audience in mind and can be beautiful and touching if written well, and obfuscated and tedious if not. And if we can’t come up with a program to write beautiful fiction novels for us, then we won’t be able to come up with something to convert to readable C++.

1

ViM is a great IDE for C++. It has the best completion I’ve ever seen so far too, though it gets a little slow if you pull in a lot of headers, the clang complete. And for compilation I found all IDEs lacking anyway; you end up writing build system in CMake or something anyway. And I have not seen anything to provide any help for lisp, period.

True, C++ does not have lisp-style macros, but templates can do everything scheme’s hygienic macros can and some more, because you can implement them differently based on types and based on their capabilities. True, it’s lack of garbage collector makes closures a bit more tedious, but the RAII idiom used for resource management instead has it’s own advantages and interesting properties.

If you are a student, do you really know all the advanced C++? From algorithms library over writing templates with alternate implementations based on properties of argument types, compile time calculations using template meta-programming (using Boost.MPL) to understanding how Boost works under the hood? If not, I recommend taking this as opportunity to learn some advanced C++. School assignment won’t need to be maintained, so you can play with the language to see what the features are worth where in production code you’d have to be careful about readability.


And to answer the final direct question: C++ has so many more idioms under it’s belt that there is no way to generate idiomatic C++ from anything. Simply because there will be no way to express most of those idioms in anything else. Starting from the fact that anything will garbage collection will allocate everything on heap while in C++ it is idiomatic to take advantage of the stack.

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật