Click here to Skip to main content
15,907,913 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.

 
GeneralRe: Is there a programming language... Pin
Marc Clifton18-Dec-13 1:40
mvaMarc Clifton18-Dec-13 1:40 
GeneralRe: Is there a programming language... Pin
Rob Grainger17-Dec-13 22:48
Rob Grainger17-Dec-13 22:48 
GeneralRe: Is there a programming language... Pin
Marc Clifton18-Dec-13 1:38
mvaMarc Clifton18-Dec-13 1:38 
GeneralRe: Is there a programming language... Pin
Rob Grainger18-Dec-13 4:28
Rob Grainger18-Dec-13 4:28 
GeneralRe: Is there a programming language... Pin
Marc Clifton18-Dec-13 4:52
mvaMarc Clifton18-Dec-13 4:52 
GeneralRe: Is there a programming language... Pin
Rob Grainger18-Dec-13 7:00
Rob Grainger18-Dec-13 7:00 
GeneralRe: Is there a programming language... Pin
greydmar20-Dec-13 2:17
greydmar20-Dec-13 2:17 
GeneralRe: Is there a programming language... Pin
Eduard Matei18-Dec-13 0:53
Eduard Matei18-Dec-13 0:53 
In Python you can inherit from int (something like):
Python
class AgeInYears(int):
    unit = "years"
    def __new__(cls, age:int):
        cls.age = age
        return int.__new__(cls,age)

    def __str__(self):
        return "{} {}".format(self.age, self.unit)
    def __add__(self, value:int):
        self.age += value
        return self


class User():
    def __init__(self, age:int):
        self.age = AgeInYears(age)

    def __str__(self):
        return "User: age: {}".format(self.age)


And then use it like:
Python
user = User(29)
print(user) #User: age: 29 years
print(user.age) #29 years
print(type(user.age)) #<class '__main__.AgeInYears'>

user.age += 2 #use it like an int, and just increase it.
print(user.age) #31 years
print(type(user.age)) #<class '__main__.AgeInYears'> 


Of course, you still have to override some default methods of int (new, add).
This should cover the semantics nicely: you have an int, with unit, you can do basic int operations.

Ed
GeneralRe: Is there a programming language... Pin
Marc Clifton18-Dec-13 1:33
mvaMarc Clifton18-Dec-13 1:33 
GeneralRe: Is there a programming language... Pin
908236518-Dec-13 2:32
908236518-Dec-13 2:32 
GeneralRe: Is there a programming language... Pin
Marc Clifton18-Dec-13 2:34
mvaMarc Clifton18-Dec-13 2:34 
GeneralRe: Is there a programming language... Pin
908236518-Dec-13 2:57
908236518-Dec-13 2:57 
GeneralRe: Is there a programming language... Pin
Rob Grainger18-Dec-13 4:20
Rob Grainger18-Dec-13 4:20 
GeneralRe: Is there a programming language... Pin
908236518-Dec-13 6:12
908236518-Dec-13 6:12 
GeneralRe: Is there a programming language... Pin
Anas Karm.18-Dec-13 4:23
Anas Karm.18-Dec-13 4:23 
GeneralRe: Is there a programming language... Pin
Marc Clifton18-Dec-13 4:26
mvaMarc Clifton18-Dec-13 4:26 
GeneralRe: Is there a programming language... Pin
Member 460889818-Dec-13 7:50
Member 460889818-Dec-13 7:50 
GeneralRe: Is there a programming language... Pin
aschmahmann19-Dec-13 16:29
aschmahmann19-Dec-13 16:29 
GeneralRe: Is there a programming language... Pin
Marc Clifton20-Dec-13 2:27
mvaMarc Clifton20-Dec-13 2:27 
GeneralRe: Is there a programming language... Pin
b.leclerc27-Dec-13 3:20
b.leclerc27-Dec-13 3:20 
GeneralFacebook launches auto-play video ads on news feeds Pin
Gregory Gadow17-Dec-13 3:46
Gregory Gadow17-Dec-13 3:46 
GeneralRe: Facebook launches auto-play video ads on news feeds Pin
Maximilien17-Dec-13 3:55
Maximilien17-Dec-13 3:55 
GeneralRe: Facebook launches auto-play video ads on news feeds Pin
Gregory Gadow17-Dec-13 4:12
Gregory Gadow17-Dec-13 4:12 
JokeRe: Facebook launches auto-play video ads on news feeds Pin
Johnny J.17-Dec-13 4:58
professionalJohnny J.17-Dec-13 4:58 
GeneralRe: Facebook launches auto-play video ads on news feeds Pin
Dan Neely17-Dec-13 10:23
Dan Neely17-Dec-13 10:23 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.