473,387 Members | 1,863 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,387 software developers and data experts.

general coding issues - coding style...

Hi all,

since I'm just a 'handicraft'/beginner or so,

could anybody provide me with some (rough) hints, about how to enhance the code
here:

http://calmar.ws/tmp/cal.html

Cheers and thanks a lot
calmar
--
calmar

(o_ It rocks: LINUX + Command-Line-Interface
//\
V_/_ http://www.calmar.ws
Feb 18 '06 #1
11 1457
calmar schrieb:
Hi all,

since I'm just a 'handicraft'/beginner or so,

could anybody provide me with some (rough) hints, about how to enhance the code
here:


- why are these {{{ thingies there?

- use string interpolation like "Foo %s %i" % ("bar", 1) instead of
concatenating strings.

- it seems that you could benefit from a class instead of a bunch of
functions & few globals. No need to go too crazy about OO, but it has
its merits

- try using something like glade - creating GUIs by hand sucks
big-timer :)

- read up about unicode and encodings, what they mean and why and when
to use what. Really. Most problems in that field stem from people being
sort of ignorant on that topic and just wiggling themselves through all
the time - in the end, messing up stuff. It really _isn't_ that complicated.

- when creating string-keyed dicts, the idiom

dict(foo="bar",
baz="pillepalle")

has its merits.

Besides that - looks ok to me.

Diez
Feb 18 '06 #2
On 2006-02-18, Diez B. Roggisch <de***@nospam.web.de> wrote:

Hi Diez,
- why are these {{{ thingies there?
markers for folding for vim
http://www.calmar.ws/tmp/sc.png
- use string interpolation like "Foo %s %i" % ("bar", 1) instead of
concatenating strings.
I see, get's shorter and so, and I can break lines.
(seems to me, after ( or [ or so, I can use a new line without
to worry)
- it seems that you could benefit from a class instead of a bunch of
functions & few globals. No need to go too crazy about OO, but it has
its merits
I see. Maybe I could then build some classes for that prog,
especially since I use only one file, it probably would make
some sense for getting a better structure.

- try using something like glade - creating GUIs by hand sucks
big-timer :)
I should (seriously) check out probably.
- read up about unicode and encodings, what they mean and why and when
to use what. Really. Most problems in that field stem from people being
sort of ignorant on that topic and just wiggling themselves through all
the time - in the end, messing up stuff. It really _isn't_ that complicated.
I read up. In fact, basically it does not seem to be that complicate.
Unicode just a 'numbered' list of all available character, and
e.g. uft-8 a organized way to 'store' those 'numbers' wisely
into bytes.

I still have some problems with that (and gave up), but since I begin to
now understand it somebit more, I should try/check again.
- when creating string-keyed dicts, the idiom

dict(foo="bar",
baz="pillepalle")


I see, I changed too.

Thanks a lot,
marco

--
calmar

(o_ It rocks: LINUX + Command-Line-Interface
//\
V_/_ http://www.calmar.ws
Feb 18 '06 #3
Hi,

1585 if sys.path[0][-12:] == "\library.zip": #for py2exe

how about

if sys.path[0].endswith( "\\library.zip" ):

(did you really mean one back-slash there?)
499 tuple = os.path.split(filename)

bad variable name... tuple(x) converts a sequence to a tuple.
You have a number of places where you check for len(x)==0:

674 if len(files) == 0:
853 if len(file_show) == 0:
950 if len(imgprocess["files_todo"]) == 0:

people usually recommend:

if not files:
if not file_show:
if not imgprocess["files_todo"]:
you should run your code through pychecker (it had a lot to say...).
You use global alot... that should be a red flag. Like the poster
above mentioned, you have things that are telling you they want to
be objects.
The #{{{ and #}}} stuff is very annoying to other programmers
(ok, to me...). You might want to investigate a Python aware
editor (like SPE, which has pychecker built in). This is
coming from someone who uses vim regularly.

Feb 18 '06 #4

calmar wrote:
On 2006-02-18, Diez B. Roggisch <de***@nospam.web.de> wrote:
- why are these {{{ thingies there?


markers for folding for vim
http://www.calmar.ws/tmp/sc.png


I would look into one of the many Vim scripts which automatically fold
most large blocks without the ugly {{{.

Feb 18 '06 #5
Dylan Moreland wrote:
I would look into one of the many Vim scripts which automatically fold
most large blocks without the ugly {{{.


Who needs a script?
"set foldmethod=indent"
works pretty well for most python programs.

Feb 19 '06 #6
On 2006-02-18, Justin Azoff <ju**********@gmail.com> wrote:

Hi all,
Dylan Moreland wrote:
I would look into one of the many Vim scripts which automatically fold
most large blocks without the ugly {{{.


Who needs a script?
"set foldmethod=indent"
works pretty well for most python programs.


Well, foldmethod=marker does not bother me, because the folds are
normally closed. With markers, it takes one line per function, with
indent I see 2, so I prefer markers.

...and since I can easily get rid of them, and add them again, I will at
least remove them before e.g. putting to the web or so.
Cheers and thanks,
calmar

--
calmar

(o_ It rocks: LINUX + Command-Line-Interface
//\
V_/_ http://www.calmar.ws
Feb 19 '06 #7
On 2006-02-18, pl****@alumni.caltech.edu <pl****@alumni.caltech.edu> wrote:

Hi,
1585 if sys.path[0][-12:] == "\library.zip": #for py2exe
if sys.path[0].endswith( "\\library.zip" ):
cool, thx,
(did you really mean one back-slash there?)
(yeah, one backslash)
499 tuple = os.path.split(filename)
bad variable name... tuple(x) converts a sequence to a tuple.
I see, I changed that to
path, filen = os.path.split(filename)
You have a number of places where you check for len(x)==0:
674 if len(files) == 0:
--> if not files:
I see. thx
you should run your code through pychecker (it had a lot to say...).
I see, cool tool that pychecker!
I can't do something against the 'not used variable' so probably?
(since pygtk just sends those items anyway)
You use global alot... that should be a red flag. Like the poster
above mentioned, you have things that are telling you they want to
be objects.


I will try to get some order (classes) and maybe remove them.

thanks a lot!!

cheers,
calmar

--
calmar

(o_ It rocks: LINUX + Command-Line-Interface
//\
V_/_ http://www.calmar.ws
Feb 19 '06 #8
calmar a écrit :
Hi all,

since I'm just a 'handicraft'/beginner or so,

could anybody provide me with some (rough) hints, about how to enhance the code
here:

http://calmar.ws/tmp/cal.html
1/ learn OO and get rid of globals.
2/ use dict or list based dispatch instead of long if/elif/elif... clauses
3/ stdout is meant for *normal* program outputs. Errors and verbosity go
to stderr
4/ triple quoted strings are fine for multiline text
5/ os.path is fine for portable filepath operations
6/ things that dont change during program execution (ie : constants)
should not be defined inside a function
Cheers and thanks a lot
calmar

Feb 19 '06 #9
On 2006-02-19, Bruno Desthuilliers <bd*****************@free.quelquepart.fr> wrote:

Bonjour,

1/ learn OO and get rid of globals.
Well I created two classes now. I put some things global (your point 6).
e.g. if it's on Windows or not, and other things.
2/ use dict or list based dispatch instead of long if/elif/elif... clauses
when I find out what you mean, I will. Probably something lika a 'case'
thing? #python meant a list containing functions or so. So that the
values represent the functions to call, isn 'it?
3/ stdout is meant for *normal* program outputs. Errors and verbosity go
to stderr
yeah, changed (somebit)
4/ triple quoted strings are fine for multiline text
yeah. I have lot of triple prints...
5/ os.path is fine for portable filepath operations
I don't really understant what you mean here, sorry
6/ things that dont change during program execution (ie : constants)
should not be defined inside a function


As I mentioned above, these I placed globally:

main gtkwindows,
smwin or not,
pyexe or not,
preferred encoging

according to your statement?
Anyway, since I did lot of changes, I'm myself confused actually.
http://calmar.ws/tmp/cal.html

Will try to cleanup and implement even further all good
advices from all in some days.

Thanks a lot!!
calmar

--
calmar

(o_ It rocks: LINUX + Command-Line-Interface
//\
V_/_ http://www.calmar.ws
Feb 20 '06 #10
JW
About this line:
1585 if sys.path[0][-12:] == "\library.zip": #for py2exe

pl... suggested:
if sys.path[0].endswith( "\\library.zip" ):

and said, "did you really mean one back-slash there?". You responded
"yeah, one backslash", but I still don't believe you. In this case, it
happens to work, but you should be aware that the back-slash is an
escape character, which causes the next character to be interpreted
differently. Try this in your interpreter:

print "\a" # System bell - might cause your speaker to beep
print "\t" # Tab character
print "\n" # Newline character / sequence

See http://www.python.org/doc/2.4.2/ref/strings.html for more details
on the escape sequences that Python recognizes. Here's a summary: if
the backslash + character is a special escape code, then replace it
with that, otherwise assume the programmer meant a real backslash.
That's dangerous, and will break when the name changes from one that
starts with an L to one that starts with an A, B, F, N, etc. The safe
way it to tell Python "Yes, I really want a backslash", which is
indicated with the double backslash:

print "\\library.zip"

If you don't use the double backslash, you'll eventually have a
problem, especially in Windows, which unfortunately uses the backslash
as a directory seperator. You might also want to look at os.sep and
the os.path.* functions, if you are interested in making your code work
on different platforms.

JW

Feb 20 '06 #11
On 2006-02-20, JW <Jo***********@ieee.org> wrote:

Hi JW,
About this line:
1585 if sys.path[0][-12:] == "\library.zip": #for py2exe

pl... suggested:
if sys.path[0].endswith( "\\library.zip" ):
print "\\library.zip"

Yeah, I have two backslashes, but thaks for pointing out.
If you don't use the double backslash, you'll eventually have a
problem, especially in Windows, which unfortunately uses the backslash
as a directory seperator. You might also want to look at os.sep and
the os.path.* functions, if you are interested in making your code work
on different platforms.


Yeah, I will use the os.sep variable, that's a good idea

thanks a lot,
calmar
--
calmar

(o_ It rocks: LINUX + Command-Line-Interface
//\
V_/_ http://www.calmar.ws
Feb 21 '06 #12

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

Similar topics

3
by: Roman Roelofsen | last post by:
Dear python-list, while looking for some coding conventions for python programs, i found the PEP8 at http://www.python.org/peps/pep-0008.html. It defines the rules very well and leaves no space...
18
by: craig | last post by:
I am curious about how many of you prefer style 1 vs. style 2, and why. Are there names for these style? style 1: method { }
144
by: Natt Serrasalmus | last post by:
After years of operating without any coding standards whatsoever, the company that I recently started working for has decided that it might be a good idea to have some. I'm involved in this...
1
by: Dgates | last post by:
I'm learning ASP.NET, C# and VB.NET, and hoping to get some feedback from more experienced programmers on a few issues regarding efficient, readable, well-organized code. I'm trying to program...
4
by: Mike Labosh | last post by:
I realize that you people have not seen much of me other than some framework responses I have posted. I am primarily a VB guy (yes, you can laugh) But I have lurked here for several years,...
13
by: benben | last post by:
Is there an effort to unify the c++ coding standard? Especially identifier naming. Not a big issue but it would be annoying to have to incorporate different coding styles simultaneously when...
3
by: ct-86 | last post by:
http://www.cdbook.cn/book.asp?id=2393 Organizational and Policy Issues 1 0. Don't sweat the small stuff. (Or: Know what not to standardize.) 2 1. Compile cleanly at high warning levels. 4 2....
3
by: Andrew Robinson | last post by:
I have never done this or seen this but thought it might be useful. What do you think of it? This is a very simplified example but frequenly when reusing an object, I find myself spending a lot of...
8
by: boki_pfc | last post by:
Hi Everybody, I am looking for an advice on following: I have that "pleasure" of reading C++ codes that have been written by person(s) that have not attended the same C++ classes that I did or...
3
by: The Natural Philosopher | last post by:
Ok, I have another form to write, and one of its features will be pop up or drop down select-from-list stuff. Could be done with javascript, could be done with <SELECT> <OPTIONetc etc.. It...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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:
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
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...

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.