Create a slice of string

I noticed you were using range on the same thing (rt) in both the outer and inner loop. Write lots of code. Read lots of other people’s code. After a while, things like this will look suspicious. :wink:

1 Like

Don’t take this too seriously, but here is another version of the program with more descriptive variable names:

I’m not saying I chose ideal names, but see how you can read it more easily and information about what the variable holds and its type are included in the name? The variable name is descriptive.

They help the code to be more “self-documenting”, so while reading the code, the names of variables, types, and functions help you or someone else to understand it.

In many cases, it may be excessive to include information about the variable’s data type in its name, but at least you can use whole words or obvious abbreviations (like “max” for “maximum”) to name the variable and show what the variable is being used for.

It’s easy to use cryptic variable names and have your program full of them. (It may take a few seconds to think of a better name, which is “inconvenient” in a feverish coding session.) But think of the long term. After you finish your program and go on to other things, what if you look at it again after a few years? Will you understand it? If you can’t, don’t expect other people to.

3 Likes

Why is that?

I did so and you are correct

Interesting

Suspicious? Why?

Interesting.
You might notice that every time I go back to a question, I review from top to bottom. This often results in me asking the same question twice. Sorry about that

Thanks for this and the foregoing information.

I saved all that

Cheri, if you really interested, I recommend you to read Clean Code from Robert Cecil Martin. Its explain pretty good that concept about declaring variables and a lot of good pratices that will help you out in the future to maintain a consistent and readable code.
Even if you feel a kind of advanced, go chapter to chapter and always feel free to ask here or in private messages, where you find more confortable, about your doubts.
When I read this book, my future self always thanks me for being very atentious with my personal projects and stuff.

Or Am I being pretty straightforward on the learning curve? :thinking:

When I searched for the book, I found this: Summary of 'Clean code' by Robert C. Martin · GitHub

I saved it, and I believe it will be very helpful to me in the future. One of these days, I will order the book.
Thanks.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.