I am a newbie in web development… Mostly I am pretty comfortable with coding in python and writing OO pythonic codes..
Whenever I write a code, I think of in terms of classes.. For the sake of discussion lets say I want to add to numbers..
In normal console based development I would do probably write a function and get the input from console..Like this
add.py
def add(a,b):
return (a+b)
and then in main.py call this function..
and so on…
and for more complicated functions I will write classes and so on.
But you get the idea …right.. Whenever I code, I think of these objects as living environment and that these objects has methods to maintain itself like a living organism and this sort of thinking helps me alot..
But now, lets say i want to add two numbers in the browser..
What should be my state of mind.
Maybe I write an html form to get input from users.. (connect it to the db to store the input from the users (just to make it a complete example.. )
And then what?
It would be of great help if anyone can actually write addition of two numbers where code executes on browser…
Assume that whatever framework you are using (django.. and sql library like mysqldb) are set up and configured on my local machine.. Just please help me write the “hello world” example in the web environment and from that i can draw the analogies which will help me to go long distance.
Thanks
Edit:
Just to adress the comments and answers..
class Add:
def __init__(self, a,b):
self._a = a
self._b = b
self._sum = self.__add()
def __add(self):
return (self._a + self._b)
A: There’s nothing wrong with adopting your OO coding style for server side coding.
A: Adding two numbers – as your example abundantly demonstrates – really isn’t “OO”.
Once you have something with “state” and “behavior”, it becomes interesting to think about objects. In your example, however, you just define an “operation” with a couple of “parameters”. There’s nothing wrong with that: your example is in fact a very good solution to the problem. But it’s not an “object oriented” solution.