News for hackers. Stuff that matters.
Re:Where do argc and argv come from? by vidanay on Monday August 10, 2020 @01:28PM (#24111736)
I feel like the article does not address the stated question.

arg(ument) c(ount) and arg(ument) v(ector) is what I was taught.

edit: After a re-read, the article is about where the actual values come from and not the historical semantic meaning of the variable names.

Re:Where do argc and argv come from? by zabzonk on Monday August 10, 2020 @02:04PM (#24112153)
Also, in C (and C++) the names of the parameters are not significant - you could call them x and y and the compiler would be happy.
Re:Where do argc and argv come from? by vidanay on Monday August 10, 2020 @02:07PM (#24112198)
In what language is the name of a method parameter ever significant?
Re:Where do argc and argv come from? by senkora on Monday August 10, 2020 @02:26PM (#24112403)
Python. Since any argument can be called as a keyword arg, the names of arguments are a part of the API, and renaming them can break user code.

I have written bugs because of this.

Re:Where do argc and argv come from? by wwright on Monday August 10, 2020 @04:26PM (#24113605)
Modern Python lets you explicitly opt out of this by putting “/“ in your argument list iirc correctly:

    def only_positional(a, b, /):
        Pass
Similarly, you can prevent keyword args from being called as positional (which has the inverse problem of breaking client code by changing the order of keyword arguments):

    def only_keyword(*, foo, bar):
        pass
Re:Where do argc and argv come from? by dralley on Monday August 10, 2020 @11:01PM (#24116758)
The first feature pretty much only exists to make interop with C apis less error prone. It's not really something that should be used in idiomatic Python
Re:Where do argc and argv come from? by dragonwriter on Monday August 10, 2020 @11:09PM (#24116797)
> The first feature pretty much only exists to make interop with C apis less error prone.

It makes it so that certain built-ins and native APIs can be properly typed, sure, but positional/keyword interchangeability is arguably a violation of the Zen, too.

Re:Where do argc and argv come from? by wwright on Tuesday August 11, 2020 @05:44PM (#24126384)
I disagree for the exact reason the thread here started: it’s part of your public API. If you don’t want keyword arguments in your public API contract, you absolutely should omit them from the contract.
Re:Where do argc and argv come from? by dotancohen on Monday August 10, 2020 @03:31PM (#24113104)
To be fair, "Python" is the answer to at least three other questions in the form of "In what language is ___ ever significant?"

That said, I love Python and it's the language that I taught to my daughters first.

Re:Where do argc and argv come from? by xmprt on Monday August 10, 2020 @06:00PM (#24114531)
I wonder if Python should still be the go to language for teaching programming. It's pretty simple and reads like English but I feel like if you can get over a few syntax bumps, Go is a lot easier to understand and is much more straightforward compared to Python which has a lot of quirks (like why can't spaces/tabs be mixed if they look the same on the editor, why are there so many different ways to write a loop)...

The only thing that might trip up beginners in Go is error handling but if they haven't learned any other way of doing it before then they might just accept it for what it is.

Re:Where do argc and argv come from? by int_19h on Tuesday August 11, 2020 @03:07AM (#24117895)
Go has a lot of quirks on things that matter far more. Like, arrays and slices, and how to use them as collections, is very much non-trivial compared to Python lists.

On the other hand, stuff like tabs vs spaces - when you would expect this to even come up? Whatever editor they'd use to start coding with, it'll be configured to use one or the other. In fact, these days, unless you get something exotic, it'll be spaces for sure.

And Python has exactly two ways to write a loop: one for conditional looping, and another when you want to iterate over a collection or a range. Is that really too many?

Re:Where do argc and argv come from? by xmprt on Tuesday August 11, 2020 @03:41AM (#24118093)
With tabs vs spaces stuff, the problem is that it's not exactly something that you can teach (like you said the editor will handle it for you). Then later if a beginner tries doing something on their own and runs into that error, it's not exactly intuitive how to fix it and they run into a brick wall that can't be solved no matter how much they look at their code.
Re:Where do argc and argv come from? by brandmeyer on Monday August 10, 2020 @06:59PM (#24115117)
Maybe as introduction, sure. But IMO Python does not encourage exploratory reasoning about how programs work.

For example, the question "how does `x.y()` get evaluated?" has a very complex answer. `x += y` is even more complex.

Re:Where do argc and argv come from? by Voliokis on Monday August 10, 2020 @08:44PM (#24116017)
What languages would you recommend for exploratory reasoning?
Re:Where do argc and argv come from? by xmprt on Tuesday August 11, 2020 @03:45AM (#24118118)
C++11 is probably as close as you can get to something that's simple enough and widely used but also supports diving into how computers work because you will eventually have to manage your own memory (although I'm not sure if memory management is an important skill for someone just starting to learn how to code).

For a real deep understanding, you'd probably have to jump into the actual computer microchip architecture to learn how computers store memory and do things like pipelining, branch prediction, and caching. Then a primer on Operating Systems (I like "Three Easy Pieces") should fill in the gaps.

Re:Where do argc and argv come from? by userbinator on Monday August 10, 2020 @11:35PM (#24116934)
I would choose Asm or perhaps even raw machine code.
Re:Where do argc and argv come from? by ramshorns on Monday August 10, 2020 @07:24PM (#24115386)
Whitespace or indentation is one, what else?
Re:Where do argc and argv come from? by loopz on Monday August 10, 2020 @02:30PM (#24112438)
For compiled languages, it's neat to get compiler error instead of a nasty bug.
Re:Where do argc and argv come from? by quietbritishjim on Monday August 10, 2020 @03:33PM (#24113123)
A bug is a problem that affects your users. If you're a library author then your users are developers of applications (and higher-level libraries), so an unintentional breaking change to your API is definitely a bug.
Re:Where do argc and argv come from? by kortilla on Monday August 10, 2020 @03:04PM (#24112817)
In python without explicit analysis using something like pylint you won’t find out until function call time.
Re:Where do argc and argv come from? by Karliss on Monday August 10, 2020 @03:08PM (#24112863)
No compiler in Python. In combination with features like varargs, kwargs, unpacking dictionary into args, argument forwarding Python allows you to turn this into bugs.
Re:Where do argc and argv come from? by senkora on Monday August 10, 2020 @04:59PM (#24113923)
Well, Python does get compiled to bytecode before it is run. And the compiler does tell you about some errors, like inconsistent indentation, even if that code is never executed.
Re:Where do argc and argv come from? by foota on Monday August 10, 2020 @02:08PM (#24112211)
Any with named args?
Re:Where do argc and argv come from? by ufo on Monday August 10, 2020 @04:20PM (#24113552)
Another example is Angular.js It used Javascript's toString() method to get the names of the arguments and then did dependency injection magic based on it.

Does anyone know if that is still the case for recent versions of Angular?

Re:Where do argc and argv come from? by bmm6o on Monday August 10, 2020 @04:50PM (#24113827)
And because js is frequently minified, there is a way to specify the names as string literals to keep the injection working.
Re:Where do argc and argv come from? by monocasa on Monday August 10, 2020 @02:16PM (#24112278)
Smalltalk and ObjC for a couple examples. I wouldn't be surprised to find out Swift was too, but I'm not 100% on that.
Re:Where do argc and argv come from? by plorkyeran on Monday August 10, 2020 @02:27PM (#24112417)
The name of method parameters in obj-c is not significant. The argument label and argument name are different things. In `- (void)frobulateThing:(id)firstThing andAlso:(id)secondThing;`, `firstThing` and `secondThing` are the argument names and can be changed with no impact on the callers, while `frobulateThing:andAlso:` is the part relevant to callers.

In Swift the argument labels are the same as the argument names by default, but you can also supply different values for them.

Re:Where do argc and argv come from? by loopz on Monday August 10, 2020 @02:24PM (#24112379)
I kinda like the idea of it, or at least have the option to do that. You can name args in python function calls.
Re:Where do argc and argv come from? by dcminter on Monday August 10, 2020 @05:08PM (#24114016)
Java (sometimes) where reflection allows you to inspect the parameter names, and you can optionally retain the names in the compiled bytecode.

E.g. these days the Spring framework defaults to using the parameter name as the qualifying name to discriminate between otherwise identical types during autowiring.

Re:Where do argc and argv come from? by DSMan195276 on Monday August 10, 2020 @09:36PM (#24116336)
Since it hasn't been mentioned yet, C#/.NET also has this dumb feature - the name of the parameter is compiled into the dll, and can be used for 'named arguments', where the caller can write `a: 20` in the argument list to assign the parameter called `a` to 20. If the library developer renames the parameter to something other than `a`, than that old code won't compile anymore (Though AFAIK the old compiled code is still ABI compatible with the new version, since the method arguments are resolved at compile time).
Re:Where do argc and argv come from? by SilasX on Monday August 10, 2020 @03:33PM (#24113130)
Ruby on Rails. Ugh. (Though yes, that’s a framework rather than a language.)
Re:Where do argc and argv come from? by inopinatus on Monday August 10, 2020 @07:05PM (#24115194)
Named arguments in much of the Rails API are received by the method via a single hash parameter, not as individual lexically bound variables.

In most cases, Ruby handles this capture via a double-splat operator in the parameter list.

However, Ruby itself does have both positional and named method parameters. The former contribute to arity and may be overridden and renamed in subclasses, and this remains true for Rails methods accepting positional arguments.

It is also the case that a hash is implicitly congruent to named arguments, although this is controversial and may change in future. I’m sorry to report that no-one has ever described this as “arg hash” or “argh” for short.

Re:Where do argc and argv come from? by int_19h on Tuesday August 11, 2020 @03:04AM (#24117884)
Pretty much any language that allows named parameters at call site.
Re:Where do argc and argv come from? by staycoolboy on Monday August 10, 2020 @04:24PM (#24113578)
That's an easy one: Python. The function declaration can force significant naming, but only for the caller.
Re:Where do argc and argv come from? by enriquto on Monday August 10, 2020 @03:41PM (#24113206)
I prefer to use c and v, to be more explicit.
Re:Where do argc and argv come from? by sillysaurusx on Monday August 10, 2020 @01:52PM (#24111991)
I was just as interested in the etymology.
Re:Where do argc and argv come from? by globuous on Monday August 10, 2020 @01:59PM (#24112079)
Me too, I once knew it but looked it up again earlier today out of curiosity. I was actually quite surprised to see this thread popup on HN a few hours later!
Re:Where do argc and argv come from? by srathi on Monday August 10, 2020 @03:23PM (#24113013)
I thought the same. Now I think it is simply argument-count and argument-values. Not sure if that is correct!