Skip to content
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

What is a trap and what isn't? #1523

Closed
AlexDaniel opened this issue Sep 3, 2017 · 10 comments
Closed

What is a trap and what isn't? #1523

AlexDaniel opened this issue Sep 3, 2017 · 10 comments
Labels
meta RFCs, general discussion, writing style, repository organization, etc. trap

Comments

@AlexDaniel
Copy link
Member

From #1163 (comment):

A trap would be something that makes you think that your code works, but in reality there are edge cases that may lead to disastrous results. We should delete some sections from language/traps that do not match this definition.

@AlexDaniel AlexDaniel added docs Documentation issue (primary issue type) meta RFCs, general discussion, writing style, repository organization, etc. and removed docs Documentation issue (primary issue type) labels Sep 3, 2017
@AlexDaniel
Copy link
Member Author

AlexDaniel commented Sep 3, 2017

Here's a list that we can use to mark (✓) things that should stay:

Variables and Constants

  • Constants are Compile Time

Objects

  • Assigning to attributes
  • BUILD prevents automatic attribute initialization from constructor arguments

Whitespace

  • Whitespace in Regexes does not match literally
  • Ambiguities in Parsing
  • Block vs. Hash slice ambiguity
  • Reduction vs. Array constructor ambiguity
  • Less than vs. Word quoting/Associative indexing

Captures

  • Containers versus values in a Capture

Cool tricks

  • Strings are not Lists, so beware indexing
  • Lists become strings, so beware .index()ing
  • Lists become strings, so beware .contains
  • Numeric literals are parsed before coercion
  • Getting a random item from a List

Arrays

  • Referencing the last element of an array
  • Typed Array parameters

Strings

  • Quotes and interpolation
  • Strings are not iterable
  • .chars Gets the Number of Graphemes, not Codepoints
  • All Text is Normalized By Default
  • Allomorphs Generally Follow Numeric Semantics

Operators

  • Junctions
  • String Ranges/Sequences
  • Topicalizing Operators
  • Fat Arrow and Constants

Regexes

  • <{$x}> vs $($x) : Implicit EVAL

Common Precedence Mistakes

  • Adverbs and Precedence
  • Ranges and Precedence
  • Loose boolean operators
  • Exponentiation Operator and Prefix Minus
  • but in List Construction

Subroutine and method calls

  • Named Parameters
  • Argument Count Limit

Input and Output

  • Closing Open File Handles and Pipes
  • IO::Path Stringification
  • Splitting the Input Data Into Lines

Exception Handling

  • Sunk Proc

Using Shortcuts

  • The ^ twigil
  • Using » and map interchangeably

Scope

  • Using a once block

@AlexDaniel
Copy link
Member Author

Note that there may be other reasons we can call something a trap. Think wisely before removing stuff to resolve this ticket. When it doubt, leave the text in. If it saves somebody, great! If not, well, maybe people will learn something interesting when they read it.

@rafaelschipiura
Copy link
Contributor

I think we should move instead of removing them, to a tricks page.

@stmuk
Copy link
Contributor

stmuk commented Sep 3, 2017

Also using the term "gotcha" might be useful

See https://en.wikipedia.org/wiki/Gotcha_(programming)

@AlexDaniel
Copy link
Member Author

Or maybe call it “Perl 6 Pitfalls” analogously to BashPitfalls.

@zakame
Copy link
Member

zakame commented Sep 4, 2017

This reminds me of Chapter 24, "Common Practices", of Programming Perl, 3rd Ed. There's a "Frequently Ignored Advice" section there that outlines several traps, as well as other traps brought on when moving from C, Shell, and previous Perls.

@coke
Copy link
Collaborator

coke commented Oct 24, 2017

I thought the traps were supposed to be "if you came from another language and expected FOO, sorry it's not quite like that". I always expected the traps would eventually actually be tied to the language it's a trap for, and this information would be moved to the lang-to-perl6 specific pages.

@toolforger
Copy link

toolforger commented Oct 24, 2017

How about splitting the document in two?

One for traps. The things with the edge cases that nobody thinks about. Lieing in wait for the moment that they can do the maximum possible damage, secretly praying to Murphy, God of Breakage, that it will be Remote Code Execution As Root.

One for surprises. Things that work differently than expected, but in a clearly visible fashion, and you instantly get unexpected behaviour. One-time surprises if you will: You learn to avoid them by falling to them, once.

@AlexDaniel
Copy link
Member Author

OK, after coming back to this after a while… I think that anything that results in a compile-time error with a helpful error message is not a trap. For example, Referencing the last element of an array should be moved elsewhere. That is, if the thing does not compile, and in fact even tells you what's wrong, then there's no trap.

In other words, all items that are current not marked with ✓ have to go. Hopefully to another page where that discussion is more appropriate.

@AlexDaniel
Copy link
Member Author

I am happy with the current page, and IMO this issue outlived itself. I think if someone wants to change anything they'll have to start a new issue, this one is a bit overloaded already.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
meta RFCs, general discussion, writing style, repository organization, etc. trap
Projects
None yet
Development

No branches or pull requests

6 participants