473,395 Members | 1,975 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.

Standalone Python functions in UML?

Hi!

Out of curiosity, how do I draw functions outside classes with UML? How
module could be drawn in this case?

More theoretical question is if I create classes on the fly, how UML can
reflect that?

(I know that Python code itself is best at communication design ideas,
but there are some people which prefer to talk UML.)

(Have not found anything relevant with google)

Thanks!

Regards,
Roman Suzi

Apr 4 '06 #1
16 5316
>> Out of curiosity, how do I draw functions outside classes with UML? How
module could be drawn in this case?

As a utility class.
More theoretical question is if I create classes on the fly, how UML can reflect that?

"On the fly" usually means "at runtime". I guess you mean if you
"change code" will my diagram stay in sync?. You will have to use round
trip tools. I don't know any tool supports round trip for Python code.
But if you just mean reverse engineering, lookup PyNSource, Boa
Constructor, PyReverse among others
(I know that Python code itself is best at communication design ideas,

but there are some people which prefer to talk UML.)

Actually no. Python is a good tool for "prototyping" which is not the
same as "communicating design ideas". Diagrams are better for the later
and do not need to be executable. At least from what I know, except
Eiffel, no language makes that claim. UML is really the only contender
currently for design notation.

Apr 4 '06 #2

Roman Susi wrote:
Hi!

Out of curiosity, how do I draw functions outside classes with UML? How
module could be drawn in this case?
I would say that within a class diagram, you can't. In other UML
diagrams (such as sequence interaction), the function is simply used as
if it were a method belonging to an object. If you need to make it
clear where this function is located within the code, use a note on the
diagram.

Remember, UML is not able to accurately capture all implementation
details of a system; It's not meant to.

More theoretical question is if I create classes on the fly, how UML can
reflect that?
Again, don't try to depict fine-grained implementation details. If the
dynamically generated class is important to the class diagram, include
it but don't include all of it's internals (methods etc.). Use a note
to exaplin how/when/why it is generated.

(I know that Python code itself is best at communication design ideas,
but there are some people which prefer to talk UML.)

(Have not found anything relevant with google)

Thanks!

Regards,
Roman Suzi


Rob C

Apr 4 '06 #3
Roman Susi wrote:
Hi!

Out of curiosity, how do I draw functions outside classes with UML? How
module could be drawn in this case?
I'm not up to par on the latest UML specs (or not too old) - but I don't
believe UML handles that: it is called a class diagram after all.
More theoretical question is if I create classes on the fly, how UML can
reflect that?
You mean objects I think: by using a 0..n in you agregation ?

(I know that Python code itself is best at communication design ideas,
but there are some people which prefer to talk UML.)

(Have not found anything relevant with google)

Thanks!

Regards,
Roman Suzi


Regards,

Philippe

Apr 4 '06 #4
Ravi Teja wrote:
(snip)
More theoretical question is if I create classes on the fly, how UML can


reflect that?

"On the fly" usually means "at runtime". I guess you mean if you
"change code" will my diagram stay in sync?.


Nope, the OP really meant "on the fly", as in "at runtime". In python,
it is possible to create new classes at runtime. Remember,
everything-is-an-object implies that classes are objects too.

--
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'o****@xiludom.gro'.split('@')])"
Apr 4 '06 #5
Philippe Martin wrote:
Roman Susi wrote:

(snip)
More theoretical question is if I create classes on the fly, how UML can
reflect that?

You mean objects I think:


Yes : class objects !-)

Python's classes *are* objects. And you can create new classes at runtime.

(snip)
--
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'o****@xiludom.gro'.split('@')])"
Apr 4 '06 #6
Ravi Teja wrote:
Out of curiosity, how do I draw functions outside classes with UML? How
module could be drawn in this case?

As a utility class.
So, function could be a utility class method. If there are no better ways.
More theoretical question is if I create classes on the fly, how UML can
reflect that?

"On the fly" usually means "at runtime". I guess you mean if you
"change code" will my diagram stay in sync?. You will have to use round
trip tools. I don't know any tool supports round trip for Python code.
But if you just mean reverse engineering, lookup PyNSource, Boa
Constructor, PyReverse among others


No. I do not need it. I just want to know if UML is capable of doing it.
(I know that Python code itself is best at communication design ideas,


but there are some people which prefer to talk UML.)

Actually no. Python is a good tool for "prototyping" which is not the
same as "communicating design ideas". Diagrams are better for the later
and do not need to be executable. At least from what I know, except
Eiffel, no language makes that claim. UML is really the only contender
currently for design notation.


Well, maybe SOL (Semantic Object Language) could also be quite
beneficial in some cases. At least, it depends with whom to communicate
design ideas and what level of formality to maintain.

Also, my argument that Python is quite good at communicating design
ideas is supported by the fact that Python developers do not use UML (or
other modelling tools/languages) as often as say Java programmers, nor
feel the need to. And probably Python is too dynamic for UML. That is
another reason rountrip tools aren't there.

