- [Instructor] So far on our journey
to increase our vibe coding productivity and quality
to be deliberate developers,
we focused on making our code work correctly
and improving its internal structure.
But there's another crucial layer to quality software,
making it understandable to others as well as
to our future selves.
Documentation is often seen as a chore,
something that you do after the real work is done.
So today we're going to treat that as part
of the design process.
You'll learn how to use Gemini
to rapidly generate high quality drafts of doc strings
and templates, turning a tedious task into a fast,
consistent and creative one.
Let's start with a common scenario.
A piece of code that works perfectly
but has zero documentation.
And here it is, it's a black box.
This Python function processes a list of dictionaries,
filters out inactive users, and then formats
the remaining names.
I can kind of sort of read the code to figure out
what it does, but that takes time and mental energy.
A good doc string could tell me at a glance,
and instead of writing one from scratch,
I'm going to ask Gemini to help me create
a professional grade draft.
So let's switch to Gemini.
So now I'm in Gemini and I'm going to prompt it.
I'll put in this code act as a senior Python developer,
your task is to write a comprehensive doc string
for the following Python function.
And if you remember the Python function
that we had a moment ago, I'm just going to paste
that in to the prompts.
And then I'm going to give Gemini some clear instructions
about what I wanted to do.
Include the Google style for the doc string format,
include a clear one line summary of what the function does,
detail the arguments explaining the expected type
and structure, and describe the return value.
So Gem and I will start processing it
and start working on it.
Now, when I check out the results,
I can see some very interesting feedback.
Note that I was very specific about the format
and that specificity is key to getting consistent results.
And let's take a look at what we got back.
It's pretty good, maybe 90% of the way there.
It's correctly identified the argument type
and the return value and the overall purpose.
But as a deliberate developer,
I'm not just going to accept this, I want to refine it
and I might add a detail
that only the original author would know.
In that case, in the arc section,
I've identified that inactive users
or those that don't have a name,
are actually silently ignored.
So what I'm going to do is I'm going to copy this
and I'm going to put it into Visual Studio,
and then I'll edit it from there.
So now I'm back in Visual Studio
and I'll paste in the code that I got from Gemini,
and I'll make a note in the ARGs of the thing
that I've noticed that didn't show up earlier,
and that was,
note that inactive users
are those without a name will be silently ignored
and save that out.
This small addition can add some crucial context
that wasn't immediately obvious just from reading the code.
The AI gave us speed and it gave us structure,
but that final layer
of human insight from knowing the overall code base
is vital and is important.
Now, for the powerful part,
we can use this high quality human refine doc string
as an example or a template
to enforce consistency across our entire project.
So for example, say I have another function,
something like this one calculate order totals.
I could use that previous function as an example.
Let's take a look at the prompt for that.
I'll switch back to Gemini.
So I'm going to work with Gemini
and tell it that I want to doc string for a function.
And I'm going to start by saying, I want you to act
as a Python developer.
Generate a doc string for a new function first.
Here is an example of the exact style I want you to follow.
This is my template,
and I'm going to paste in that code that we had created earlier
and then we had updated with doc strings.
So here's that code
and we can see our doc string that we've created,
including the ARGs and even the little note
that I put on the ARGs.
This is called Few shot prompting, where you give an example
to an LLM like Gemini.
Okay, so now I'm going to say using that exact style
as a template,
generate a doc string for this other function.
So this is the calculate order totals
that has no doc string in it.
And let's run it.
And here's the output.
Calculate new order totals has a new doc string on it,
and I can copy that and let's paste it into VS Code
so we can look at it.
Here's the old function.
I'll paste in the new one with our doc string.
And we can see that we now have a doc string in the same
format as the previous one, showing us the ARGs
and the returns, and giving us a description upfront
about that function.
So from this we can see vibe coding isn't just about code.
It can also help with your documentation.
And with Gemini,
we could generate high quality drafts very quickly,
and then we could use those drafts
as templates for others.
So the job transforms from being a technical writer
to being a thoughtful editor and prompt engineer.
You can accelerate that process, maintain high standards
with explicit templates,
and always ensure that your code
is clear and understandable.
Now, this was for the doc string at the top of your code.
What about inline comments? Well, we'll explore that next.