Skip to content

Dynamic/static arrays: Fix some doc errors #629

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed

Dynamic/static arrays: Fix some doc errors #629

wants to merge 2 commits into from

Conversation

AndrewGodfrey
Copy link

Split out the less controversial fixes from #623:

Fix some documentation errors, around dynamic array semantics and static array syntax.

  • Add a note about the need for assumeSafeAppend in order to regrow a dynamic array.
  • Add examples for static arrays as lvalues (for copying and setting).
  • Soften an over-strong claim in ctod.dd.
  • Also tweak some heading levels and such.

Fix some documentation errors, around dynamic array semantics and static array syntax.
- Add a note about the need for assumeSafeAppend in order to regrow a dynamic array.
- Add examples for static arrays as lvalues (for copying and setting).
- Soften an over-strong claim in ctod.dd.
- Also tweak some heading levels and such.

s[] = t; // the 3 elements of t[3] are copied into s[3]
s[] = t[]; // the 3 elements of t[3] are copied into s[3]
d[] = t; // the 3 elements of t are copied into d (unlike "d = t")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would add a note what d = t does. You could add an example, e.g.:

int[] e = new int[3];
e = t;
e[0] = 10;
assert(t[0] == 10);

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, it was already mentioned on line 160 ("a = s" there), and this section is focused on copying.
I agree with a few points you may be implicitly making:

  1. Sample code should use assert in this way to 'demonstrate' things, especially surprising things like this one.
  2. These semantics are surprising enough to warrant more exposition.
  3. This documentation is grouped by operation (such as copying), which only answers half of the questions a reader will have. The other half is: Given a particular syntax, like "array1 = array2;" what does it mean for a dynamic array vs. a static array?

I haven't decided what solution to propose, but here's a possible thought:
Perhaps this should be divided into a few sections - first considering only copying/assignment,
next adding concatentation and 'array-setting', and finally more esoteric things like prefix vs. postfix notation.
And then within each of the first two sections, explore all the interactions, in both 'directions' (that is, ordered by syntax and ordered by semantics).

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it's already mentioned, then no need to worry. Looks good then.

@ghost
Copy link

ghost commented Dec 5, 2014

Sorry for allowing this to go stale. Could you rebase this, and then I'll merge it? Thanks for the work so far!

@andralex
Copy link
Member

andralex commented Jan 8, 2015

LGTM but please rebase.

@andralex
Copy link
Member

closing until we hear back from @AndrewGodfrey. Alternatively, @AndrejMitrovic are you familiar enough with this to take it over?

@andralex andralex closed this Jan 11, 2015
@AndrewGodfrey
Copy link
Author

I can't say right now when I'll have time.
Possibly in the next week or two.


From: Andrei Alexandrescumailto:notifications@github.com
Sent: ‎1/‎7/‎2015 5:23 PM
To: D-Programming-Language/dlang.orgmailto:dlang.org@noreply.github.com
Cc: Andrew Godfreymailto:andrew@gfreys.com
Subject: Re: [dlang.org] Dynamic/static arrays: Fix some doc errors (#629)

LGTM but please rebase.


Reply to this email directly or view it on GitHub:
#629 (comment)

@andralex
Copy link
Member

sounds good thx - reopen when ready

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants