473,395 Members | 1,343 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

What about an EXPLICIT naming scheme for built-ins?

I just read the changes for 2.4 and while scanning the list the past tense
built-ins got my attention:

sorted() - a new builtin sorted() acts like an in-place list.sort() but
can be used in expressions, as it returns a copy of the sequence, sorted.

reversed() - a new builtin that takes a sequence and returns an iterator
that loops over the elements of the sequence in reverse order (PEP 322)
sort() works in-place.
reverse() works in-place.

The past tense of sort() indicates that a copy of the sequence is returned.
The past tense of reverse() indicates that an iterator over the original
sequence is returned.

To my eyes it lacks a bit of consistency... well both past-tense functions
return something (but different somethings although the concepts behind
sorting and reversing are similar - a possible future trap for the faq).

It is a common trap that sort() and reverse() work in-place. Any tutorial
will warn you and still users fall into the trap over and over again...
One should take this as a usability weakness of the language!

<opinion>
I would like to see Python introducing a naming scheme for built-ins. Ruby
for example uses the ! to indicate an in-place function [sort() vs.
sort!()]. I know, that the exclamation mark is out of discussion but I
would appreciate to have a clear and distinct function naming (Explicit is
better than implicit).

An example but not very well thought out:

sort_inpl() -> in-place returns nothing
sort_copy() --> returns a sorted copy
sort_iter() -> returns an iterator over the original sequence
sort_copy_iter() -> returns an iterator on a copied and sorted sequence

</opinion>

What do you think about a naming scheme? Do you have any proposals/ideas?

Regards,
Marco

Jul 18 '05 #1
3 1537
Marco Aschwanden wrote:
I just read the changes for 2.4 and while scanning the list the past
tense built-ins got my attention:

sorted() - a new builtin sorted() acts like an in-place list.sort() but
can be used in expressions, as it returns a copy of the sequence, sorted.

reversed() - a new builtin that takes a sequence and returns an iterator
that loops over the elements of the sequence in reverse order (PEP 322)
sort() works in-place.
reverse() works in-place.


How about reversed() returning a sequence, like sorted does, but adding
an iterator function called riter or reverseiter to iterate over
sequences in reverse order. That would then be similar to the iter
builtin. You could have a sortediter as well

David
Jul 18 '05 #2
"David Fraser" <da****@sjsoft.com> wrote in message
news:ch**********@ctb-nnrp2.saix.net...
Marco Aschwanden wrote:
I just read the changes for 2.4 and while scanning the list the past
tense built-ins got my attention:

sorted() - a new builtin sorted() acts like an in-place list.sort() but
can be used in expressions, as it returns a copy of the sequence, sorted.
reversed() - a new builtin that takes a sequence and returns an iterator
that loops over the elements of the sequence in reverse order (PEP 322)
sort() works in-place.
reverse() works in-place.


How about reversed() returning a sequence, like sorted does, but adding
an iterator function called riter or reverseiter to iterate over
sequences in reverse order. That would then be similar to the iter
builtin. You could have a sortediter as well

David


Huh! I just assumed that sorted() and reversed() would both return new
lists, one sorted, and one reversed. I should think if you wanted an
iterator, you could use iter(sorted(x)) or iter(reversed(x)). But to get an
iterator over the reverse of a sequence, without making a copy of the
sequence, then this should have a different name, something like riter, or
reverse_iter.

In the current system, how does one construct a reversed list?
- revx = x[::-1]
- revx = [ i for i in reversed(x) ]
- revx = [tooth for tooth in ... ] # not a real example, just wanted to
follow up after "i for i"

(What if you wrote a sorted_iter that would iterate over an existing list in
sorted order?)

-- Paul
Jul 18 '05 #3
On Fri, 03 Sep 2004 20:26:13 GMT, Paul McGuire
<pt***@austin.rr._bogus_.com> wrote:
(What if you wrote a sorted_iter that would iterate over an existing list in
sorted order?)


I wrote about it earlier today. The proper way to do it is through a
generator. This way you can sort a sequence and use just a small part
of it -- maybe just the top few items or so. I proposed the name
xsorted() to keep company with xrange(), but that's being deprecated,
so I really don't know if it's worth it at this point.
--
Carlos Ribeiro
Consultoria em Projetos
blog: http://rascunhosrotos.blogspot.com
blog: http://pythonnotes.blogspot.com
mail: ca********@gmail.com
mail: ca********@yahoo.com
Jul 18 '05 #4

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

Similar topics

220
by: Brandon J. Van Every | last post by:
What's better about Ruby than Python? I'm sure there's something. What is it? This is not a troll. I'm language shopping and I want people's answers. I don't know beans about Ruby or have...
699
by: mike420 | last post by:
I think everyone who used Python will agree that its syntax is the best thing going for it. It is very readable and easy for everyone to learn. But, Python does not a have very good macro...
176
by: Thomas Reichelt | last post by:
Moin, short question: is there any language combining the syntax, flexibility and great programming experience of Python with static typing? Is there a project to add static typing to Python? ...
137
by: Philippe C. Martin | last post by:
I apologize in advance for launching this post but I might get enlightment somehow (PS: I am _very_ agnostic ;-). - 1) I do not consider my intelligence/education above average - 2) I am very...
22
by: Generic Usenet Account | last post by:
A lot has been said in this newsgroup regarding the "evil" set/get accessor methods. Arthur Riel, (of Vanguard Training), in his class, "Heuristis for O-O Analysis & Design", says that there is...
27
by: Derek | last post by:
The company where I work uses a naming convention that I have never used before. They use mixed-case letters for public member functions, but lower-case with underscores for the rest, like this:...
7
by: DEX | last post by:
Main page of my NC: http://www.ddmrm.com/coding/cpp/naming/cpp.naming.main.html Rules of my NC: http://www.ddmrm.com/coding/cpp/naming/cpp.naming.rules.html Comments are welcome. ...
38
by: news.microsoft.com | last post by:
Greetings, I am posting this message to both the SQL Server and C# news groups because this inquiry is more of a theoretical question that applies to both database and code naming conventions. ...
3
by: Doug | last post by:
Scenario: I select data from a SQL Server View which links 3 tables, into a single dataset table. I update some of those fields on a web form. When I want to update the db, clearly I can't update...
669
by: Xah Lee | last post by:
in March, i posted a essay “What is Expressiveness in a Computer Language”, archived at: http://xahlee.org/perl-python/what_is_expresiveness.html I was informed then that there is a academic...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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...

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.