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

Tag updates #2817

Merged
merged 5 commits into from
Dec 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bot/resources/tags/codeblock.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
embed:
title: "Formatting code on discord"
title: "Formatting code on Discord"
---
Here's how to format Python code on Discord:

Expand Down
24 changes: 24 additions & 0 deletions bot/resources/tags/equals-true.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
embed:
title: "Comparisons to `True` and `False`"
---
It's tempting to think that if statements always need a comparison operator like `==` or `!=`, but this isn't true.
If you're just checking if a value is truthy or falsey, you don't need `== True` or `== False`.
Copy link
Member

Choose a reason for hiding this comment

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

truthy or falsey

Should we expand on what these mean?

Copy link
Contributor

Choose a reason for hiding this comment

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

I lean towards no. It would make the scope of the tag a lot bigger and is not necessarily relevant to the reader. As is, newbies can make an assumption about what they mean and still understand the rest or they can ask what they mean. Either are good outcomes.

```py
# instead of this...
if user_input.startswith('y') == True:
my_func(user_input)

# ...write this
if user_input.startswith('y'):
my_func(user_input)

# for false conditions, instead of this...
if user_input.startswith('y') == False:
my_func(user_input)

# ...just use `not`
if not user_input.startswith('y'):
my_func(user_input)
```
This also applies to expressions that use `is True` or `is False`.
4 changes: 2 additions & 2 deletions bot/resources/tags/range-len.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
embed:
title: "Pythonic way of iterating over ordered collections"
---
Iterating over `range(len(...))` is a common approach to accessing each item in an ordered collection.
Beginners often iterate over `range(len(...))` because they look like Java or C-style loops, but this is almost always a bad practice in Python.
```py
for i in range(len(my_list)):
do_something(my_list[i])
```
The pythonic syntax is much simpler, and is guaranteed to produce elements in the same order:
It's much simpler to iterate over the list (or other sequence) directly:
```py
for item in my_list:
do_something(item)
Expand Down