timmerk / ipaddr-py

Automatically exported from code.google.com/p/ipaddr-py
0 stars 0 forks source link

BaseIP properties and indexes (netmask, broadcast, etc) should return IP objects #21

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
The following methods:

  BaseIP.__getitem__
  BaseIP.broadcast / BaseIP.broadcast_ext
  BaseIP.hostmask / BaseIP.hostmask_ext
  BaseIP.netmask_ext

return strings or integers. They should return IPv4 objects instead.

The fact that you have separate broadcast and broadcast_ext methods that return 
the integer and 
string forms of a network's broadcast address, for instance, indicates that 
your object model is 
not as clean as it could be. Since the broadcast address is, in fact, an 
address, why not return a 
fully functional IPv4 instance? Users could then do (assuming network is an 
IPv4 instance):

str(network.broadcast) if they want the string form, or could do:

network.broadcast.is_private

or any of the other valid operations on an address.

Returning strings and integers from these methods leads to code duplication and 
does not 
embrace the spirit of object-oriented design.

Original issue reported on code.google.com by gtg464t@mail.gatech.edu on 2 Jun 2009 at 6:13

GoogleCodeExporter commented 9 years ago
closing this out.  taken care of in 2.0.x

Original comment by pmo...@google.com on 26 Aug 2009 at 9:13