--
Roman
Apr 4 '06 #7
But not in UML: a class diagram will represent classes while a sequence
diagram objects.

Philippe

bruno at modulix wrote:
Philippe Martin wrote:
Roman Susi wrote:

(snip)
More theoretical question is if I create classes on the fly, how UML can
reflect that?

You mean objects I think:


Yes : class objects !-)

Python's classes *are* objects. And you can create new classes at runtime.

(snip)


Apr 4 '06 #8
> So, function could be a utility class method. If there are no better ways.

What I mean is <<utility>> is the formal notation for a class in which
global functions are aggregated. It's not a hack.
Python is not alone here. Most OO languages aside Java and Smalltalk
have functions outside classes and UML accomodates though not
encourages free functions.
Well, maybe SOL (Semantic Object Language) could also be quite beneficial in some cases. At least, it depends with whom to communicate
design ideas and what level of formality to maintain.

I don't know what Semantic Object Language is. One important
requirement of choosing communication notations is that they should be
sufficiently popular that everyone understands. Kind of beats the
purpose if you are the only person who knows it. I got 146 hits on
Google for "Semantic Object Language" and UML. Too few for me to care.
If it is a deserving notation, hopefully that will change in the
future.
Also, my argument that Python is quite good at communicating design ideas is supported by the fact that Python developers do not use UML
(or
other modelling tools/languages) as often as say Java programmers, nor
feel the need to.

I guess you and I mean VERY different things when we say "Design
Ideas". You seem to imply pseudo code. I mean overall archetecture. I
think Python devs will use UML tools if there are good ones available.
I know I would. I could really use a round trip class and package
diagram editor now.
And probably Python is too dynamic for UML. That is another reason rountrip tools aren't there.


As you probably already know, UML diagrams are structural and
behavioural (plus interactional with 2.0). Round trip tools only model
structural diagrams. Python is dynamic but only once the program starts
executing :-). Even though Python classes "can" change, they do so only
at runtime ( wouldn't it be scary if they decided to change as code
when you are not looking :-) ). So dynamism of Python should not be as
much of an issue. I think the reason we don't have good UML round trip
tools for Python is primarily a market issue rather than a language
issue. If Python gets the same market share as Java, it will surely get
all these tools and more.

Apr 5 '06 #9
In <ma***************************************@python. org>, Roman Susi
wrote:
Out of curiosity, how do I draw functions outside classes with UML? How
module could be drawn in this case?


I just create a (UML) class for modules. After all a Python module can be
seen as a class definition for a singleton which is instantiated at import
time.

Ciao,
Marc 'BlackJack' Rintsch
Apr 5 '06 #10
Ravi Teja wrote:
(snip)
And probably Python is too dynamic for UML. That is another reason rountrip tools aren't there.
As you probably already know, UML diagrams are structural and
behavioural (plus interactional with 2.0). Round trip tools only model
structural diagrams. Python is dynamic but only once the program starts
executing :-). Even though Python classes "can" change, they do so only
at runtime


Well, you can have a lot of things happening during the import stage. Is
this 'runtime' or not ?-)

And you can actually *create* (not 'change') classes at runtime too.
So dynamism of Python should not be as
much of an issue.


Not so sure about this.

--
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'o****@xiludom.gro'.split('@')])"
Apr 5 '06 #11
Philippe Martin wrote:
<meta> please don't top-post - corrected</meta>
bruno at modulix wrote:

Philippe Martin wrote:
Roman Susi wrote:


(snip)

More theoretical question is if I create classes on the fly, how UML can
reflect that?
You mean objects I think:


Yes : class objects !-)

Python's classes *are* objects. And you can create new classes at runtime.

(snip)


But not in UML: a class diagram will represent classes while a sequence
diagram objects.


Yes, there's in UML a fundamental distinction between classes and
objects - distinction that does not exist in a lot of OO languages. This
greatly limits UML's usability for some common idioms in dynamic OOPL's.
Seems like UML has been designed to express only the restricted subset
of OO supported by rigid static languages like C++, Java and ADA.

My 2 cents
--
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'o****@xiludom.gro'.split('@')])"
Apr 5 '06 #12
> Well, you can have a lot of things happening during the import stage. Is
this 'runtime' or not ?-)

Runtime.
And you can actually *create* (not 'change') classes at runtime too.


Yes sir! By now I am quite well aware what 'dynamic typing' means. Once
again, round trip tools today model program structure/code/text, not
runtime magic - all the stuff a dynamically typed language such as
Python does differently from statically typed languages like Java. So
this does not affect them much.

Languages like Python with metaclasses and other dynamic aspects do
present an interesting case for modelling but what I am talking about
is round trip tools, not the full scope of modelling and UML. Round
trip implementations today get at class and package diagrams
(structural), not object diagrams and collaboration diagrams. Class and
Package diagrams are concerned with the layout, not intricate runtime
behaviour, mutations and mutilations of classes and packages. That
would be the domain of behavioural diagrams of which I made no
assertions. There isn't much magical about Python as far as code layout
is concerned. Metaclasses can for example change the very behaviour of
the class construct but modelling that is not the purpose of a class or
package diagram.

