This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

Depreciated or not depreciated?

Website and forum-related announcements and discussion, and anything else that doesn't fit in the above forums.
Post Reply
User avatar
Alchera
Revered One
Posts: 3344
Joined: Mon Aug 11, 2003 12:42 pm
Location: Ballarat Victoria, Australia
Contact:

Depreciated or not depreciated?

Post by Alchera »

Just a question (after a meaningful discussion) based on a friend's faith in Komodo (Windows syntax thingie).

Anyway.... according to Komodo the following is "depreciated":

Code: Select all

if {$vbl == 1} {
   puts "vbl is one"
} {
   puts "vbl is not one"
}
I personally prefer the above to the following (according to Komodo) current (non-depreciated code):

Code: Select all

if {$vbl == 1} {
   puts "vbl is one"
} else {
   puts "vbl is not one"
}
The purpose of this post is to determine if the first example is indeed depreciated (as the Komodo user believes) as I cannot find one piece of documentation actually stating this.

Any input is (as always) gratefully accepted. :D
Add [SOLVED] to the thread title if your issue has been.
Search | FAQ | RTM
User avatar
DragnLord
Owner
Posts: 711
Joined: Sat Jan 24, 2004 4:58 pm
Location: C'ville, Virginia, USA

Post by DragnLord »

I have seen nothing that indicates the code is depreciated. As long as it works (with it does), I wouldn't worry about it. :)
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

If dropping "else" is deprecated, wouldn't the dropping of "then" also be deprecated?

Sofar, I have not read anything suggesting either being deprecated, with perhaps the exception of multiple-cases coding:

Code: Select all

if {$vbl == 1} then {
   puts "vbl is one"
} elseif {$vbl == 2} then {
   puts "vbl is two"
} else {
   puts "vbl is other than one or two"
}
Here you can drop both "then" and "else" (but not "elseif"), but not the "elseif". Still not quite as saying dropping either is deprecated.

Also, this qoute from the 8.5.0 if manpage:
Remember, expressions can be multi-line, but in that case it can be a good idea to use the optional then keyword for clarity:

Code: Select all

if {
   $vbl == 1 || $vbl == 2 || $vbl == 3
} then {
   puts "vbl is one, two or three"
}
Would suggest "then" and "else" are mainly intended to make the code more readable, and has no "syntax function"
NML_375
User avatar
Alchera
Revered One
Posts: 3344
Joined: Mon Aug 11, 2003 12:42 pm
Location: Ballarat Victoria, Australia
Contact:

Post by Alchera »

Thank you both for that information; very much appreciated. :D

I was up until the wee small hours trying to find any reference to this and all to no avail.

I am wary of any (authoritative) statement emanating from a Windows software company especially when it refers to an Open Source project (that I suspect they'd like to make closed source if they could).

:mrgreen:
Add [SOLVED] to the thread title if your issue has been.
Search | FAQ | RTM
User avatar
De Kus
Revered One
Posts: 1361
Joined: Sun Dec 15, 2002 11:41 am
Location: Germany

Post by De Kus »

The tcl 8.5 docu doesn't prefer either of the 2 possibilities. To quote the documentation:
The then and else arguments are optional “noise words” to make the command easier to read.
And I'd take that literally. They are meant to make code easier to read, that means either always use them or never. ^-^

Code: Select all

if {
   $vbl == 1 || $vbl == 2 || $vbl == 3
} then {
   puts "vbl is one, two or three"
}
Is imho a really really bad idea, because the eye catchs

Code: Select all

if {} {
   $vbl == 1 || $vbl == 2 || $vbl == 3
} else {
   puts "vbl is one, two or three"
}
which isn't meant at all. I'd suggest to write something like the following:

Code: Select all

if {$vbl == 1 || $vbl == 2
      || $vbl == 3} {
   puts "vbl is one, two or three"
}
I split the line, because I wanted to start the 2nd line of the condition with a || or && to don't make the impression of just wrong indention. This follows a often used rule to use the double indention for multiple line for a single command.

PS: I personally would always use else, unless you want to write some quick code which just works but doesn't have to be maintained.
De Kus
StarZ|De_Kus, De_Kus or DeKus on IRC
Copyright © 2005-2009 by De Kus - published under The MIT License
Love hurts, love strengthens...
Post Reply