Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[split] Looping a Program
#4
(Oct-06-2018, 08:31 AM)volcano63 Wrote: those are poor excuses for showing bad coding practices Since you don't care to learn best practices, I hope my comments will be useful as a warning to those trying to learn who stumble upon your code.

First, I would like to make clear what we are talking about.

I think that your solution going directly to the object is superior to looping through objects to find needed one. No dispute here.

You are right that there was unnecessary repetition of string. I agree with that.

You consider else clause redundant. I accept this opinion and no dispute here as well.

However, I disagree with "those are poor excuses for showing bad coding practices" regarding else clause.

Following are my explanations (not excuses)

1. Programs are written for humans to read. I am as instance of human class find it easier to read. I have met other instances of that class who share this viewpoint.

2. Explicit is better than implicit. There is no performance penalty for machine to have 'redundant' branch. Explicitly stating that flow will either break or continue can be considered better than doing it implicitly.

3. Programming is expressing ideas. "In reality, programming languages are how programmers express and communicate ideas — and the audience for those ideas is other programmers, not computers. The reason: the computer can take care of itself, but programmers are always working with other programmers, and poorly communicated ideas can cause expensive flops. In fact, ideas expressed in a programming language also often reach the end users of the program — people who will never read or even know about the program, but who nevertheless are affected by it." (Kings Day Speech by Guido van Rossum). I think that using 'redundant for computer' else clause in flow control helps me to communicate my idea better to other humans (but by all means, I am not a programmer)

4. As mentioned earlier, there are some literature which have something to say about else-clause in if statement:

Learn Python 3 the Hard Way: A Very Simple Introduction to the Terrifyingly Beautiful World of Computers and Code, First Edition by Zed Shaw, Exercise 36. Designing and Debugging (average rating 4.5 on safaribooksonline.com)

"Every if-statement must have an else. If this else should never run because it doesn’t make sense, then you must use a die function in the else that prints out an error message and dies, just like we did in the last exercise. This will find many errors."

Code Complete by Steve McConnell, 2nd edition, chapter 15, Using Conditionals (average rating 4.7 on safaribooksonline.com)

"Consider the else clause. If you think you need a plain if statement, consider whether you don't actually need an if-then-else statement. A classic General Motors analysis found that 50 to 80 percent of if statements should have had an else clause (Elshoff 1976).

One option is to code the else clause—with a null statement if necessary—to show that the else case has been considered. Coding null elses just to show that that case has been considered might be overkill, but at the very least, take the else case into account. When you have an if test without an else, unless the reason is obvious, use comments to explain why the else clause isn't necessary"

(I do realise that what is obvious to one person may be not so obvious to another person)

It seems to me that there are circumstances and examples where using redundant-for-computer else clause can not be considered as bad coding practice.
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply


Messages In This Thread
[split] Looping a Program - by volcano63 - Oct-05-2018, 09:26 PM
RE: [split] Looping a Program - by micseydel - Oct-09-2018, 12:26 AM
RE: Looping a Program - by perfringo - Oct-06-2018, 05:12 AM
RE: Looping a Program - by volcano63 - Oct-06-2018, 08:31 AM
RE: Looping a Program - by perfringo - Oct-07-2018, 09:00 AM
RE: Looping a Program - by volcano63 - Oct-07-2018, 09:26 AM
RE: Looping a Program - by perfringo - Oct-08-2018, 11:31 AM
RE: Looping a Program - by stullis - Oct-08-2018, 02:38 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [split] Results of this program in an excel file eisamabodian 1 1,612 Feb-11-2022, 03:18 PM
Last Post: snippsat
  Need help looping this program JakobeTheKid 1 2,128 May-19-2019, 05:30 AM
Last Post: SheeppOSU
  Looping a Program DavidRobinsons 4 3,591 Oct-09-2018, 12:14 AM
Last Post: micseydel
  [split] Coin Flip Program Crackity 5 4,895 Sep-25-2017, 03:48 AM
Last Post: Crackity

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020