Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[split] Looping a Program
#5
(Oct-07-2018, 09:00 AM)perfringo Wrote: 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.

Never read any - but I have nearly 3 decades of programming experience and more than 6 years of Python experience, and I tell you that
Quote:Every if-statement must have an else
is pure undiluted bullshit.

I do not care much for 40+ years old
Quote:A classic General Motors analysis found that 50 to 80 percent of if statements should have had an else clause
either - 30% margin is so convincing.

Let me teach you a simple KISS imperative - Keep It Simple Stupid. Using a loop instead of indexing is extremely stupid - but not simple. I have no intention to continue this argument - but your arguments are pure demagoguery without any value.

I wish you would invest as much effort into learning proper Python as you invest in this argument. Intellectual laziness is not a commendable value. Hijacking threads for defending bad practices is not appreciated in programming community either,
Test everything in a Python shell (iPython, Azure Notebook, etc.)
  • Someone gave you an advice you liked? Test it - maybe the advice was actually bad.
  • Someone gave you an advice you think is bad? Test it before arguing - maybe it was good.
  • You posted a claim that something you did not test works? Be prepared to eat your hat.
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,610 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,588 Oct-09-2018, 12:14 AM
Last Post: micseydel
  [split] Coin Flip Program Crackity 5 4,893 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