Hacker News new | ask | show | jobs
by SamReidHughes 2712 days ago
It fails to compile the program

    #include <iostream>

    int main() {
        int x = 23;
        std::cout << x;
        return 0;
    }
It seems like it can't handle namespaces.

When I write

    #include <vector>
it complains, "cannot find library: vector".

I think this isn't going to be very useful for people unless you get a C++ evaluator that works correctly. There is a demo of Clang running in the browser using webassembly here: >> https://tbfleming.github.io/cib/ << but it doesn't actually work for me on Firefox. Maybe I need to use Chrome. That is probably a better option for getting C++ running in the browser.

1 comments

The repo of the original interpreter: https://github.com/felixhao28/JSCPP

Which notable features are not implemented yet?

    Goto statements
    Object-oriented features
    Namespaces
    Multiple files support
The target audience would consists in students trying simple algorithms. By the end of the high school, students are only using very basic C-syntax: variables, arrays, functions, and a couple of functions from the standard library.

Some partial implementations: iostream (only cin and cout and endl) cmath cctype cstring cstdio (partial) cstdlib (partial)

Other includes could be added too.

What I am trying to highlight is if there is any possibility to increase the visual feedback for students heading first to programming.

Something more like an interpretor would be more suitable in this case, but the wasm compilation doesn't seem too slow though. Thanks for this demo!

> By the end of the high school, students are only using very basic C-syntax: variables, arrays, functions, and a couple of functions from the standard library.

if the goal is to have them writing C-style C++ code, why not just use C? or if the goal is to teach C++, why start with only the features available in C?

I've been a TA for classes in both C and C++, and I think we ultimately do a disservice to these students by not treating these languages more separately.

I agree. However, the goal of the computer science classes is to teach basic algorithms and data structures, and not focusing on the language particularly. For instance, in the national exam (written) you may use any printing function (printf / cout), but you are limited to use C-style string functions. No vectors, no additional containers C++. Pointers are being studied too, but there are no exercises which involve coding in exams for memory allocations, so you never get to choose between new/malloc. I don't like this situation but this is the problem I am trying to address, any idea is well appreciated!
As far as I can tell, this interpreter doesn't even have std::string, and you can't define your own datatypes or allocate. The interpreter also doesn't handle pointers into arrays properly.

I'm not familiar with other countries' curricula, but we had vectors and strings very early on when I learned C++. I like the general idea of the debugging interface, that could help a lot of people. But I think you should upgrade the interpreter. I don't know if that's possible while retaining the debugging interface, unfortunately.

These are the main downsides indeed. As a matter of fact, in the current curricula the only option is cstring, and it's been that way in the last 20 years. I am looking forward to put in balance the upsides and downsides in using such an interpreter. Thank you for feedback!
If it has no object-oriented features, then I don't think it deserves to be called a C++ interpreter at all, since that's basically the one feature everyone thinks of when they're asked to compare C and C++; from the description it looks more like a C-subset interpreter.
From the point of end user yes, but the original JSCPP project allows custom classes and members to be available via include.