Rather than going hypothetical and us miscommunicating in the abstract
plane, could you just tell me why you could not draw a class or package
diagram for your last project? That will probably make me see what I am
missing from your points.

Apr 5 '06 #13
Ravi Teja wrote:
What I mean is <<utility>> is the formal notation for a class in which
global functions are aggregated. It's not a hack.
Python is not alone here. Most OO languages aside Java and Smalltalk
have functions outside classes and UML accomodates though not
encourages free functions.
It doesn't seem to sit well with the common Python idiom of having
several free functions packaged in a module, sadly.
Python is dynamic but only once the program starts
executing :-). Even though Python classes "can" change, they do so only
at runtime ( wouldn't it be scary if they decided to change as code
when you are not looking :-) ). So dynamism of Python should not be as
much of an issue.


But on a similar note, I was wondering about classes such as
BaseHTTPServer where the function to be called is looked up by name,
and may or may not exist, or the situation where multiple function
calls with similar signatures can be redirected to one using some
getattr trickery - these don't seem to play well with the static nature
of UML. (Or editor auto-completion, or cross-referencing code in an
IDE...) I tend to shy away from such constructs for these reasons.

--
Ben Sizer

Apr 5 '06 #14

Roman Susi wrote:
[...]
Also, my argument that Python is quite good at communicating design
ideas is supported by the fact that Python developers do not use UML (or
other modelling tools/languages) as often as say Java programmers, nor
feel the need to. And probably Python is too dynamic for UML. That is
another reason rountrip tools aren't there.


Another reason is probably the problem you started this thread with;
UML class diagrams are very much centered around Java style object
orientation. Other paradigms, like the procedural and the generic ones,
do not fit well. Nor is it well suited to represent the shift to a meta
level that is involved when you start creating types at execution time.

Cheers,
Nicola Musatti

Apr 5 '06 #15

bruno at modulix wrote:
[...]
Yes, there's in UML a fundamental distinction between classes and
objects - distinction that does not exist in a lot of OO languages. This
greatly limits UML's usability for some common idioms in dynamic OOPL's.
Seems like UML has been designed to express only the restricted subset
of OO supported by rigid static languages like C++, Java and ADA.


Moreover, it also seems like UML has been designed to express the
restricted OO subset of the paradigms supported by languages like C++
and ADA.

And I suspect UML design tools are not that popular within the C and
Lisp programming communities...

Cheers,
Nicola Musatti

Apr 5 '06 #16
Marc 'BlackJack' Rintsch wrote:
In <ma***************************************@python. org>, Roman Susi
wrote:

Out of curiosity, how do I draw functions outside classes with UML? How
module could be drawn in this case?

I just create a (UML) class for modules. After all a Python module can be
seen as a class definition for a singleton which is instantiated at import
time.


Thanks. That was precise answer to one of the questions.

I am not able to answer to everyone, but I see it really boils down to
UMLs restricted nature. That is quite ok.

Ciao,
Marc 'BlackJack' Rintsch


Sy,
Roman
Apr 5 '06 #17

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

Similar topics

2
by: Sandeep Gupta | last post by:
Hi, I've written a commercial application that uses Python scripts for some of the functionality. Installing the Python portion of the application requires me to first install Python, and then...
9
by: Dan Williams | last post by:
Hi people I'm getting a little annoyed with the way the print function always adds a space character between print statements unless there has been a new line. The manual mentions that "In some...
4
by: j_mckitrick | last post by:
Does it make sense to use doc strings rather than #-comments for a standalone Python app? If the classes aren't going to be re-used or imported, do they need them?
7
by: Chris | last post by:
hello, I have a small module which only contains some utility functions. when running this standalone I would like to show the module docs and each function docs, as if doing import M help(M)...
2
by: James Stroud | last post by:
Hello All, I am trying to create a semi-standalone with the vendor python on OS X 10.4 (python 2.3.5). I tried to include some packages with both --packages from the command and the 'packages'...
11
by: beginner | last post by:
Hi Everyone, I am looking for a way to allow a standalone python process to easily interactive with a few web pages. It has to be able to easily receive requests from the web and post data to...
3
by: shaun roe | last post by:
This may be a question of style: Sometimes I need a little helper function (e.g. checkRange(val, lo, hi)) in my .cpp and have a habit of making these functions simple standalone functions in the...
4
by: Gabriel Rossetti | last post by:
Hello everyone, I like to create a cross-platform standalone python application, like Mac OS *.app dirs. The idea is to distribute a zip file containing everything (the python interpreter and...
0
by: Philip Semanchuk | last post by:
On Oct 17, 2008, at 2:59 AM, Gabriel Rossetti wrote: Hi Gabriel, For details on how OS X .app dirs work, plug this into Google: "os x" application bundle But as Martin said, that's...
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: 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?
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
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
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...
0
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,...

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.