Home Artificial Intelligence Easy methods to Effectively Start Coding within the Era of ChatGPT Rule number one: how you can appropriately ask inquiries to ChatGPT Rule number 2: all the time seek advice from the documentation Rule number 3: troubleshooting and debugging Examples in Python Conclusions

Easy methods to Effectively Start Coding within the Era of ChatGPT Rule number one: how you can appropriately ask inquiries to ChatGPT Rule number 2: all the time seek advice from the documentation Rule number 3: troubleshooting and debugging Examples in Python Conclusions

0
Easy methods to Effectively Start Coding within the Era of ChatGPT
Rule number one: how you can appropriately ask inquiries to ChatGPT
Rule number 2: all the time seek advice from the documentation
Rule number 3: troubleshooting and debugging
Examples in Python
Conclusions

The very first thing to learn is how you can appropriately ask ChatGPT the best questions.

After I began learning to program I assumed that developers were nerdy individuals who began to program at 5 years old and had an enormous knowledge of programming, having in mind all of the code they needed.

And you recognize what? I couldn’t be more fallacious. Here’s a harsh truth:

  1. A whole lot of developers began to learn to program of their 20s and 30s.
  2. The vast majority of developers work by searching stuff on Google and StackOverflow (and today, they ask inquiries to ChatGPT).

So, to begin with, should you’re beginning to program without delay don’t be ashamed to spend lots of time on Google, StackOverflow, or ChatGPT. It’s completely normal. You simply have to know how you can appropriately achieve this since you’ll never keep in mind all of the code you wish (you’ll keep in mind just the methods and functions you utilize probably the most, in fact).

Anyway, the difference between today and the 90s is that within the 90s the Web barely existed, so developers hadn’t all of the support which have today due to global communities, forums, web sites, and AI.

This led developers to learn to program the hard way, not rarely spending days to resolve an issue (finding a bug or finding the best piece of code).

Today, you’ve gotten a fantastic opportunity: you’ve gotten a senior developer available 24/7 and that is ChatGPT, but you’ve gotten to treat it like so, not like an oracle.

So, here’re some guidelines on how it is best to appropriately query ChatGPT should you’re beginning to program today:

  1. . Before using ChatGPT, my advice is that it’s essential learn the fundamentals first for an easy reason: ChatGPT often gives you code that it’s essential refactor, for any reason. Which means that it’s essential have prior knowledge of coding: you may’t just ask ChatGPT to create some code for you to resolve an actual problem. The sort of developers that can be replaced by AI is correctly those that ask inquiries to ChatGPT with no prior (or with poor) knowledge of coding. So, before prompting, get a course and begin practicing.
  2. . Once we’re children we’re very curious and our questioning makes us grow because we’re genuinely curious about the answers. That is the frame of mind we’d all the time have as Software Professionals: having a solution and just copying and pasting it won’t make us learn how you can program. If the code we get from ChatGPT works it is best to, not less than, ask it to clarify the code it used and why it’s used it. As a beginner, the truth is, your role is to learn in order that in the longer term you should use ChatGPT less and be more independent: for this reason it is best to all the time ask for code explanations.
  3. . When programming, we are able to solve the identical problem with different methods: for this reason it doesn’t make any sense to only ask ChatGPT to generate some random code. We absolutely have to ask it something related to a project we’re making or an issue we want to resolve.
  4. . As a generative AI system, ChatGPT is susceptible to errors. While today with GTP-4 models we’ve seen excellent improvements, there are still errors within the code. Also, errors are sometimes as a consequence of the prompts which may be incomplete or in some way misleading. For this reason, even when the code works, you may’t blindly trust the answers and want to grasp deeply the code you get.
The training workflow while coding. Image by Creator.

I created the above image for some content I wrote on Linkedin some months ago (oh, and by the best way: here’s my profile if you would like to get in contact).

Here’s the moral of the story: no matter where you’re trying to find the data it’s essential solve your coding issue, you usually have to read the documentation. At all times.

That is the Gospel for us Developers/Data Professionals. We all the time have to read the documentation.

In reality, if we discover a snippet of code that may solve an issue we’re facing, if we do not understand the code we won’t have the ability to generalize the code we’re using. Which means that in the longer term we can’t have the ability to resolve an analogous problem because we haven’t learned anything: we just copied and pasted the code.

And this is especially true with ChatGPT, especially because sometimes it invents libraries that don’t exist. Yes, you read it right: sometimes ChatGPT invents libraries.

We’ve to say that, due to GPT-4, OpenAI made lots of improvements. But within the last months, it happened to me not less than a few times that ChatGPT invented some unexisting libraries.

And you recognize how we are able to see if a library doesn’t exist? There are some possibilities:

  1. You recognize what you’re doing and asking ChatGPT. But this may occur after months of practice if you gained some experience.
  2. You get the code from ChatGPT, read it, try to grasp it, ask ChatGPT for some explanation on the usage, go surfing to read the documentation and find no reference.
  3. You are attempting the code and get an error, and also you learn your lesson the hard way. But don’t be ashamed of it: it happened even to me.

Remember: there’s nothing bad within the urge to resolve an issue as soon as possible. So, you may even try the code and get an error. Well, the reality is that the error may even be as a consequence of a foul prompt, and this happens very incessantly.

Anyway, remember: in case your job is completed since you solved the actual problem, then, please: go read the documentation for more understanding. Chances are you’ll also discover that your issue could be solved with less code.

