Hacker Newsnew | past | comments | ask | show | jobs | submit | jibal's commentslogin

Zig doesn't have exceptions, it has error unions, so basically functions return either a value or an error code and the caller is forced by the language to note which was returned. And instead of RAII it has defer ... which of course can easily be forgotten or mis-scoped, so it's not safe.

> I sorely miss it in Python, JS and other languages. They keep me guessing whether a function will mutate the parent structure, or a local copy in those languages!

Python at least is very clear about this ... everything, lists, class instances, dicts, tuples, strings, ints, floats ... are all passed by object reference. (Of course it's not relevant for tuples and scalars, which are immutable.)


Everything being passed by object reference just means every case is equally unclear.

  answer = frobnicate(foo)
Will frobnicate destroy foo or not?

If you mean that it can modify it, you should say that. It can't destroy it as that term is generally understood.

No. It can’t. It can only destroy its own reference to foo, not the calling scope’s reference.

Right, but I don't care about the reference to foo (that's a low-level detail that should be confined to systems languages, not application languages) I was asking about the foo.

foo is a name. It's not at all clear what you mean by "the foo" ... the called function can modify the object referenced by the symbol foo unless it's immutable. If this is your complaint, then solve it with documentation ... I never write a function, in any language, that modifies anything--via parameter or in an outer scope--without documenting it as doing so.

> I don't care about the reference to foo (that's a low-level detail that should be confined to systems languages, not application languages)

This is not true at all. There's a big difference, for instance, between assigning a reference and assigning an object ... the former results in two names referring to the same object, whereas in the latter case they refer to copies. I had a recent case where a bug was introduced when converting Perl to Python because Perl arrays have value semantics whereas Python lists have reference semantics.

There seem to be disagreements here due entirely to erroneous or poor use of terminology, which is frustrating ... I won't participate further.


>> I sorely miss it in Python, JS and other languages. They keep me guessing whether a function will mutate the parent structure, or a local copy in those languages!

> Python at least is very clear about this ... everything, lists, class instances, dicts, tuples, strings, ints, floats ... are all passed by object reference. (Of course it's not relevant for tuples and scalars, which are immutable.)

Then let me just FTFY based on what you've said later:

Python will not be very clear about this ... everything, lists, class instances, dicts, tuples, strings, ints, floats, they all require the programmer to read and write documentation every time.


Right, but that reference is all the function has. It can’t destroy another scope’s reference to the foo, and the Python GC won’t destroy the foo as long as a reference to it exists.

The function could mutate foo to be empty, if foo is mutable, but it can’t make it not exist.


>> I sorely miss it in Python, JS and other languages. They keep me guessing whether a function will mutate the parent structure, or a local copy in those languages!

No mention of references!

I don't care about references to foo. I don't care about facades to foo. I don't care about decorators of foo. I don't care about memory segments of foo.

"Did someone eat my lunch in the work fridge?"

"Well at least you wrote your name in permanent marker on your lunchbox, so that should help narrow it down"


Then I don’t know what you mean. If you have:

  foo = open(‘bar.txt’)
  answer = frobnicate(foo)
  print(foo)
then frobnicate may call foo.close(), or it may read foo’s contents so that you’d have to seek back to the beginning before you could read them a second time. There’s literally nothing you can do in frobnicate that can make it such that the 3rd raises a NameError because foo no longer exists.

In other words,

>> I sorely miss it in Python, JS and other languages. They keep me guessing whether a function will mutate the parent structure, or a local copy in those languages!


  #!/usr/bin/env python3
  import inspect
  
  def frobnicate(unfrobbed: any) -> None:
      frame = inspect.currentframe().f_back
      for name in [name for name, value in frame.f_locals.items() if value is unfrobbed]:
          del frame.f_locals[name]
      for name in [name for name, value in frame.f_globals.items() if value is unfrobbed]:
          del frame.f_globals[name]
  
  foo = open("bar.txt")
  answer = frobnicate(foo)
  print(foo)

  
  Traceback (most recent call last):
    File "hackers.py", line 20, in <module>
      print(foo)
            ^^^
  NameError: name 'foo' is not defined
Be careful with the absolutes now :)

Not that this is is reasonable code to encounter in the wild, but you certainly can do this. You could even make it work properly when called from inside functions that use `fastlocals` if you're willing to commit even more reprehensible crimes and rewrite the `f_code` object.

Anyway, it's not really accurate to say that Python passes by reference, because Python has no concept of references. It passes by assignment. This is perfectly analogous to passing by pointer in C, which also can be used to implement reference semantics, but it ISN'T reference semantics. The difference comes in assignment, like in the following C++ program:

  #include <print>
  
  struct Object
  {
      char member{'a'};
  };
  
  void assign_pointer(Object *ptr)
  {
      Object replacement{'b'};
      ptr = &replacement;
  }
  
  void assign_reference(Object &ref)
  {
      Object replacement{'b'};
      ref = replacement;
  }
  
  int main()
  {
      Object obj{};
      std::println("Original value: {}", obj.member);
      assign_pointer(&obj);
      std::println("After assign_pointer: {}", obj.member);
      assign_reference(obj);
      std::println("After assign_reference: {}", obj.member);
      return 0;
  }

  $ ./a.out
  Original value: a
  After assign_pointer: a
  After assign_reference: b

Just like in Python, you can modify the underlying object in the pointer example by dereferencing it, but if you just assign the name to a new value, that doesn't rebind the original object. So it isn't an actual reference, it's a name that's assigned to the same thing.

ANYWAY, irrelevant nitpicking aside, I do think Python has a problem here, but its reference semantics are kind of a red herring. Python's concept of `const` is simply far too coarse. Constness is applied and enforced at the class level, not the object, function, or function call level. This, in combination with the pass-by-assignment semantics does indeed mean that functions can freely modify their arguments the vast majority of the time, with no real contract for making sure they don't do that.

In practice, I think this is handled well enough at a culture level that it's not the worst thing in the world, and I understand Python's general reluctance to introduce new technical concepts when it doesn't strictly have to, but it's definitely a bit of a footgun. Can be hard to wrap your head around too.


They seem to be using "destroy" in some colloquial sense, actually meaning "modify".

I'm truly not sure, but you're probably right.

Even if that were true (and it obviously isn't), what then would be the point of expending tremendous time and energy to "dam it off and keep it dry"?

These are alternative ways to keep the tents dry ... which entails that they were never soaked in the first place.

> A tent that’s been in a lake

The tents were never in the lake. A few inches of the campsite was in the lake at high water.

> sounds like a throwaway to me

Do you have any experience with this? I've been on trips where tents and even sleeping bags ended up in a river. They don't dissolve ...they can be dried in the sun. And a tent with a wet floor can be wiped down.

> “Just take the tents out of the water”.

Those words don't appear anywhere. Try looking at the actual words and not just your mental images.


> The tents were never in the lake. A few inches of the campsite was in the lake at high water. [...] Those words don't appear anywhere. Try looking at the actual words and not just your mental images.

I think some people are interpreting “campsite” as the literal space occupied by the tent’s ground sheet while you are interpreting it as the broader area - which in an organised institutional arrangement might be called the “campground”

To use an analogy, think of being in a partly flooded parking space vs parking lot

It makes sense that someone with the former interpretation - the tent ground sheet submerged by a few inches of water - would understand that the tent got soaked.


I've always understood "campground" to be a whole area open to camping with dozens or hundreds of campers. A campsite is where your group's claim is staked and the area you occupy including picnic tables, fires, etc--not just the tent.

I'm interpreting the word as what it means and how it is obviously being used. No one takes "campsite" to mean "the literal space occupied by the tent’s ground sheet" unless they are playing some silly sophistic game. Here is what it means (pick your own source ... they are all similar and none agrees with your definition):

"A campsite is a designated area where individuals can set up bedding, sleeping bags, or cooking equipment, such as stoves or fires. This definition encompasses any location that allows for sleeping or cooking, regardless of whether it includes a tent, lean-to, shack, or other structures."

And here's the Wikipedia description, which notes that the English "campsite" is equivalent to the American "campground", but that is broader and neither is so absurdly narrow as your words:

https://en.wikipedia.org/wiki/Campsite

> would understand that the tent got soaked

I already refuted this nonsense ... there is no reason to think from the OP's description that the tent got soaked.

> To use an analogy, think of ...

I don't need any help with thinking, especially from bad analogies that are flatly contradicted by the OP's description. What's the parking lot analogy to building dams?


I guess the term "tent" is pretty broad, this is what I see: [0], the cotton does not take being in water very well.

But I guess a synthetic ultra light tent will do better.

I also assumed the tents were already there when he arrived (complete assumption, but the term campsite conjures up a place with tents already there), and so must be of the more heavy more stationary kind.

Anyway, the point is, I also had this question: Where do you go when you mess up your tent like that? How can a dam in a layer of water make it dry? Don't you need a dam and then pump it dry.

This is going too far, I just wanted to defend the question. Maybe it's a cultural difference.

[0] https://duckduckgo.com/?t=ffab&q=de+waard+tent&ia=images&iax...


> Maybe it's a cultural difference.

It appears that you are confused with West European camping, which is where you drive two days to the south of France (most of which stuck in traffic), pay large amounts of money for a patch of perfectly flat grass where you are allowed to park your car and set up your tent. In a grid pattern with hundreds of other tents. Where there is a building nearby for toilets and showers. And a swimming pool plus live entertainment for the children.

OP appears to be talking about camping in nature.


A “campsite” is a relatively flat and relatively root/stump-free patch of dirt. That’s it. Also tents are generally not made out of the canvas material you linked that yurts and teepees might be made from.

Tents are generally made of a very wuick-drying, thin synthetic.

And like the other person said, this does make it seem like you’ve potentially never been camping but i don’t want to gatekeep the definition of “camping”. My version is carrying everything I need on my back for two weeks and walking 10-15 miles each day to the next campsite (read: “patch of dirt”, preferably near fresh water). Other people “camp” in RV’s though, so.


Have you tried hammock camping? I only tried it at a campground, so, maybe there are some downsides I missed for the real backpackers. But it was pretty cool to not care about roots, the flatness of my patch of ground, or anything like that.

I have! And i do love it. Hammocks generally benefit from very dense forest/tree cover just in case it’s raining!

Camping is just the bit about sleeping at night. I’d call your version hiking/walking/backpacking depending where I am.

Of course it's not.

"A campsite is a designated area where individuals can set up bedding, sleeping bags, or cooking equipment, such as stoves or fires. This definition encompasses any location that allows for sleeping or cooking, regardless of whether it includes a tent, lean-to, shack, or other structures."

I would note that camping also involves sitting in campchairs talking, reading, singing, etc.

And

> I’d call your version hiking/walking/backpacking depending where I am.

The hiking/walking/backpacking is what nerdsniper does between campsites:

> My version is carrying everything I need on my back for two weeks and walking 10-15 miles each day ==> to the next campsite <==

Despite his phrasing, he of course is not saying that hiking == camping.


Natural fiber canvas tents take to water about the same as your tee shirt does. Which is to say perfectly fine. Soaking them for a few days or even weeks shouldn't really bother them if the water is not warm and stagnant (like a nice clean lake). The biggest killer is storing them still wet.

> the term campsite conjures up a place with tents already there

You've never been camping. Ok.


I think you’re viewing this through your own cultural lens where camping can be totally solo (in the woods?)

In England, we can’t just pitch up a tent in the woods, we need to pay for a campsite where there’s other tents.

I suspect, from their description, this person is from a different country again, where camping may happen in large open steppe with lots of other yurts.


Nothing you wrote contradicts anything I said about camping. Someone else suggested that "campsite" just means the area covered by a tent and its groundcover, which is closer to the "mental image" of the other person who wrongly believes that tents got waterlogged, but is the arch opposite of yours. I've camped in the woods, on open steppes, and in designated camping areas in French and English towns. In each of those cases I brought my own tent, but I've also "glamped" and stayed in existing canvas-sided structures, from Yosemite to Mont St. Michel.

Also, this is about a campsite a few inches of which is in a lake, and people moving their tents. But apparently paying attention to the actual context is optional for some people.


I’m not trying to dispute your version of events. I’m just offering a suggestion of what teekert had in their mind when they thought of a campsite, to better help you see where the misunderstanding comes from. Given they replied with agreement, I hope I captured it accurately.

I also feel it was unnecessary to dismiss their experience as “not camping,” just because it was different to yours. It turns a learning opportunity for us all into a needlessly toxic argument.


None of this is responsive to my comment that you are responding to ... I find that quite toxic. And I will note that you wrote this toxic criticism:

> I think you’re viewing this through your own cultural lens where camping can be totally solo (in the woods?)

Again, your notion of my experience of camping does not come from anything I actually wrote ... that's quite toxic.

And recognizing the mere possibility of camping solo in the woods (which has nothing to do with anything in this thread--the OP was in a group on a lakeshore) has nothing to do with a "cultural lens".

That's the last I will say about this trivial matter.


> I think you’re viewing this through your own cultural lens where camping can be totally solo (in the woods?)

Allow me to correct myself: I meant to say I believed you were referring wild camping, away from a commercial site (either alone or part of a group).

> None of this is responsive to my comment that you are responding to ... I find that quite toxic.

You find it toxic that I won’t join you in an argument that only you want to have?

> Again, your notion of my experience of camping does not come from anything I actually wrote ... that's quite toxic.

I just woke up an hour ago. Did you find that toxic, too?


Yeah, this.

I’ve been camping, on trips that ranged from “park on the side of the road and set up a tent” to “hike four days carrying everything” and also “drive to campsite, walk into permanent managed tent”. Sounds like you’ve only done a more limited range of camping trips.

No, it doesn't sound like that at all, and you have offered no reason to think so. It's the other person who clearly has an extremely limited notion of camping: "the term campsite conjures up a place with tents already there" -- perhaps you have the two of us mixed up. And the OP said that they moved the tents, so ass-u-me ing that they were fixed structures is not rational.

Nowhere did he argue that. What he actually argued--poorly and offensively--is that it's "pretty obvious" that bronson has no experience writing Linux hardware drivers.

That makes no sense. The value of two bytes as a single number is strictly dependent on endianness, and there's no "convention" that can be assumed.

These aren't good faith questions.

> There is a word for people who cannot tolerate even the smallest difference of opinion: bigots.

No, that's not what that word means.

> all the same rights could be obtained through a domestic partnership or an out-of-state marriage. It was just a nominal dispute about what the word “marriage” means.

That too is not true.

> The fact that Mozilla didn't allow their CEO to deviate from the majority point of view on this issue (again, a minority viewpoint in California at the time!) revealed Mozilla to be a heavily politicized, extremely bigoted corporation, that puts ideological conformity first.

Not at all true.


periods are ignored in gmail addresses so there's no difference between firstlast@gmail.com and first.last@gmail.com

> I thought that a Gmail account that was first.last@gmail also allowed for email sent to firstlast@gmail (no period) to reach my inbox as well.

Yes, and you've received email that was addressed like that ... so what's your issue?

> I’ve wondered if this person has access to any of my information?

Yes, because "this person" is you.


Love Elinor Merle's snowflake earrings.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: