473,761 Members | 2,455 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
29 2370
But all of them are clear on how they work: they affect one line, or have a
bracket style like /* */ and thus demark clearly what they affect. Even
someone not fluent in the language in question will quickly grab what they
mean.
There's nothing remotely fuzzy about how wip or halt comments would
work, nor anything unclear about what they would affect. Nor are they
remotely difficult to explain. They just haven't been employed before,
to my knowledge, even though the underlying effects seem to be a
reasonably common requirement.
But the key-difference is that the comment in python has a meaning for the
interpreter - ignore this.
OK that is true. But it's true for the halt comment as well.

The ? has no meaning. It only has a meaning for an editor.
So it _does_ have meaning! I'm sorry I just don't buy into this kind
of abstract programming ideology, and I never really have. I don't
care what the interpreter finds meaningful and neither, on a day to
day basis, do most users, I'm sure. It seems like the same kind of
aesthetic ideology that leads lots of programmers to feel repulsed by
Python's whitespace block delimiting. There's a more important
principle being missed by them: the human factor. The guy or gal who's
actually _using_ this stuff. BTW I don't mean to imply that you're not
thinking about human readability / useability, just that you don't
seem to be arguing from that basis.

Not in my opinion -
;p

Would if I could!

Well, grab eric3, it's written in python, and teach it to do so! It's an
exercise in python then :)
I may do that. Thanks for bringing it to my attention.

What we're talking about here is a form of 'alternate commenting
style'. With the IDE's cooperation it'd work on whole blocks at once,
it would highlight without disrupting the code concerned (at least the
way I'm envisaging it), it would be versatile (could probably be used
for as big a variety of purposes as the # comment), and yes, it'd be
persistent, which is how it would be different from any IDE-based
highlighting.

I think you contradict yourself here. On the one side, you want it not
disturbing to the eye, yet it should be highlighted, so it will be directly
noticed by that same eyes.
You misread me. I wasn't talking about visual disturbance but 'code
disturbance'. Let me rephrase..
"..it would highlight without causing the highlighted code to be
ignored by the interpreter.."

it _is_ an disturbance. And with an IDE that stores such information in
e.g. project metainformation , you can even have the persistence, without
the disturbance and without altering python.
So it's fine and wonderful to add a massive chunk of code to IDEs to
introduce jargon-strewn behaviour that newbies have little hope of
comprehending yet alone taking advantage of, and which will inevitably
behave differently in any IDE that does get around to providing it?
But adding two special characters to the core language is 'messy'?

I can't argue with your aesthetic dislike of the proposed syntax, it's
just the reasoning you use to support your stance that doesn't ring
true to me! (I trust no offense is caused.)

Mar 9 '07 #21
>The ? has no meaning. It only has a meaning for an editor.

So it _does_ have meaning! I'm sorry I just don't buy into this kind
of abstract programming ideology, and I never really have. I don't
care what the interpreter finds meaningful and neither, on a day to
day basis, do most users, I'm sure. It seems like the same kind of
aesthetic ideology that leads lots of programmers to feel repulsed by
Python's whitespace block delimiting. There's a more important
principle being missed by them: the human factor. The guy or gal who's
actually _using_ this stuff. BTW I don't mean to imply that you're not
thinking about human readability / useability, just that you don't
seem to be arguing from that basis.
I certainly do. Because a comment is always a comment. If you happen to
have a multi-line comment (in python that is) that spans more than a
page of your current terminal, you clearly will see it as such when
piped through less - a frequent tool for looking into code of libraries
for example. At least for me, and I guess some other coders as well.

But a tiny ? or !, the latter one massively changing the semantics of
the displayed code? I'm not too positive that this will be getting the
proper attention needed when comprehending the code.

Even the multiline-comments of C are easier, because they feature an
end-mark. Which for one _is_ easier to implement, thus even "less" might
implement some syntax hi-lighting based on it (if the terminal supports
that, that is. I've been doing my fair share of last-minute hacking
through malconfigured ssh-connections in vi, no syntax-highlighting
whatsoever) - while it is much less probable that "less" will grow a
full blown python parser just for the sake of hi-lighting a !-prefixed
block of code.
FWIW, I'm totally convinced that the addition of this feature to the
interpreter itself would be a minor operation that wouldn't cause much
headache from a implementation POV. It's just I don't buy into its
usefulness.
>
>>What we're talking about here is a form of 'alternate commenting
style'. With the IDE's cooperation it'd work on whole blocks at once,
it would highlight without disrupting the code concerned (at least the
way I'm envisaging it), it would be versatile (could probably be used
for as big a variety of purposes as the # comment), and yes, it'd be
persistent, which is how it would be different from any IDE-based
highlightin g.
I think you contradict yourself here. On the one side, you want it not
disturbing to the eye, yet it should be highlighted, so it will be directly
noticed by that same eyes.

You misread me. I wasn't talking about visual disturbance but 'code
disturbance'. Let me rephrase..
"..it would highlight without causing the highlighted code to be
ignored by the interpreter.."

What do you mean by code-disturbance? Programming is usually something
that needs carefully assembled sequences of characters, with some
seemingly minor interpunction characters becoming extremly meaningful.
And you want to add to that the complexity of something that has _no_
meaning at all - for the language. To me that is a disturbance. Clearly
a matter of taste, though.
>
>it _is_ an disturbance. And with an IDE that stores such information in
e.g. project metainformation , you can even have the persistence, without
the disturbance and without altering python.

So it's fine and wonderful to add a massive chunk of code to IDEs to
introduce jargon-strewn behaviour that newbies have little hope of
comprehending yet alone taking advantage of, and which will inevitably
behave differently in any IDE that does get around to providing it?
But adding two special characters to the core language is 'messy'?
Adding two characters to the language from which one's only purpose is
to support the introduction of jargon-strewn behavior that newbies have
little hope of comprehending let alone taking advantage of, and which
will inevitable behave differently in any IDE that does get around
providing it.

I couldn't say it better. It is exactly my point: the ? is _nothing_
without an IDE, where _none_ of them is forced to interpret and
represent it by any means. Yet still you want to add it? Sorry, I can't
buy that.

Besides, the whole purpose of IDEs is to add massive chunks of code to
e.g. analyze class structures, show syntactic errors even before the
code is run and so on... so if you accept that editing code is more than
poking with a hex editor on your hard disk image, I fail to see the
problem of adding such chunks of code if it is feasible.
I can't argue with your aesthetic dislike of the proposed syntax, it's
just the reasoning you use to support your stance that doesn't ring
true to me! (I trust no offense is caused.)
Certainly not. And I don't intend to cause offense myself!

Diez
Mar 9 '07 #22
pyhelp,

I set up a table in SQLite3.

While running other modules I want to know if a
table exists.

SQL has a command "List Tables" but I don't think
SQLlite3 has this command.

I've tried
cursor.execute( "select * from debtor where key
is not null ")

The table debtor does not exist so I get
"OperationalErr or"
which I want to trap with try/except or some other
way.

However python 2.5,
except OperationalErro r:
responds with
"OperationalErr or" is not defined.

Ideas on how to determine if a table exists would
be welcome.

jim-on-linux
Mar 9 '07 #23
On 3/9/07, jim-on-linux <in*****@verizo n.netwrote:
However python 2.5,
except OperationalErro r:
responds with
"OperationalErr or" is not defined.
I believe that needs to be spelled
except sqlite3.Operati onalError:
do_something()

--
Jerry
Mar 9 '07 #24
On Friday 09 March 2007 13:10, Jerry Hill wrote:
On 3/9/07, jim-on-linux <in*****@verizo n.net>
wrote:
However python 2.5,
except OperationalErro r:
responds with
"OperationalErr or" is not defined.

I believe that needs to be spelled
except sqlite3.Operati onalError:
do_something()

--
Jerry
Thanks,
except sqlite3.Operati onalError:
works for me.

jim-on-linux
Mar 9 '07 #25
Bruno Desthuilliers <br************ ********@wtf.we bsiteburo.oops. comwrote:
>>>Nick Craig-Wood a ecrit :
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
Thanks you both.
For what it's worth, sufficiently recent versions of emacs python-mode
have this built in.

-M-

Mar 9 '07 #26
On 09 Mar 2007, Matthew Woodcraft wrote:
Bruno Desthuilliers <br************ ********@wtf.we bsiteburo.oops. comwrote:
>>>>Nick Craig-Wood a ecrit :
>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
>Thanks you both.

For what it's worth, sufficiently recent versions of emacs
python-mode have this built in.
Is this with xemacs python mode or have you downloaded python mode
separately from emacs? I've got the latest emacs cvs (well a week
old) and it doesn't have it, or is it very,very recent?

Robert
--
La grenouille songe..dans son château d'eau
Links and things http://rmstar.blogspot.com/
Mar 9 '07 #27
db*******@googl email.com wrote:
But # is 'only a comment sign' as well, and equally meaningless to
the interpreter.
No! "#" means "disregard everything until EOL" to the interpreter.
Your proposed highlighting character means exactly nothing to the
interpreter. Get the difference?
But it's still part of the language, very very
useful and I profit from its existence every day.
See above, comment tokens do have syntactical meaning.
If you can highlight an entire block with a single character,
won't there be _less_ visual clutter than the current way of
achieving the same effect with # comments?
You can't "highlight" something with comments. It will become a
comment and not be executed.

Some editors may display comments in a different manner, yes. But
that's not what comments are for -- the different display is just
for convenience.
>So - if you want that feature, patch your editor of choice to
deal with that comments, make them added and removed with a key
stroke, whatever - be my guest.

Would if I could!
Why don't you grab a good editor ...
What we're talking about here is a form of 'alternate commenting
style'. With the IDE's cooperation it'd work on whole blocks at
once,
I know editors that can select blockwise without any special
characters in the source, just by keystrokes ...
it would highlight without disrupting the code concerned (at
least the way I'm envisaging it), it would be versatile (could
probably be used for as big a variety of purposes as the #
comment),
Any kind of highlighting is absolutely different from comments.
and yes, it'd be persistent, which is how it would be
different from any IDE-based highlighting.
(Why shouldn't other ways of highlighting be persistent? Metadata
exists.)
I think that'd be most useful. You don't. So far nobody else here
does either, and I've not persuaded anybody differently. Fair
enough!
Agreed.

Regards,
Björn

P.S.: More and more I'm getting the impression that everybody should
first learn to program with a most simple editor. The typical
Java+Eclipse start is wrong, IMHO ...

--
BOFH excuse #225:

It's those computer people in X {city of world}. They keep stuffing
things up.

Mar 9 '07 #28
jim-on-linux schrieb:
pyhelp,

I set up a table in SQLite3.

While running other modules I want to know if a
table exists.

SQL has a command "List Tables" but I don't think
SQLlite3 has this command.
I think "list tables" is a mysqlism
>
I've tried
cursor.execute( "select * from debtor where key
is not null ")
FROM sqlite_master SELECT name WHERE type='table';

cheers
Paul

Mar 10 '07 #29
On Mar 9, 10:30 am, Nick Craig-Wood <n...@craig-wood.comwrote:
dbhbar...@googl email.com <dbhbar...@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 <n...@craig-wood.com--http://www.craig-wood.com/nick
Vim will highlight the following comments too:
#FIXME
#TODO
#XXX

- Paddy

Mar 11 '07 #30

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

Similar topics

1
4718
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
1582
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
2425
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
3549
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
4793
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
16570
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
3878
by: daskumardilip | last post by:
how to remove comment from c source code.
1
2345
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
2877
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
10856
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
9522
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
9336
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,...
0
9765
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
8770
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...
1
7327
isladogs
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...
0
6603
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
5364
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3866
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
2738
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.