ChatGPT is a fantastic tool even for troubleshooting and debugging your code. Nonetheless, even on this case, you should learn how you can use it appropriately, should you’re starting your learning-how-to-code path.

To start with, should you’re using an IDE like VS CODE or PYCHARM to program, then use their debugging features. They’ve integrated debugging features due to which you may just push a button, and so they debug your code, showing you (eventual) troubles in your code.

At this stage, but even later (I’m still using this method), one of the best idea is to follow this path:

  1. Write your program.
  2. Debug your code within the IDE.
  3. Read the eventual warnings you get from the debugger if something doesn’t work.
  4. Paste the warnings on Google should you don’t know how you can solve them.
  5. Paste the warnings on ChatGPT if Googling doesn’t solve your problem.
  6. Paste the entire code in ChatGPT should you still have not solved your issue.
  7. Go read the documentation if the previous point solved your issue.

I’ll never get drained to repeat it: we have to seek advice from the documentation when Google or ChatGPT solve a problem we’ve with our code.

So, please: don’t blindly paste the code into ChatGPT asking to go looking for troubles in your code: first, strive to search out them on your personal the hard way because that is the one way you’ll learn things. There’s no other solution to learn stuff, and I do know you recognize it.

Finally, an : do not forget that ChatGPT works within the cloud and, also, it might use your prompts to coach its algorithms (with recent changes in the info privacy usage it is best to have the ability to vary the settings, and select not to provide consent to OpenAI to coach its algorithms together with your prompts).

Nonetheless, a crucial thing to take into account is to not paste into ChatGPT code to debug with sensible information: as a consequence of data breaches and other related security issues, it’s higher to maintain yourself protected.

Now, let’s see some examples of prompts we should always write on ChatGPT to learn how you can code.

I’ve asked ChatGPT the next: “How can we print in Python?

Here’s the reply:

In Python, you should use the print() function to display output on the console or terminal. The print() function takes a number of arguments and prints them as text.

Listed below are a number of examples of using the print() function:

Printing an easy string:

print("Hello, world!")

>>>

Hello, world!

2. Printing variables:

name = "Alice"
age = 25
print("My name is", name, "and I'm", age, "years old.")

>>>

My name is Alice and I'm 25 years old.

3. Printing multiple arguments separated by a selected character:

print("One", "Two", "Three", sep="-")

>>>

One-Two-Three

4. Printing formatted output using f-strings (Python 3.6 and above):

name = "Bob"
age = 30
print(f"My name is {name} and I'm {age} years old.")

>>>

My name is Bob and I'm 30 years old.

These are only a number of examples to show the usage of the print() function. You’ll be able to pass various sorts of objects as arguments to the print() function, and it’ll robotically convert them right into a string representation before printing.

Now, a matter: which method would you utilize?

Exactly, here’s the issue! The prompt we made was too generic so ChatGPT gave us a generic answer.

So, here’s one other lesson: . One could possibly be: “I actually have an inventory with some strings in Python: how can I print them efficiently?”

Here’s the reply:

To print an inventory of strings efficiently in Python, you should use the join() method together with the print() function. The join() method concatenates all of the strings within the list right into a single string using a specified separator. Then you definately can simply pass this concatenated string to the print() function to display it.

Here’s an example:

my_list = ['Hello', 'World', 'Python']

# Using join() to concatenate the strings within the list with an area separator
result = ' '.join(my_list)

# Printing the result
print(result)

>>>

Hello World Python

In the instance above, the join() method joins the strings in my_list using an area ' ' because the separator. Then the print() function is used to display the concatenated string.

By utilizing the join() method, you avoid the overhead of multiple calls to the print() function, leading to more efficient string concatenation and printing.

And here we’re: with a selected query we got a selected answer.

And now, you recognize what we’ve to do? Yes, you recognize: if we don’t understand how it really works, we’ve to ask ChatGPT some more explanations on the join() method. We are able to do it in the identical chat like so: “What’s the strategy ‘join()’ and the way does it work?”

And here’s the reply:

The join() method is a string method in Python that concatenates the weather of an iterable (similar to an inventory, tuple, or set) right into a single string using a specified separator. It returns a recent string that incorporates all the weather joined together.

The syntax for using the join() method is as follows:

separator.join(iterable)

Here, separator is the string that can be used to affix the weather, and iterable is the gathering of elements to be joined.

When join() is named on a separator string, it iterates over the weather of the iterable and concatenates them, inserting the separator string between each pair of elements. The separator shouldn’t be added at the start or the top of the resulting string.

Here’s an example as an example how the join() method works:

my_list = ['Hello', 'World', 'Python']

# Using join() to concatenate the strings within the list with an area separator
result = ' '.join(my_list)

print(result)

>>>

Hello World Python

In the instance above, the join() method is named on the separator string ' '. It iterates over the weather of my_list and concatenates them, inserting an area between each pair of elements. The resulting string 'Hello World Python' is then printed.

It’s value noting that the join() method is a more efficient solution to concatenate multiple strings in comparison with using the + operator in a loop. It is because join() internally optimizes the means of concatenation, leading to higher performance, especially when coping with a lot of strings.

Now, at this point, it is best to do other two things:

  1. Trying to find “join() Python” on Google and see another examples and skim the documentation.
  2. As we are able to see, ChatGPT tells us that this method is more efficient than using the + operator with a loop to resolve this problem. It is best to proceed the chat and ask for an example (then, read the documentation that will include the subsequent examples).

LEAVE A REPLY

Please enter your comment!
Please enter your name here