-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
[New Concept Exercise]: Functions in Python #3121
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
Comments
Comments for discussion ported from original issue: @BethanyG Any idea for what you want to see for the exercise here? Any analogous exercise you might want transcribed from another track? I can start looking at the tracks I'm familiar with. Nothing comes to mind right now. Originally posted by @bobahop in #2353 (comment) Rust uses lasagna, but we use lasagna for basics. Go uses Booking Up For Beauty, but that also makes significant use of string formatting, so it might not be as focused for functions as desired. Originally posted by @bobahop in #2353 (comment) @bobahop there are a few things to note here:
I'll add some thoughts/ideas to the new issue. Originally posted by @BethanyG in #2353 (comment) |
So this wouldn't be a port of the tasks, but if you like the Secrets on the Elixir track looks like it has a good setup, and that the tasks might be adaptable to Python scenarios. They will probably need a lot of replacing, but could work. Likewise, Library Fees could be adapted, but the instructions and introduction to the exercise would have to be amended to cover whatever New Passport could be adapted, but not to use Pizza Pricing holds some promise, but again - the tasks would have to be re-done for Python. Really, you could use just about any story here. The problematic bit is coming up with 4-6 tasks that cover the concept. If sudden purpose-built inspiration strikes, I'll update. |
Sound like many promising leads. I'm a bit remiss on researching the tracks, as I'm also slowly slogging through crafting interpreters. Very slowly. |
I like the dystopian DMV idea... a lot. |
Creating an "Adventures at the DMV" story would have the added benefit of carrying a story credit (and a legendary badge). 😉 Inspiration: https://www.youtube.com/watch?v=ONFj7AYgbko. You could even borrow (with credit) the premise from Zootopia - the DMV is populated by Sloths, and any mistake not only sends you to a new line...but then you have to deal with the Sloths. Might need some brief background on what DMV stands for, but I think globally most people understand horrible bureaucracy, so it wouldn't take much. |
I think I'll start to work up some files tomorrow. And you're getting author credit, too, since it's your story idea. What do you think of the title "Della's Delays at the DMV"? |
"Della's Delays at the DMV" is great. A personal ambition of mine is to have as many alliterative concept exercise titles as possible. |
I just looked over the learning objectives and concepts and I winced a bit at |
Apologies. Had some things to take care of this afternoon, so am late with replying to things.
I think for the exercise, it's important to provide students the opportunity to practice using both And I think for the instructions/introduction, it would be great to put cautions in, and examples of why it can be a bad idea. Although my thinking here is that if the task or tasks set up a "proper" or "good" use case, the students will more than likely find the foot-gun, and that will convey a really good lesson, about scope, using the keywords, AND about how the Python ethos is to say "we are all adults here, so you need to think through your choices, Python's not going to do that for you." It does seem somewhat "unfair" to set up students like that ... but I don't know that we teach them fluency by hiding the warts of the language. While we do do that to some extent early on, by the time students are getting ready to feed functions to other functions, use recursion, nest functions, and all the other goodness that comes along with FP paradigms in Python, they should have a working sense of caution, and be building a sense of why endless mutability can be problematic. So my thought is that maybe there is a task that has them reach out and modify/update a ...and thinking out loud here..... I don't know if we want to consider a |
While stale, this issue should remain open. |
Arg. This keeps falling off the radar. Will do better this week! |
I still think it is a good idea, but I am just focused on other things. I also have an idea for a practice exercise, but that is on the back burner as well. |
I won't have time before this weekend I don't think - but I am going to PR turning off the stale bot, since none of us on the track are moving very fast these days (which is OK!). Right now, if we comment on anything and 22 days pass, the critter wakes up and flags things as abandoned. It's starting to not be useful, so. 😀 |
This issue describes how to implement the
functions
concept exercise for the Python track.There is an outdated issue for this exercise with some discussion. It can be found here
The related concept documents can be found here.
✅ Getting started
If you have not yet created or contributed to a concept exercise, this issue will require some upfront reading to give you the needed background knowledge. Some good example exercises to look at in the repo:
💡Example Exercises💡 (click to expand)
We also recommend completing one or more of the concept exercises (they're called "learning exercises") on the website.
Please please read the docs before starting.
Posting PRs without reading these docs will be a lot more frustrating for you during the review cycle, and exhaust Exercism's maintainers' time. So, before diving into the implementation, please go through the following documents:General Contributing Docs:
Documents on Language Tracks and Concept Exercises
🎯 Goal
This
functions
concept exercise is meant to teach a deeper understanding and use offunctions
in Python. It should also explain how Python treats/views functions (as callable objects), and dig into some of the features that make Pythonfunctions
unique.💡Learning objectives
scopes
andnamespaces
global
andnonlocal
keywords and when to use themreturn
, and the difference between explicit and implicitreturn
None
functions
areobjects
in Python, and that they havetypes
functions
can be assigned to variables, used in expressions, and stored in various data structures such asdicts
orlists
functons
that are assigned to variables, used in expressions, and stored in different data structures.functions
that are/can be nested inside one anothercallable object
.function object
is created by afunction definition
.🤔 Concepts
callable objects
first-class functions
global
nested functions
nonlocal
return
,implicit return
,explicit return
scope
function attributes
🚫 Topics that are Out of scope
Concepts & Subjects that are Out of Scope (click to expand)
named parameters
(these can be touched on if needed)default parameters
(these can be touched on, if needed)arbitrary parameters
*args & **kwargs
keyword-only arguments
/
and*
for requiring parameter typesfunctions-as-arguments
(this can be mentioned, but shouldn't be required for the exercise)functions-as-returns
(_this can be mentioned, but will be covered in-depth inhigher-order functions
)closures
(these will be covered in a different exercise)decorators
(these will be covered in a different exercise)functools.wraps
(this is used mostly for decorators)functools
(this will get its own exercise)comprehensions
generators
lambda
,anonymous functions
(these will be covered in a different exercise)recursion
↩️ Prerequisites
These are the concepts/concept exercises the student needs to complete/understand before solving this concept exercise. Since
functions
is a "meta" topic, these will probably need to be adjusted to fit the parameters of the exercise.Prereqs (click to expand)
basics
bools
comparisons
lists
list-methods
loops
numbers
strings
string-methods
📚 Resources for Writing and Reference
Resources (click to expand)
nonlocal
Statement (Python Docs)global
Statement (Python Docs)Exercise Ideas & Stories
Should you need inspiration for an exercise story, you can find a collection here. You can also port an exercise from another track, but please make sure to only to include tasks that actually make sense in Python and that add value for a student. Remove/replace/add tasks as needed to make the concept clear/workable.
📁 Exercise Files to Be Created
File Detail for this Exercise (click to collapse)
Exercise
introduction.md
For more information, see Exercise
introduction.md
about
or theintroduction
). The summary does need to have enough information and examples for the student to complete all the tasks outlined for this concept exercise.Exercise
instructions.md
For more information, see
instructions.md
Instructions for an exercise usually center on a story that sets up the code challenge to be solved. You can create your own story, or fork one from the ones listed here. Please make sure to give credit to the original authors if you use a story or fork an exercise.
Exercise
Exemplar.py
SolutionFor more information, see exemplar implementation.
This file should not use syntax or datas structures not introduced in this exercise or in this exercise's prerequisites. It will be used as an "ideal" solution for the challenge, so make sure it conforms to PEP8 and other formatting conventions, and does not use single letter variable names. It should also include proper module and function-level docstrings. However, it should NOT include typehinting or type aliases.
<Exercise>.py
(Stub) for ImplementationFor more information, see stub implementation.
This file should provide the expected function names imported for testing, and optionally TODO comments and or docstrings to aid the student in their implementation. TODOs and docstrings are not required.
<Exercise>_Test.py
FilesFor more information, see Tests.
Additionally, please note that Python associates exercise tasks to tests via a Pytest Marker, and uses
unittest subtests
as a form of test paramaterization. See the test file forLittle Sisters Vocab
for examples of how these techniques work.Exercise
Hints.md
For more information on writing hints see
hints.md
Exercise Metadata Files Under
.meta/config.json
For more information on exercise
.meta/
files and formatting, see concept exercise metadata files.meta/config.json
- see this link for the fields and formatting of this file..meta/design.md
- see this link for the formatting of this file. Please use the Goal, Learning Objectives,Concepts, Prerequisites and , Out of Scope sections from this issue.♾️ Exercise Metadata - Track
For more information on concept exercises and formatting for the Python track
config.json
, please seeconfig.json
. The trackconfig.json
file can be found in the root of the Python repo.You can use the below for the exercise UUID. You can also generate a new one via exercism configlet, uuidgenerator.net, or any other favorite method. The UUID must be a valid V4 UUID.
9f38f70d-48f4-4934-ae6e-d8277ede8edc
🎶 Implementation Notes
As a reminder, code in the
.meta/examplar.py
file should only use syntax & concepts introduced in this exercise or one of its prerequisite exercises. We run all ourexamplar.py
files through PyLint, but do not strictly require module docstrings. We do require function docstrings similar to PEP257. See this concept exerciseexemplar.py
for an example.Please do not use comprehensions, generator expressions, or other syntax not previously covered either in the introduction to this exercise, or to one of its prerequisites. Please also follow PEP8 guidelines.
In General, tests should be written using
unittest.TestCase
and the test file should be named<EXERCISE-NAME>_test.py
.PyTest custom mark
to link test cases to exercise task numbers.unittest.subtest
to parameterize test input where/when needed.Here is an example testfile that shows all three of these in action.
While we do use PyTest as our test runner and for some implementation tests, please check with a maintainer before using a PyTest-specific test method, fixture, or feature.
Our markdown and JSON files are checked against prettier . We recommend setting prettier up locally and running it prior to submitting your PR to avoid any CI errors.
🆘 Next Steps & Getting Help
If you'd like to work on this issue, comment saying "I'd like to work on this"
(there is no real need to wait for a response, just go ahead, we'll assign you and put a[claimed]
label on the issue).The text was updated successfully, but these errors were encountered: