473,732 Members | 2,196 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

2 new comment-like characters in Python to aid development?

Had a thought that's grown on me. No idea if it's original or not- too
inexperienced in programming- but I guess there's no harm floating it
out there.

Python wins big on readability, and there's no doubt that context-
dependent text formatting in IDEs (keywords, strings, comments etc) is
a massive help too, therefore benefitting development and maintenance.
This idea is in a similar vein, especially for when scripts grow
large.

What if 2 new 'special' comment-like characters were added to Python?:
1. The WIP (Work In Progress) comment:

A '?' placed in the preceding whitespace of a line as a means of
quickly highlighting a line or block of code for special attention.
The interpreter simply ignores these characters, and executes the code
as if each WIP character wasn't there. The value-added comes from how
IDEs can exploit this to color the line or code block (in a
customisable fashion as with other context-dependent IDE formatting).

Thus...
?a=6 #This line gets highlighted.
?class MyClass: #This entire class gets highlighted.
def __init__(self):
self.val=3
?def MyFn(): #This entire function gets highlighted.
return 'x'
?for each in range(9): #This entire block gets highlighted.
print each

Simply delete the ? and the associated highlighting vanishes
immediately.
Indeed if the interpreter can tolerate one '?' then perhaps it can
also allow '??' and '???', letting the IDE color each differently for
some additional flexibility.

Applications...
Lets you highlight / un-highlight entire blocks with a single
keystroke: to record which part of a long script you're working on, or
which part needs development or optimization. IDEs could add
additional functionality if they chose: options to remove all wip
comments, or step through them, or even to automatically add WIP
comments (to highlight syntax errors, potentially infinite loops, or
rate-limiting code blocks, perhaps?)
2. The HALT comment:

A '!' at the start of a line, indicating the end of the script proper.
The interpreter would register this one, and ignore everything after
it, a bit like a sys.exit() call but also stopping it from picking
syntax errors after the HALT. IDEs could then 'grey out' (or 'yellow
out' or whatever) all following characters, including later HALT
comments.

Applications...
Lets you mask / unmask the tailing parts of a py script with a single
keystroke: potentially quite useful during the writing / testing phase
of coding when you might not want to run the whole thing, or as
another means of adding extensive comments to the end of a file. Could
also be rather handy in 'tutorial scripts' and the like...

E.g...
# Welcome to my Python Tutorial Script
my_string="Hell o World"
print my_string
! # Everything after this '!' is ignored and greyed out for now, but
when you're ready to move on to the next part of the tutorial script
just delete the '!' and run it again.
my_list=list(my _string)
print my_list
! # <-- delete '!' when ready, etc etc
my_list_reverse d=my_list[::-1]
print my_list_reverse d
As far as I can see, neither of these would break backwards
compatibility and, like the @ decorator, if you don't like it, you
wouldn't have to use it. I don't know enough about the guts of Python
to say much about ease of implementation, but it doesn't seem like it
would be too hard.

Personally I'd use these a lot, but I'm a rank amateur so maybe I just
don't develop code properly.
That's it. Useful? Pointless? Dangerous? Stupid?
Dave.

Mar 9 '07 #1
29 2368
En Fri, 09 Mar 2007 06:14:46 -0300, <db*******@goog lemail.comescri bió:
A '?' placed in the preceding whitespace of a line as a means of
quickly highlighting a line or block of code for special attention.
The interpreter simply ignores these characters, and executes the code
as if each WIP character wasn't there. The value-added comes from how
IDEs can exploit this to color the line or code block (in a
customisable fashion as with other context-dependent IDE formatting).
This could be implemented without new syntax: just make your editor
recognize some special comments, and apply the highlighting to the
following block. By example,

# XXX Remove this when FuruFaifa is fixed to always provide
# XXX the names in the same order
names.sort()
names.reverse()

if names==oldnames :
...

would highlight the first 4 lines (let's say, up to the next blank line or
dedent).
2. The HALT comment:

A '!' at the start of a line, indicating the end of the script proper.
The interpreter would register this one, and ignore everything after
it, a bit like a sys.exit() call but also stopping it from picking
syntax errors after the HALT. IDEs could then 'grey out' (or 'yellow
out' or whatever) all following characters, including later HALT
comments.
You accidentally type a ! somewhere, and your module stops working - not
so good :( and worse, hard to find.

I sometimes use '''this string marks''' to ignore whole blocks of code. It
works fine unless the block already contains the same kind of
triple-quoted string...
As far as I can see, neither of these would break backwards
compatibility and, like the @ decorator, if you don't like it, you
wouldn't have to use it. I don't know enough about the guts of Python
to say much about ease of implementation, but it doesn't seem like it
would be too hard.
The main problem with new syntax is breaking compatibility with older
versions, and I doubt it's worth the pain just for highlighting or playing
interactively, so you don't have a great chance of them being
implemented...

--
Gabriel Genellina

Mar 9 '07 #2
db*******@googl email.com <db*******@goog lemail.comwrote :
What if 2 new 'special' comment-like characters were added to Python?:
1. The WIP (Work In Progress) comment:
I use # FIXME for this purpose or /* FIXME */ in C etc.

I have an emacs macro which shows it up in bright red / yellow text so
it is easy to see and the company has a system which makes a web page
with a list of all the FIXMEs on.

FIXME is easy to grep for, language neutral and a lot of people use
something similar (eg XXX or TODO).
2. The HALT comment:
You can so this with triple quotes. ''' and ''' (if you normally use
""" """ for docstrings)

Python just ignores strings that lie around.

--
Nick Craig-Wood <ni**@craig-wood.com-- http://www.craig-wood.com/nick
Mar 9 '07 #3
Thanks for the thoughts.
This could be implemented without new syntax: just make your editor
recognize some special comments, and apply the highlighting to the
following block. By example,

# XXX Remove this when FuruFaifa is fixed to always provide
# XXX the names in the same order
names.sort()
names.reverse()
Yes I recognise that we can use existing comments for this purpose,
and if I was suitably gifted I guess I could try to make the IDE
recognise these 'special comments', and maybe even work out what block
they're meant to apply to. Of course I'll still argue that the WIP
character would be a more elegant, speedy and versatile alternative.

You accidentally type a ! somewhere, and your module stops working - not
so good :( and worse, hard to find.
By my reckoning it would be very very easy to find. Even if the IDE
wasn't greying out everything after it. And how often do you
accidentally mistype a ! at the beginning of a line?

I sometimes use '''this string marks''' to ignore whole blocks of code. It
works fine unless the block already contains the same kind of
triple-quoted string...
Indeed. Moreover those quotes have to be in pairs, so it's not exactly
a quick and dandy way of doing what I'd like.

The main problem with new syntax is breaking compatibility with older
versions...
Agreed. But both characters are currently disallowed in the positions
concerned, and in the proposal they're optional extras. This can't
stop old scripts from working, it can only stop new scripts from
working on old installations- just like any new feature.
>, and I doubt it's worth the pain just for highlighting or playing
interactively
Ah well there's the issue!
>, so you don't have a great chance of them being
implemented...
Obviously I like the idea, but I never hold out much hope that people
will agree with me!

Mar 9 '07 #4
Nick Craig-Wood a écrit :
db*******@googl email.com <db*******@goog lemail.comwrote :
> What if 2 new 'special' comment-like characters were added to Python?:
1. The WIP (Work In Progress) comment:

I use # FIXME for this purpose or /* FIXME */ in C etc.

I have an emacs macro which shows it up in bright red / yellow text so
it is easy to see
<ot>
Care to share this macro ?
</ot>
Mar 9 '07 #5
db*******@googl email.com wrote:
Of course I'll still argue that the WIP character would be a more
elegant, speedy and versatile alternative.
I don't think so. Those characters have no syntactical meaning and
would, IMHO, make the language "dirty".

Regards,
Björn

--
BOFH excuse #73:

Daemons did it

Mar 9 '07 #6
On 9 Mar 2007 02:31:14 -0800, db*******@googl email.com
<db*******@goog lemail.comwrote :
Thanks for the thoughts.
This could be implemented without new syntax: just make your editor
recognize some special comments, and apply the highlighting to the
following block. By example,

# XXX Remove this when FuruFaifa is fixed to always provide
# XXX the names in the same order
names.sort()
names.reverse()

Yes I recognise that we can use existing comments for this purpose,
and if I was suitably gifted I guess I could try to make the IDE
recognise these 'special comments', and maybe even work out what block
they're meant to apply to. Of course I'll still argue that the WIP
character would be a more elegant, speedy and versatile alternative.
But you are overloading the ? character for a purpose which it totally
was not meant for. What the character means really depends on what
person you are asking. To me, it means that what precedes it is
something someone or something does not know and wants to know the
answer to. To me, it really does not mean that what follows it is work
in progress.

Even if I could intuitively tell that a question mark represents a
work in progress, that information is not very useful. Similarly to
the "under construction" animated gifs that were popular on the web in
the mid 90-ties, the symbol does not convey any useful information.
WHY is it a work in progress? Is there something wrong with it?

?def foobar():
do stuff

The question mark does not leave me any the wiser. Now if you replace
that question mark with a comment:

# foobar() is buggy because it throws weird exceptions when x = 42.
def foobar():
do stuff

That gives me some useful information.

--
mvh Björn
Mar 9 '07 #7
>Those characters have no syntactical meaning...

?
Neither does # until you give it syntactical meaning. I must be
missing what you mean.
would, IMHO, make the language "dirty".
Well I'm not a big fan of decorators so I know how you must feel. But
# FIXME + a hack doesn't seem clean to me. And commenting off the
bottom half of a long script with triple quotes is ugly and a pain and
you can't indicate multiple alternate halt points as in the 'tutorial
script' example I gave.

Mar 9 '07 #8
>
Well I'm not a big fan of decorators so I know how you must feel. But
# FIXME + a hack doesn't seem clean to me. And commenting off the
bottom half of a long script with triple quotes is ugly and a pain and
you can't indicate multiple alternate halt points as in the 'tutorial
script' example I gave.
It's not a hack. Without an IDE, there won't be support for that anyway -
after all, you're about to highlight blocks and the like, how is that
supposed to work?

And besides that - you might not _like_ decorators, but they do have a
semantic. Just inserting "random" characters into the source code that one
has to overread doesn't make any sense, it just clutters the code.

With an proper IDE, you could make that tagging of yours bound to a simple
keystroke, and the IDE could store the tagging information separately. E.g.
eric3 offers some bookmark features, I presume something like your proposal
would be possible, too.
Diez

Mar 9 '07 #9
On Mar 9, 10:59 am, "BJörn Lindqvist" <bjou...@gmail. comwrote:
On 9 Mar 2007 02:31:14 -0800, dbhbar...@googl email.com

<dbhbar...@goog lemail.comwrote :
Thanks for the thoughts.
This could be implemented without new syntax: just make your editor
recognize some special comments, and apply the highlighting to the
following block. By example,
# XXX Remove this when FuruFaifa is fixed to always provide
# XXX the names in the same order
names.sort()
names.reverse()
Yes I recognise that we can use existing comments for this purpose,
and if I was suitably gifted I guess I could try to make the IDE
recognise these 'special comments', and maybe even work out what block
they're meant to apply to. Of course I'll still argue that the WIP
character would be a more elegant, speedy and versatile alternative.

But you are overloading the ? character for a purpose which it totally
was not meant for. What the character means really depends on what
person you are asking. To me, it means that what precedes it is
something someone or something does not know and wants to know the
answer to. To me, it really does not mean that what follows it is work
in progress.

Even if I could intuitively tell that a question mark represents a
work in progress, that information is not very useful. Similarly to
the "under construction" animated gifs that were popular on the web in
the mid 90-ties, the symbol does not convey any useful information.
WHY is it a work in progress? Is there something wrong with it?

?def foobar():
do stuff

The question mark does not leave me any the wiser. Now if you replace
that question mark with a comment:

# foobar() is buggy because it throws weird exceptions when x = 42.
def foobar():
do stuff

That gives me some useful information.

--
mvh Björn- Hide quoted text -

- Show quoted text -
perhaps another character would be preferable. '~' perhaps. As to what
you use the WIP character for- in my mind the purpose is to allow an
extra type/level of commenting over and above #, which is inherently
flexible. I could for example choose to use ? (or ~) for blocks I'm
still writing, ?? (or ~~) for blocks that are buggy, and ??? (or ~~~)
for blocks that work but could use optimization. It's a commenting
shortcut for me as the script's developer and its advantage over #
comments are speed or insertion/removal.
Ah but I can see I'm not winning anybody over. I shall graciously
retire!

Mar 9 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
4717
by: RSG | last post by:
Hi, Stupid question: how do I get an XSLT stylesheet to emit a comment into the HTML output file? Obviously this won't work; it's interpreted as a comment in the stylesheet: <template ...> ...
6
1581
by: frizzle | last post by:
Hi there I've built this user management system, using PHP & mySQL, to manage users that can comment on a certain site. Users have to be logged in to comment. Below each comment is (how original) the date of commenting, and the author. If the user changes his name in his profile, it changes everywhere. So what i mean is that the user_id is saved together with the comment. When the comment is pulled out, the query also gets the user's...
6
2422
by: cdrsir | last post by:
we can use 1) // my comments a 2) /* my comments b */ when we want to add some comments. I know some compilers just support the 2nd syntax, but normally both of these 2 syntaxs are supported by most of the compilers. But what are the difference for those two syntaxs in the sense for the compiler, if it support both. Is one of them will be processed faster?
0
3548
by: karen987 | last post by:
Could someone please tell me what code to add here? I have a weblog, with daily news which readers can add comments to, which are stored in a database. The form to add the comments is on an ASP page, (see code below). There is a small box, where readers can type a comment. What i want to do is to add a simple text editor, nothing too elaborate. A toolbar above the text area, should suffice, and it should be the same size as the box obviously. ...
12
4791
RedSon
by: RedSon | last post by:
Greetings all, The host I use does not let me have mysql so I am going to need to write a comment engine that uses flat files. Unless of course there are commenting solutions already available that do not use mysql. So now lets talk about how this is going to work... (your input is appreciated). I think we are going to need a couple things, an admin panel and the UI. The user is going to need a UI, so we will have a few fields, probably...
5
16567
helimeef
by: helimeef | last post by:
I designed a little PHP/MySQL forum (just for fun), and I have commenting set up and top threads on the homepage and whatnot. I'm relatively new to PHP, and this is the biggest project I've done, but the only problem is that I can't think up a way to let people reply to an already-posted comment... Anyway, I have a MySQL database called "forum", with three tables; "comment", "thread", and "user". I had the idea of creating a new field in the...
14
3877
by: daskumardilip | last post by:
how to remove comment from c source code.
1
2344
by: Nethra | last post by:
Hi... I am trying a program which convert the multiline comment type in a program to single line comment type ie. /*have a nice day */ to //have a //nice day
39
2873
by: polas | last post by:
Afternoon all. I was just wondering about this point - I have (generally) used // for commenting a single line in C, but from looking at code other people have written it seems many use /* */ (which I only use if my comment will be over multiple lines) - does one way have any advantages over the other, or is the style exactly that, a question of style? Cheers, Nick
3
10854
by: Richard | last post by:
Again, new to DB2. Trying to do something I can do in Sybase ASE. In any Sybase SQL script I can use /* */ to comment out a block of code. In the DB2 9.0 SQL Reference Manual V1 it says: Comments: SQL comments are either bracketed (introduced by /* and end with */) or simple (introduced by two consecutive hyphens and end with
0
8946
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8774
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,...
1
9235
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,...
0
9181
tracyyun
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...
0
8186
agi2029
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...
0
6031
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();...
0
4550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3261
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2180
bsmnconsultancy
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.