News for hackers. Stuff that matters.
Re:What is “the stack”? by gcc_programmer on Thursday March 03, 2016 @07:56AM (#11216534)
> I found it pretty surprising that the x86 assembly instruction set knows about the C stack pointer and how the stack in C is laid out. Of course, you could invent your own new smart stack format, but you wouldn't be able to use the callq and retq instructions to call functions.

I find it pretty amazing how modern "programmers" are lacking in knowledge of basic computer science concepts. Let me nit-pick this statement as it is obviously wrong.

The x86 assembly language knows ABSOLUTELY nothing about the "C stack pointer and how the stack in C is laid out". I will now illustrate why the first part of this statement is wrong.

You can have a bare-metal x86 device that is only programmed though assembly and push/pop would still be available. You are clearly confusing the roles of the compiler, operating system, and the language your program is written in. On a modern operating system like Linux, each program, when started, runs in a new process, which has its own view of memory due to the virtual memory system. Each program has its view of memory split into several sections, and one of them is allocated as "stack space" (it's usually the high memory addresses but this is architecture and/or OS dependent). When the program is executed, %rsp would be set-up appropriately by the OS, and on context switches it would save/restore it. Moreover, the actual address of your stack in real memory is different for every program since each process/program has its own mapping of virtual to physical memory, again provided by the OS.

Now, the second part about the "layout of the stack". The language you write your program in (in this case C) knows ABSOLUTELY nothing about the layout of "the stack". However, when you give your source code to the compiler, it will analyse it and, because C is low-level and staticly typed, will infer HOW it actually needs to lay out the stack FOR you. The output of the compiler is assembly code, and the assembly code produced "knows" about the layout of the stack because it has been written that way, generated by the compiler. It is, actually, the compiler that knows about all of this, not the source or assembly language.

Also, the example with python was a bad one - python is an interpreted language, and AFAIK it has no concept of a stack, and even if it does, it is the interpreter that allocates frames for it's own computations, not the program that you are running. And, moreover, even if python does allocate stack frames, they are most probably on the heap since it needs to do so dynamically (again, since it's not compiled but interpreted).

Re:What is “the stack”? by vm_programmer on Thursday March 03, 2016 @09:25AM (#11216956)
> python is an interpreted language, and AFAIK it has no concept of a stack,

Here, I could say, "I find it pretty amazing that old-timey[1] 'programmers' fail to understand modern VM architecture". In fact, Python's interpreter (cpython) is partly based on the concept of a stack.

But instead, I'll just explain that most modern VM's are either stack-based or register-based. Stack-based VM's, like Python's, are (not surprisingly) based on a virtual machine that uses a stack as it interprets Python's bytecode. Yes, not the same level of abstraction as the call stack, but it's still a stack.

So instead of expressing dismay at how little modern programmers know about your little corner of the programming world (low-level systems programming), why not spend some time pondering about how so much programming has moved up the stack, and how abstractions have grown multifold.

In the 1970s and 1980s, it used to be that the typical self-taught programmer had to know all the details low-level C and assembly, because that was almost all there was to know, unless you were a high-level Lisp hacker.

I mean, I'm a little surprised at how little some C kernel hackers know about how the modern Web works (particularly regarding async programming patterns; eg, been asked by one why I didn't just use a mutex somewhere in JS program, wasn't trolling.). But then I realize that there's just too much for any but the most exceptional programmers to truly understand the full modern stack, from system architecture, to GPU, to networking, to Web, on so on.

Why not instead welcome how this particular web-focused programmer is interested in these low-level concepts? Is it that it wouldn't give you as much of a chance to show off your knowledge?

1. Said by another old-timey programmer.

Re:What is “the stack”? by TheOtherHobbes on Thursday March 03, 2016 @10:45AM (#11217512)
VMs, and VM-based languages, are applications that run on top of all that kernel programming.

Applications come and go so there's no reason to feel amazed that not everyone know how the Python VM works - especially considering the details aren't considered a core part of the Python curriculum, and they're almost completely inaccessible to a typical Python user.

But not understanding the heap or the stack has real implications for application performance and stability in whatever language or VM you're working in. The abstractions have gotten more abstract, but developers who no longer understand what happens when you run out of memory, or have a buffer under/overflow, or your stack explodes because you're using recursion without tail calls, are definitely a bad thing.

You seem to be arguing that anyone who does web or VM dev doesn't really need to know what happens inside a computer. I think that's an unhelpful view, because it implies that all those abstractions "just work" and no one who uses them needs to care how.

Do they really "just work"? I think the evidence suggests they don't. Perhaps if developers understood hardware better that could be improved.

Re:What is “the stack”? by vm_programmer on Thursday March 03, 2016 @01:58PM (#11219056)
> VMs, and VM-based languages, are applications that run on top of all that kernel programming.

I'm guessing the vast majority of all modern programming is done using VMs: Python, Java, C#, Lua^, JavaScript^, etc. Basically, if your language uses a runtime, it's likely using a documented or undocumented bytecode and VM. They're pretty important to understand.

> You seem to be arguing that anyone who does web or VM dev doesn't really need to know what happens inside a computer.

That's not my argument. I highly recommend new programmers to understand as much of machine architecture as reasonable. I'm just arguing that there's no place for a systems programmer to be so dismissive toward a web programmer because he/she doesn't know his part of the stack as well as he does. There is always going to be a gap in knowledge about low-level programming between these two specializations. That gap is no reflection on the intelligence or competence of the higher-level programmer.

In this particular case, I believe that Julie has only been programming for a few years. If that's the case, and assuming she only retains a fraction of what she writes about, she's further along than most of us were at that point (me included). Just because many of us bluff and bluster our way through interactions with our peers, and Julie is up-front about her state of knowledge, doesn't mean that she's an inferior programmer (at all). I suspect her honest curiosity will carry her along to the top of our profession in due time.

So if the parent had written something like, "it's so important for new programmers to work on this type of material, and it's heartening to see these kinds of blog posts from younger programmers", then I would have applauded.

That also would have been more in line with the HN guidelines ("avoid gratuitous negativity"), rather than the approach that was actually taken.

^ If you want to advance the "Lua, Python, and JS" aren't VMs, but rather interpreters, you'll need to convince the likes of Mike Pall and Lars Bak that they're not working on a VM (both have explicitly referred to their creations as "VMs").

Re:What is “the stack”? by scott_s on Thursday March 03, 2016 @11:15AM (#11217784)
If everyone needed to have the same level of understanding of all of the technology they used, we would never get technological progress.
Re:What is “the stack”? by sklogic on Thursday March 03, 2016 @10:46AM (#11217521)
> "I find it pretty amazing that old-timey[1] 'programmers' fail to understand modern VM architecture"

Especially given that they've been "modern" from around 1970s, not changing much since then (tracing JITs are likely to be the only significant improvement).

> how little some C kernel hackers know about how the modern Web works

Uhm... Screw the web. It's boring and irrelevant. It does not really worth knowing. It's better to stay away from it, for a sake of sanity.

> async programming patterns

Had been around long, long before all that web crap.

Re:What is “the stack”? by wyldfire on Thursday March 03, 2016 @09:25AM (#11216961)
> I find it pretty amazing how modern "programmers" are lacking in knowledge of basic computer science concepts.

IMO this is the natural evolution of programming. It has gotten remarkably easier to write complex programs that deliver real value to society. How fantastic is it that modern programmers don't need to understand the science of computers in order to be productive?

Yes, we will always need science and engineering and folks who understand the underlying technology. But the field is broadening into new places. Like it or not, when uncle Fred writes an excel macro, he's programming. And good for him!

Re:What is “the stack”? by scott_s on Thursday March 03, 2016 @10:27AM (#11217367)
I mostly agree with you, but I actually think the original poster was incorrect in calling such low-level details "basic computer science" concepts. They are basic systems programming concepts. One can know a lot of computer science without knowing such things - you can probably find computer science professors who do strictly theoretical work that wouldn't know these details well enough to explain it.
Re:What is “the stack”? by geographomics on Thursday March 03, 2016 @02:09PM (#11219169)
I'd be very surprised to meet a computer scientist who doesn't know what a stack is. It really is a fundamental part of computer science.
Re:What is “the stack”? by scott_s on Thursday March 03, 2016 @02:22PM (#11219271)
I agree with your statement. However, that is not what I meant. The poster gcc_programmer was talking about very specific points about how "the stack" (not a stack) for a stack-based language gets implemented.
Re:What is “the stack”? by geographomics on Thursday March 03, 2016 @03:50PM (#11219940)
Good point, thanks for the correction.
Re:What is “the stack”? by brashrat on Thursday March 03, 2016 @09:31AM (#11216991)
wellll if you are going to nitpick you ought do it a little more cleanly: you are confusing machine language with assembly for starters, and even at the level of machine code, processors such as the x86 family were designed keeping support for higher level language conventions in mind, so it's difficult to pretend that there is no commonality of stack conventions baked into the microcoded x86 virtual machine.

Concepts you refer to such as "assembly language" exist a level up from bare metal, and at the same level as object libraries, linkers, and loaders and that implies full cooperation WRT calling conventions.

Re:What is “the stack”? by scott_s on Thursday March 03, 2016 @10:24AM (#11217338)
Your post has good technical information, but the attitude is not helpful. Please do not scold people for having less knowledge than you. It is not welcoming.
Re:What is “the stack”? by burfog on Thursday March 03, 2016 @11:24PM (#11222037)
Same here. I guess this relates to why it is so difficult to hire people. Just a couple days ago, somebody crashed and burned in the interview by not knowing how to do bit manipulation. Why are these people allowed to graduate?
Re:What is “the stack”? by gcc_programmer on Thursday March 10, 2016 @11:35AM (#11260176)
Those apps ain't going to write themselves.