472,354 Members | 2,083 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,354 software developers and data experts.

Almost keywords

Once in a while I feel free to write about less defined things, saying
mostly wrong things. This post is mostly chat, if you aren't
interested please ignore it.

Python is fit enough for newbie programmers, but some of its
characteristics can confuse them still, like the variables referenced
by name (that can be solved with a language that gives the illusion of
always manging values), the finite nature of floating point numbers
(that may be partially solved with interval arithmetic used in a smart
way, even if it may end being quite slower than Python floats), the
case sensitivity of all the language (in natural languages the case is
often irrelevant), the absence of rational numbers from integer
divisions, the code formatting precision required by significant
indentations, the "artificial" difference between lazy and eager
things, the silly syntax of tuples, some problems with closures that
partially come from automatic creation of variable names, many
inconsistencies present in the standard library, etc. Python 3.0
solved some of those problems, especially the smaller ones (for
example the "nonlocal" keyword workaround, etc).

If you take a look at the Python newsgroup, you can see that newbies
there do many similar mistakes all the time. A language fit for
newbies can adapt itself to avoiding those most common mistakes (but
today Python is becoming larger and more complex, more fit for real
programmers and less for programming newbies. This may be inevitable
in the evolution of a a language with commercial success). One of the
mistakes you see often is the rebinding of built-in things, like map,
list, etc. (Python 3.0 again turns some of those names into keywords,
avoiding part of those problems).

So you can see code like this that may lead to bugs in programs
written by newbies:
list = [x*x for x in range(100)

A possible way to avoid such bugs is to turn all those names like
"list", "map", "filter", "self", etc into keywords. But this may have
some disadvantages (well, I think I'd like to have "self" as keyword,
seen how all Python books strong suggest to not use a name different
from "self"). An intermediate solution is to change Python so that it
allows you to rebind those half-keywords only of you want it and you
know what you are doing, with a kind of comment at the top of the
module:

# rebinding = True
This allows you to do:
list = [x*x for x in range(100)]

By default rebinding is False, so this produces a SyntaxError:
list = [x*x for x in range(100)]

This may be a silly idea. Designing a good syntax for a language isn't
easy at all.

Note that a widely used Scheme implementation, DrScheme, implements
various sub-languages fit for newbies or almost-newbies or low-
experienced programmers. What is possible for experts can be a syntax
error for newbies. I don't like this feature much, I like more
freedom, but for purely learning purposes it may have its place. So
what I have said regarding the "almost keywords" isn't a totally new
idea :-)

Bye,
bearophile
Jul 21 '08 #1
1 1042
be************@lycos.com wrote:
A possible way to avoid such bugs is to turn all those names like
"list", "map", "filter", "self", etc into keywords. But this may have
some disadvantages (well, I think I'd like to have "self" as keyword,
seen how all Python books strong suggest to not use a name different
from "self").
I'm not convinced by making 'self' a keyword. Forcing the first argument of
a method to be named 'self' fails for many reasons (e.g.
classmethod/staticmethod) so I don't really see a benefit to making it
special in any way.

For the other names though, this would have the advantage of allowing the
compiler to optimise access to builtins which should provide a slight speed
improvement and I think would also make life easier for some
implementations (especially things like 'locals()').

A half-way house would be to generate a warning for any use of a name which
masks one of the reserved builtins, but only optimise lookups in scopes
where no such masking is seen by the compiler: this would prevent you
overriding builtins by injecting a name into the global namespace from
outside a module but not otherwise break existing code.

Of course any of this would break some existing code and therefore isn't
going to happen.
Jul 21 '08 #2

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

Similar topics

4
by: Nel | last post by:
Hi all, Before I re-invent the wheel here, has anyone willing to share a basic script to extract META keywords from a string. I have a string, let's say $pageText that contains the dynamic...
2
by: Cherry | last post by:
I have a trigger that won't compile: CREATE OR REPLACE TRIGGER TRG_CORRESPONDENCE_UPT AFTER UPDATE on TBLCORRESPONDENCE for each row BEGIN IF :OLD.Keywords <> :NEW.Keywords THEN
14
by: Jason Heyes | last post by:
I want to write a class that supports operations on keywords belonging to the C++ programming language. The following program repeatedly prompts the user for a keyword until 'explicit' is finally...
2
by: google | last post by:
I have a script which parses the BBC RSS feed once an hour, and drops any stories with certain keywords into a database. I would like to ban certain strings; at the moment the script will pick up...
2
by: dw | last post by:
Hi, everyone. I'm having difficulty understanding the difference of the keywords "friend" and "protected" vs. some of the other ways you can declare variables in ASP.NET ("dim", "public", and...
5
by: Digital.Rebel.18 | last post by:
I'm trying to figure out how to extract the keywords from an HTML document. The input string would typically look like: <meta name='keywords' content='word1, more stuff, etc'> Either single...
9
by: Nenad Loncarevic | last post by:
I am a geologist, and over the years I've accumulated quite a number of proffesional papers on the subject, in various publications. I would like to make a database that would help me find the...
5
by: mforema | last post by:
Hi Everyone, I want to search records by typing in multiple keywords. I currently have a search form. It has a combo box, text box, Search command button, and a subform. The combo box lists the...
5
by: =?Utf-8?B?UGV0ZXI=?= | last post by:
How can I get the list of connection string's keywords available in sqlclient programmatically? I have found the list in here...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. header("Location:".$urlback); Is this the right layout the...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it so the python app could use a http request to get...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...

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.