Live data from Hacker News

Show HN: Going into freshman year, figured I should build an interpreter

news.ycombinator.com

41–50 of 84 posts

Re: Show HN: Going into freshman year, figured I should build an interpreter

#41

Earlier quoted context omitted.

That old chestnut. C is nothing remotely like an assembly language, of any kind. It is a low-level programming language, but only compared to most languages. Disassemble some compiled C code sometime -- it's another world entirely.

I’ve programmed in both assembly and C, among other things. I stand by it, C is much closer to the machine than most languages.

I think Lisp won that battle. The core syntax was named after actual cpu registers (cdr/car).

Re: Show HN: Going into freshman year, figured I should build an interpreter

#42

Here's perhaps some unexpected and unsolicited advice... so pretty clearly you aren't going to have a hard time with the CS curriculum (assuming that's what you intend to study) so my $0.02 is - find a second or even third major to augment your skill set. If you are already able to get to this level on your own, you'll likely breeze right through a typical undergrad CS course of study. So consider other courses of st…

Take the grad courses.

Re: Show HN: Going into freshman year, figured I should build an interpreter

#43

Here's perhaps some unexpected and unsolicited advice... so pretty clearly you aren't going to have a hard time with the CS curriculum (assuming that's what you intend to study) so my $0.02 is - find a second or even third major to augment your skill set. If you are already able to get to this level on your own, you'll likely breeze right through a typical undergrad CS course of study. So consider other courses of st…

Can't agree more with this. I ended up double-majoring Philosophy and it was fantastic and has surprisingly helped several times in my career

Re: Show HN: Going into freshman year, figured I should build an interpreter

#44
post #11

[flagged]

Given OP's (presumed) age, curiosity and enthusiasm, my advice to OP would be to not worry about what language you are going to specialize in at all. That can come later. In fact, do the opposite: learn every language under the sun and prioritize weird languages with unique ideas that are outside of the mainstream. Learn Rust, Haskell, Lisp (OP is already learning Racket so that's covered), Prolog, Forth, assembly, Smalltalk, ... (admittedly I haven't learned every language on this list; there are some that I wished I learned when I had more time for it).

OP is at a stage in life where fluid intelligence is still very high and crystallized intelligence is growing rapidly. This is the time in your life where you are perhaps most able to absorb new ideas and ways of thinking, before you get set in your ways and less receptive to different ways of thinking.

Re: Show HN: Going into freshman year, figured I should build an interpreter

#45
For furthering your skills, i can suggest a related topic (that is never taught officialy though): debugging/reverse-engineering an interpreter. Does not have to be a JVM-size, most games have lots of interpreters in them too.. (although there might be multiple layers of interpreters - which is magnitude harder)

You may start with reversing compiled-code, but interpreter is much-much more.. interesting. Especialy if of unknown (simple) language.

Re: Show HN: Going into freshman year, figured I should build an interpreter

#46

Earlier quoted context omitted.

Ya, but would you rather spend the summer enjoying summer or writing C

It depends. When I was young I could spend hours coding and it felt amazing and like a great use of my time. Now in my 30s? No way, writing detailed code and spending all my time in front of the screen feels like I’m throwing away my life. All that minutia, whether useful or useless, is repulsive.

I'm in my 20s and I'm disappointed in myself for not spending time with my friends during school instead of wasting time making hacked together programs.

I came to realise I don't even like "real" programming only random quickly put together scripts.

When my friends explored all kind of things I was so stuck on coding and web dev and php. I didn't check out any other fields of interest or professions. When I read all the threads here about parents teaching their 4 year old BASIC to "indoctrinate them into programming", I cringe hard. They're stealing their kids' childhood and their drive to explore what they'd actually love.

Re: Show HN: Going into freshman year, figured I should build an interpreter

#47
post #11

[flagged]

C is a very popular language to use in undergrad courses, all our entry classes (intro to programming, data structures and algorithms, OS fundamentals, etc.) were in pure C - exactly because you have to deal with memory from the get-go.

If that's the case at the Uni OP is studying at, then he should be come fluent in C - because from experience as a TA, it's not necessarily the CS knowledge/fundamentals that tend to be lacking when people struggle with classes, but rather that they're fighting a new language. Even if they have years of previous experience...especially in these days, when Python or JS tend to be the first (and only) language to many freshmen.

Re: Show HN: Going into freshman year, figured I should build an interpreter

#48
My main advice: never trust C, C++, or their compilers. Undefined behavior bites. Even if you just care about the latest 64-bit Ubuntu Linux LTS, compiler updates or flag changes bite as well.

That's the main difference between C and C++ and almost any other language. Not the syntax, neither the perceived "low-levelness", nor manual memory management. In any other language, if you make a mistake, the program behaves badly, but in a predictable way. In C and C++ it may behave reasonably, it may crash in another file altogether few seconds after the erroneous line is executed, it may produce the correct answer. Or it may crash only sometimes. Or it may silently produce an incorrect answer. Different behaviors on different systems, and even on the same system with different compiler flags (e.g. optimization level), of course.

That makes reliable experiments with C and C++ impossible. Even if you have just five lines of code, you almost never know if they're valid C or C++ for sure (separately, whether they do what you want with modern/legacy compilers). It's still fun and everything (congrats on making your own language, that should've been fun!), but you never truly know whether what you wrote is not going to break in a few years (or months) with zero code modifications just because there was another UB lurking around.

See https://evan.nemerson.com/2021/05/04/portability-is-reliabil... if you're curious about more practical implications.

Re: Show HN: Going into freshman year, figured I should build an interpreter

#49
post #4

Earlier quoted context omitted.

Crumb is garbage collected (there is no need to manually allocated/deallocate memory)... though there is no background "garbage collector" process running... The interpreter for Crumb is a tree-walk interpreter, and it just frees memory whenever it can... Crumb frees memory in the following cases: 1) When a function is finished, all memory related to the scope of that runtime is freed. 2) When an value is not returne…

Sorry if I got the syntax wrong, but in something like f = { x = (list 1 2 3) y = (list x x) z = (get x 1) How does the compiler decides if it must free the memory used by x?

It should. Everything is copied and by-value, there are no references/pointers or even closures, cycles are impossible. Think Pascal that has garbage collection for strings and dynamic arrays.

Re: Show HN: Going into freshman year, figured I should build an interpreter

#50

My main advice: never trust C, C++, or their compilers. Undefined behavior bites. Even if you just care about the latest 64-bit Ubuntu Linux LTS, compiler updates or flag changes bite as well. That's the main difference between C and C++ and almost any other language. Not the syntax, neither the perceived "low-levelness", nor manual memory management. In any other language, if you make a mistake, the program behaves…

I suppose this is one of those things where people’s experiences vary widely, but FWIW after 20 years of writing C/C++, I can count the number of times this has bitten me on one finger. And even then, I still think it was more likely just an optimizer bug in the god-awful compiler.
Post reply on HN