4 ms·
> please note that `...` in the code below is the exact valid syntax, not “code omitted for a blog post” We need a standard for this. When I'm writing example
by happytoexplain 3y ago
> please note that `...` in the code below is the exact valid syntax, not “code omitted for a blog post”
We need a standard for this. When I'm writing example code, or redacting real code, I usually opt for an ellipses with spaces: `. . .`
- Pxtl 3y ago`...` is the standard. Don't make language features that use three-dot-ellipsis as a keyword. Just like don't make a language where "Hello world" is a special string with special significance, or where variables named foo, bar, baz, quux, or i have special meaning. I mean, it's nobody's fault but your own if you make a language feature that breaks industry conventions.
- elaus 3y agoBoth Java and JavaScript use the three-dot-ellipsis `...` (spread, varargs), so I'm not sure if it 'breaks industry standards' if Ruby uses them as well.
- Bootvis 3y agoR and its predecessor from 1988, S-Plus, as well.
- Pxtl 3y agoIt's a lot less confusing when it's only appearing in the function's parameter signature where you're declaring parameter names instead of the method body. It's not common to see educational snippets with ellipsis in the function signatures - they're usually in the body somewhere.
- DylanSp 3y agoGo uses it as well.
- happytoexplain 3y agoThree-dots is valuable real estate. I don't begrudge the various languages that use it - their use cases are usually worth it.
- epcoa 3y agoC has used ellipses for variable arguments ca 1985.
- __s 3y agoCan always use comments /* code */
- layer8 3y agoThe point of not using comments in those cases is to make it clear that this is not intended to be valid code.
- yebyen 3y agoI think that was the point. If it wasn't clear enough that your ellipses are meant to be showing some thing that was elided, put them in a comment. (In this case, the article used them as valid syntax and added a comment to clarify that this is indeed valid syntax!) If that isn't what you were doing, and it still isn't clear enough, add some text to the comment about what the "intentionally omitted part" was that you covered by an ellipsis.
- layer8 3y agoI think the root comment was about having a standard for denoting that some code is omitted. In that case, one doesn’t want the code sample to be syntactically valid, in order to unambiguously communicate that it is incomplete. Using comments, however, would typically make the code syntactically valid.
- tialaramex 3y agoSome languages (Rust and Swift for example) have expressions which are placeholders but won't actually work. let x = 5 + todo!("Complicated arithmetic expression"); ... is valid Rust, it typechecks, your syntax highlighter should be fine with it, it'll compile, but if that line ever executes, you panic immediately.
- layer8 3y agoPersonally I think execution time is too late.
- layer8 3y agoI’m sure we can come up with a language where three dots separated by spaces is valid syntax.
- deleted 3y ago[deleted]
- __s 3y agoBefunge
- masklinn 3y agoBrainfuck, as well. And technically Whitespace though that's maybe not as useful.
- unnah 3y agoA non-esoteric answer: in Forth dot prints the top of the stack and function calls are separated by spaces. Hence three dots separated by spaces is the simple and straightforward way to print the top three stack elements.
- Just_Harry 3y agoIt's valid in PowerShell, if "." is defined as a function: PS> function . {$Args} PS> . . . . The first dot is an operator which invokes a command in the current scope, the second dot is our command ".", and the third dot is passed to the command as a string.
- trealira 3y agoYou can also do this in Bash. $ .(){ "$@"; } # define function called "." $ . . . # nothing $ . echo hello hello $
- trealira 3y agoYou can write a function in Bash like this: .(){ :; } This creates a function called "." that does nothing. Then this is valid code: . . .
- arp242 3y agoI typically use [..trim..] or something to that effect. It's a habit I picked up because for people new to programming it's not at all obvious that ... or . . . isn't syntax, and just a word clarifies that (depending on who I'm talking to, I might expand that a bit to [..insert code here..] or some such).
- pphysch 3y agoIn Python, ... is an expression, so you can do def will_implement_later(): ... Which I prefer over "pass" in this case because the incompleteness is a little more intuitive. I think using asterisks for wildcardy-things like variadic args makes more sense too, coming from UNIX land.
- deleted 3y ago[deleted]