As someone who learned C first, when I came to Python everytime I read
about a new feature it was like, "Whoa! I can do that?!" Slicing, dir(),
getattr/setattr, the % operator, all of this was very different from C.
I'm curious -- what is everyone's favorite trick from a non-python
language? And -- why isn't it in Python?
Here's my current candidate:
So the other day I was looking at the language Lua. In Lua, you make a
line a comment with two dashes:
-- hey, this is a comment.
And you can do block comments with --[[ and ---]].
--[[
hey
this
is
a
big
comment
--]]
This syntax lets you do a nifty trick, where you can add or subtract a
third dash to change whether or not code runs:
--This code won't run because it's in a comment block
--[[
print(10)
--]]
--This code will, because the first two dashes make the rest a comment,
breaking the block
---[[
print(10)
--]]
So you can change whether or not code is commented out just by adding a
dash. This is much nicer than in C or Python having to get rid of """ or
/* and */. Of course, the IDE can compensate. But it's still neat :) 134 6095
"Joseph Garvin" <k0*****@kzoo.e du> ha scritto nel messaggio
news:ma******** *************** *************** @python.org... --This code won't run because it's in a comment block --[[ print(10) --]]
--This code will, because the first two dashes make the rest a comment, breaking the block ---[[ print(10) --]]
So you can change whether or not code is commented out just by adding a dash. This is much nicer than in C or Python having to get rid of """ or /* and */. Of course, the IDE can compensate. But it's still neat :)
python:
"""
print 10
"""
and
#"""
print 10
#"""
C++:
/*
print(10);
*/
and
///*
print(10);
//*/
?
Bye,
Enrico
Friday 24 June 2005 09:18 am Enrico wrote:
[...] --This code will, because the first two dashes make the rest a comment, breaking the block ---[[ print(10) --]]
[...]
python:
""" print 10 """
and
#""" print 10 #"""
C++:
/* print(10); */
and
///* print(10); //*/
?
I think the *trick* here was that if you had larger blocks you'd only have
to change one side of the comment, i.e. the opening line, to de-comment the
block without searching the end of it and commenting that out aswell.
Ciao
Uwe
Joseph Garvin wrote: I'm curious -- what is everyone's favorite trick from a non-python language? And -- why isn't it in Python?
Duff's device is a classic masterpiece of lateral thinking.
It is not possible in Python for many fundamental reasons, we are not
at risk.
Lorenzo Gatti
Uwe Mayer wrote: /* print(10); */
and
///* print(10); //*/
? I think the *trick* here was that if you had larger blocks you'd only have to change one side of the comment, i.e. the opening line, to de-comment the block without searching the end of it and commenting that out aswell.
Yes, but you can do that easily in C++ as well:
/*
print(10);
//*/
Change to:
//*
print(10);
//*/
I can't remember the exact pattern, but I remember using a
similar trick in BCPL where at least there was the excuse of not
otherwise having conditional compilation. C and C++ there is no excuse
for such tricks.
Google found Clive Feather's description of the BCPL trick at http://www.lysator.liu.se/c/clive-on-history.html:
I doubt it (though DMR may contradict me, of course). Every compiler I remember using allowed both // and /* */ type comment delimiters. Some also allowed | and \ to be used instead of /, so that || was also a comment-to-end-of-line, and \* ... *\ was an alternate block comment symbol. The latter was particularly useful, because it could be used to comment out blocks of code that included /* ... */ comments (as with C, comments do not nest). We used comments with vertical bars to implement a variety of conditional compilation:
|**||| IF normal code |*|||| ELSE alternate code |*|||| CANCEL ELSE more normal code |*|||| ELSE more alternate code |**||| ENDIF
By default, this would compile the "normal code". To switch to the "alternate code", the first line was changed to |**||* or |*|||| instead. Because this comment symbol was used, the code could contain normal comments and the "commenting-out" reverse comments I described above.
Check out lisp macros. Other languages have macro systems but none
compare in power to lisp's. They are so powerful in lisp because lisp is
the only language where the source code closely resembles its parse tree
(created within the compiler/interpreter).
Lowell
Joseph Garvin wrote: As someone who learned C first, when I came to Python everytime I read about a new feature it was like, "Whoa! I can do that?!" Slicing, dir(), getattr/setattr, the % operator, all of this was very different from C.
I'm curious -- what is everyone's favorite trick from a non-python language? And -- why isn't it in Python?
Here's my current candidate:
So the other day I was looking at the language Lua. In Lua, you make a line a comment with two dashes:
-- hey, this is a comment.
And you can do block comments with --[[ and ---]].
--[[ hey this is a big comment --]]
This syntax lets you do a nifty trick, where you can add or subtract a third dash to change whether or not code runs:
--This code won't run because it's in a comment block --[[ print(10) --]]
--This code will, because the first two dashes make the rest a comment, breaking the block ---[[ print(10) --]]
So you can change whether or not code is commented out just by adding a dash. This is much nicer than in C or Python having to get rid of """ or /* and */. Of course, the IDE can compensate. But it's still neat :)
Joseph Garvin wrote: As someone who learned C first, when I came to Python everytime I read about a new feature it was like, "Whoa! I can do that?!" Slicing, dir(), getattr/setattr, the % operator, all of this was very different from C.
I'm curious -- what is everyone's favorite trick from a non-python language? And -- why isn't it in Python?
Here's my current candidate:
So the other day I was looking at the language Lua. In Lua, you make a line a comment with two dashes:
-- hey, this is a comment.
And you can do block comments with --[[ and ---]].
This syntax lets you do a nifty trick, where you can add or subtract a third dash to change whether or not code runs:
So you can change whether or not code is commented out just by adding a dash. This is much nicer than in C or Python having to get rid of """ or /* and */. Of course, the IDE can compensate. But it's still neat :)
Off topic, but in C or C++ it's easier to do it using
#ifdef 1
....
#endif
Then you just have to change the 1 into 0 or vice versa. It also
prevents problems with nested comments.
Back on topic, the lack of such a construct in Python is actually one of
the very few things that bother me in the language. There are
work-arounds, of course; idle, for example, has a feature that prepends
a # to every line in the selection, or removes the # again. But not all
editors have such a feature, and even if they have it I still need to
select the block of code every time. Not that big a deal though.
--
If I have been able to see further, it was only because I stood
on the shoulders of giants. -- Isaac Newton
Roel Schroeven
> And you can do block comments with --[[ and ---]].
I am very happy not to have such "tricks" in Python.
Any other (useful) suggestions?
Claudio
"Joseph Garvin" <k0*****@kzoo.e du> schrieb im Newsbeitrag
news:ma******** *************** *************** @python.org... As someone who learned C first, when I came to Python everytime I read about a new feature it was like, "Whoa! I can do that?!" Slicing, dir(), getattr/setattr, the % operator, all of this was very different from C.
I'm curious -- what is everyone's favorite trick from a non-python language? And -- why isn't it in Python?
Here's my current candidate:
So the other day I was looking at the language Lua. In Lua, you make a line a comment with two dashes:
-- hey, this is a comment.
And you can do block comments with --[[ and ---]].
--[[ hey this is a big comment --]]
This syntax lets you do a nifty trick, where you can add or subtract a third dash to change whether or not code runs:
--This code won't run because it's in a comment block --[[ print(10) --]]
--This code will, because the first two dashes make the rest a comment, breaking the block ---[[ print(10) --]]
So you can change whether or not code is commented out just by adding a dash. This is much nicer than in C or Python having to get rid of """ or /* and */. Of course, the IDE can compensate. But it's still neat :)
Claudio Grondi wrote: And you can do block comments with --[[ and ---]].
I am very happy not to have such "tricks" in Python.
Any other (useful) suggestions?
Claudio
I'm glad and all that not everyone shares my enthusiasm over Lua's
trick, and I'm glad that C/C++ can do it, but the original issue was
non-python language tricks in general. Lets keep the thread on track.
So far we've got lisp macros and a thousand response's to the lua trick.
Anyone else have any actual non-python language tricks they like?
Yeesh.
"Joseph Garvin" <k0*****@kzoo.e du> schrieb im Newsbeitrag news:ma******* *************** *************** *@python.org...
As someone who learned C first, when I came to Python everytime I read about a new feature it was like, "Whoa! I can do that?!" Slicing, dir(), getattr/setattr, the % operator, all of this was very different from C.
I'm curious -- what is everyone's favorite trick from a non-python language? And -- why isn't it in Python?
Here's my current candidate:
So the other day I was looking at the language Lua. In Lua, you make a line a comment with two dashes:
-- hey, this is a comment.
And you can do block comments with --[[ and ---]].
--[[ hey this is a big comment --]]
This syntax lets you do a nifty trick, where you can add or subtract a third dash to change whether or not code runs:
--This code won't run because it's in a comment block --[[ print(10) --]]
--This code will, because the first two dashes make the rest a comment, breaking the block ---[[ print(10) --]]
So you can change whether or not code is commented out just by adding a dash. This is much nicer than in C or Python having to get rid of """ or /* and */. Of course, the IDE can compensate. But it's still neat :)
Am Fri, 24 Jun 2005 00:55:38 -0600 schrieb Joseph Garvin: As someone who learned C first, when I came to Python everytime I read about a new feature it was like, "Whoa! I can do that?!" Slicing, dir(), getattr/setattr, the % operator, all of this was very different from C.
I'm curious -- what is everyone's favorite trick from a non-python language? And -- why isn't it in Python?
Here's my current candidate:
[cut] This syntax lets you do a nifty trick, where you can add or subtract a third dash to change whether or not code runs:
I do it this way:
if 0: # Just for testing
print value
.....
You only need to change "if 0" to "if 1" and the code gets executed.
Thomas
--
Thomas Güttler, http://www.thomas-guettler.de/ This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Randy Given |
last post by:
What is your favorite Java development environment? What others have you
tried? What are some pros and cons of each? Thanks!
|
by: Vic Cekvenich |
last post by:
Here is my favorite tag: http://displaytag.sf.net and see examples (in upper
right). Grid, Sorting, nested, group, export, everything you like, plus it's
free.
Here is example code of how I used it:
http://cvs.sourceforge.net/viewcvs.py/basicportal/bPproj/bP/WEB-INF/pgs/forums/ArticleLst.jsp
You can view here run time by clicking here:
http://basebeans.com/do/channelsPg
|
by: Matthew Louden |
last post by:
I want to make a link that allows users to add my web site to the favorite
in IE. Anyone knows how to do that?
|
by: Scott McNair |
last post by:
What's your favorite bit of "short-cut" code that you use?
One of my favorite shortcuts I'll use when coding a page is to create a sub
along the lines of the following:
Sub Print(myText)
Response.Write myText & vbcrlf
End Sub
And then I use Print instead of Response.Write thru my code.
|
by: edunetgen |
last post by:
I have a Web Aplication.
I want an own image when an user adds me to favorite.
Thanks,
Edu
| |
by: zhaoyandong |
last post by:
One of my interviewers ask me
"Two favorite features of C++, and over-rated, and misued features"
Could anybody give me some advice on this?
Thanks
|
by: Les |
last post by:
In ancient times I had a desire to make a game and I
started to do so, I quickly found the project was beyond
the hardware's capability for that era (even in
assembler) and had to shelf the project. I retried in the
dark ages of computers, when I was in college, and got
much further before realizing the same thing was taking
place and shelved the project again. In hopes that this
new PC technology may yeild something interesting.
...
|
by: Jensen bredal |
last post by:
Hello,
I need to offer the visitors of my siste to add it to the favorite list but
only when it is ot there.
the code below:
window.external.AddFavorite(location.href, document.title)
add the link.
How can i see if the current link is already there?
|
by: clintonG |
last post by:
Want to give up your most treasured posession?
Post the URL for your favorite RegEx library you've found most useful for
validating form input.
<%= Clinton Gallagher
METROmilwaukee (sm) "A Regional Information Service"
NET csgallagher AT metromilwaukee.com
URL http://metromilwaukee.com/
URL http://clintongallagher.metromilwaukee.com/
|
by: fiversen |
last post by:
Hello,
I have a site for the collegue with a football winning game.
...fussball.html
there I redirect the user to an cgi-page
../f11.cgi
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |