Re: A design problem I met again and again.

2009-04-04 Thread andrew cooke
andrew cooke wrote: [...] >>> > #= >>> > def start(type, id): >>> > if(type == "XXX"): >>> > pass >>> > else if(type == "YYY"): >>> > pass >>> > #= i just realised i am assuming type is a type of an object, but you might be us

Re: A design problem I met again and again.

2009-04-04 Thread andrew cooke
Note sure who wrote: >> > Consolidate existing functions? >> >> > I've thought about it. >> >> > For example, I have two functions: >> >> > #= >> >> > def startXXX(id): >> > pass >> >> > def startYYY(id): >> > pass >> > #= >> >> > I could turn

Re: A design problem I met again and again.

2009-04-04 Thread 一首诗
That's clever. I never thought of that. Not only something concrete, like people, could be class, but a procedure, like a Session, could also be a Class. Thanks for you all who replied. I learned a lot from this thread and I even made some notes of all your advices because I think I might revie

Books about refactoring in Python (Was: A design problem I met again and again.)

2009-04-03 Thread Michele Simionato
On Apr 4, 6:10 am, Carl Banks wrote: > A piece of user code that looked like this (where sc is an instance of > your enormous class): > > sc.startX() > sc.send_data_via_X() > sc.receive_data_via_X() > sc.stopX() > > might look like this after you factor it out: > > session = sc.startX()  # creates

Re: A design problem I met again and again.

2009-04-03 Thread Carl Banks
On Apr 2, 11:25 pm, 一首诗 wrote: > Consolidate existing functions? > > I've thought about it. > > For example, I have two functions: > > #= > > def startXXX(id): > pass > > def startYYY(id): > pass > #= > > I could turn it into one: > > #==

Re: A design problem I met again and again.

2009-04-03 Thread paul
一首诗 schrieb: > Consolidate existing functions? > > I've thought about it. > > For example, I have two functions: > > #= > > def startXXX(id): > pass > > def startYYY(id): > pass > #= > > I could turn it into one: > > #==

Re: A design problem I met again and again.

2009-04-03 Thread Emile van Sebille
andrew cooke wrote: Emile van Sebille wrote: Whether you (generic you) choose to do so or not is a separate issue. Also agreed - and that is really my point. Doing so feels to me like continuing to look for a lost object once you've found it. i can see your point here, but there's two things

Re: A design problem I met again and again.

2009-04-03 Thread andrew cooke
Emile van Sebille wrote: >>> Whether you (generic you) choose to do so or not is a separate issue. > > Also agreed - and that is really my point. Doing so feels to me like > continuing to look for a lost object once you've found it. i can see your point here, but there's two things more to consid

Re: A design problem I met again and again.

2009-04-03 Thread Emile van Sebille
Steven D'Aprano wrote: On Thu, 02 Apr 2009 22:18:02 -0700, Emile van Sebille wrote: Steven D'Aprano wrote: On Thu, 02 Apr 2009 16:51:24 -0700, Emile van Sebille wrote: I refactor constantly during development to avoid code reuse through cut-n-paste, but once I've got it going, whether it's

Re: A design problem I met again and again.

2009-04-03 Thread Steven D'Aprano
On Thu, 02 Apr 2009 22:18:02 -0700, Emile van Sebille wrote: > Steven D'Aprano wrote: >> On Thu, 02 Apr 2009 16:51:24 -0700, Emile van Sebille wrote: > >>> I refactor constantly during development to avoid code reuse through >>> cut-n-paste, but once I've got it going, whether it's 1000 or 6000 >

Re: A design problem I met again and again.

2009-04-02 Thread 一首诗
Consolidate existing functions? I've thought about it. For example, I have two functions: #= def startXXX(id): pass def startYYY(id): pass #= I could turn it into one: #= def start(type, id): if(type == "XXX"

Re: A design problem I met again and again.

2009-04-02 Thread Michele Simionato
On Apr 3, 7:18 am, Emile van Sebille wrote: >  So, I think the question becomes, when does code need > refactoring? I would say that 99.9% of the times a single class with 15,000 lines of code is a signal that something is wrong, and refactoring is needed. M. Simionato -- http://mail.

Re: A design problem I met again and again.

2009-04-02 Thread Emile van Sebille
Steven D'Aprano wrote: On Thu, 02 Apr 2009 16:51:24 -0700, Emile van Sebille wrote: I refactor constantly during development to avoid code reuse through cut-n-paste, but once I've got it going, whether it's 1000 or 6000 lines, it doesn't matter as long as it works. If you've been refactoring

Re: A design problem I met again and again.

2009-04-02 Thread Steven D'Aprano
On Thu, 02 Apr 2009 16:51:24 -0700, Emile van Sebille wrote: > 一首诗 wrote: >> Hi all, >> >> I am a programmer who works with some different kinds of programming >> languages, like python, C++(in COM), action script, C#, etc. >> >> Today, I realized that, what ever language I use, I always meet a

Re: A design problem I met again and again.

2009-04-02 Thread Emile van Sebille
一首诗 wrote: Hi all, I am a programmer who works with some different kinds of programming languages, like python, C++(in COM), action script, C#, etc. Today, I realized that, what ever language I use, I always meet a same problem and I think I never solve it very well. The problem is : how to br

Re: A design problem I met again and again.

2009-04-02 Thread Carl Banks
On Apr 2, 8:02 am, 一首诗 wrote: > You get it. Sometimes I feel that my head is trained to work in a > procedural way. I use a big class just as a container of functions. > > About the "data-based" approach, what if these functions all shares a > little data, e.g. a socket, but nothing else? Then

Re: A design problem I met again and again.

2009-04-02 Thread Jorgen Grahn
[top-posting fixed] On Thu, 2 Apr 2009 08:02:23 -0700 (PDT), =?GB2312?B?0rvK18qr?= wrote: > On Apr 2, 5:58 am, Carl Banks wrote: >> On Apr 1, 12:44 am, ?? wrote: >> >> > I got the same problem when writing C#/C++ when I have to provide a >> > lot of method to my code's user. So I create a

Re: A design problem I met again and again.

2009-04-02 Thread 一首诗
You get it. Sometimes I feel that my head is trained to work in a procedural way. I use a big class just as a container of functions. About the "data-based" approach, what if these functions all shares a little data, e.g. a socket, but nothing else? On Apr 2, 5:58 am, Carl Banks wrote: > On Ap

Re: A design problem I met again and again.

2009-04-02 Thread Steven D'Aprano
On Thu, 02 Apr 2009 07:45:46 -0400, andrew cooke wrote: > Lawrence D'Oliveiro wrote: >>> What are the average size of source files in your project? If it's >>> far lower than 15,000, don't feel it's a little unbalance? >> >> Why? > > one reason is that it becomes inefficient to find code. if

Re: A design problem I met again and again.

2009-04-02 Thread andrew cooke
Lawrence D'Oliveiro wrote: >> What are the average size of source files in your project? If it's >> far lower than 15,000, don't feel it's a little unbalance? > > Why? one reason is that it becomes inefficient to find code. if you structure code as a set of nested packages, then a module, and

Re: A design problem I met again and again.

2009-04-02 Thread Tim Rowe
2009/4/1 一首诗 : > Hi all, > > I am a programmer who works with some different kinds of programming > languages, like python, C++(in COM), action script, C#, etc. > > Today, I realized that, what ever language I use, I always meet a same > problem and I think I never solve it very well. > > The probl

Re: A design problem I met again and again.

2009-04-02 Thread Martin P. Hellwig
Steven D'Aprano wrote: If you have too much code in one file, it will upset the balance of the spinning hard drive platter, and it will start to wobble and maybe even cause a head-crash. That is why proper designed operating systems, like windows 95,rarely write one continuous block but spre

Re: A design problem I met again and again.

2009-04-01 Thread Steven D'Aprano
On Thu, 02 Apr 2009 18:47:29 +1300, Lawrence D'Oliveiro wrote: >>> The question is not how many lines or how many methods, but whether it >>> makes sense to remain as one piece or not. In one previous project, I >>> had one source file with nearly 15,000 lines in it. Did it make sense >>> to split

Re: A design problem I met again and again.

2009-04-01 Thread Lawrence D'Oliveiro
In message <158986a9-b2d2-413e-9ca0- c584299f1...@f1g2000prb.googlegroups.com>, 一首诗 wrote: > On Apr 1, 4:55 pm, Lawrence D'Oliveiro central.gen.new_zealand> wrote: > >> In message <48506803-a6b9-432b-acef- >> >> b75f76e90...@v23g2000pro.googlegroups.com>, 一首诗 wrote: >> > Until one day I find serv

Re: A design problem I met again and again.

2009-04-01 Thread Carl Banks
On Apr 1, 12:44 am, 一首诗 wrote: > I got the same problem when writing C#/C++ when I have to provide a > lot of method to my code's user. So I create a big class as the entry > point of my code. Although these big classes doesn't contains much > logic, they do grow bigger and bigger. This seems

Re: A design problem I met again and again.

2009-04-01 Thread Martin P. Hellwig
一首诗 wrote: But I think the first step to resolve a problem is to describe it. In that way, I might find the answer myself That is an excellent approach, knowing you have a problem and describing it is actually the hardest part of a design, the rest is more like a puzzle. What I guess so fa

Re: A design problem I met again and again.

2009-04-01 Thread Nick Craig-Wood
一首诗 wrote: > But I think the first step to resolve a problem is to describe it. In > that way, I might find the answer myself :-) That is a great saying! To answer your original question, split your code up into sections that can be tested independently. If you can test code in a isolated wa

Re: A design problem I met again and again.

2009-04-01 Thread Jeremiah Dodds
On Wed, Apr 1, 2009 at 3:40 PM, 一首诗 wrote: > What are the average size of source files in your project? If it's > far lower than 15,000, don't feel it's a little unbalance? > -- > http://mail.python.org/mailman/listinfo/python-list > While I think 15,000 is, in the vast majority of cases, qu

Re: A design problem I met again and again.

2009-04-01 Thread 一首诗
On Apr 1, 4:55 pm, Lawrence D'Oliveiro wrote: > In message <48506803-a6b9-432b-acef- > > b75f76e90...@v23g2000pro.googlegroups.com>, 一首诗 wrote: > > Until one day I find service has nearly 100 methods and 6000 lines of > > code.   I don't need to read any programming book to know that it's > > too

Re: A design problem I met again and again.

2009-04-01 Thread 一首诗
I also think that's my best choice. Before I wrote my mail, I already knew that this is not a good question. It lacks details, and it is too big. But I think the first step to resolve a problem is to describe it. In that way, I might find the answer myself On Apr 1, 6:40 pm, "andrew cooke"

Re: A design problem I met again and again.

2009-04-01 Thread andrew cooke
Ò»Ê×Ê« wrote: > 3. completely move codes in service to business classes. Initialize > these classes and pass them to protocol classes. > These protocol classes calls these instances of business classes > instead of call service. These means whenever I add a new business > class. I have to add a

Re: A design problem I met again and again.

2009-04-01 Thread Lawrence D'Oliveiro
In message <48506803-a6b9-432b-acef- b75f76e90...@v23g2000pro.googlegroups.com>, 一首诗 wrote: > Until one day I find service has nearly 100 methods and 6000 lines of > code. I don't need to read any programming book to know that it's > too big. The question is not how many lines or how many metho

A design problem I met again and again.

2009-04-01 Thread 一首诗
Hi all, I am a programmer who works with some different kinds of programming languages, like python, C++(in COM), action script, C#, etc. Today, I realized that, what ever language I use, I always meet a same problem and I think I never solve it very well. The problem is : how to break my app in