I think you can make your code better by making the following changes:
- Some of the comments are kind of useless. The code is more or less self explanatory. For example the comment in the following piece of code is useless:
Some of the comments are kind of useless. The code is more or less self explanatory. For example the comment in the following piece of code is useless:
# remove the node which the message has been sent to # from the list of susceptible nodes and # add it to the list of infected nodes self.susceptible_nodes.remove(selected_port) GossipNode.infected_nodes.append(selected_port)Here the comments are making the code less readable.
` # remove the node which the message has been sent to
from the list of susceptible nodes and
add it to the list of infected nodes
self.susceptible_nodes.remove(selected_port) GossipNode.infected_nodes.append(selected_port)`
Here the comments are making the code less readable.
- The following comment is also useless since
sendtofunction's definition clearly says when it is used.The following comment is also useless since
sendtofunction's definition clearly says when it is used.# since we are using connectionless protocol, # we will use 'sendto' to transmit the UDP message
`# since we are using connectionless protocol,
we will use 'sendto' to transmit the UDP message`
- also try writing shorter comments. You can usually skip the logic behind using the function in the comments, unless it is like a very important part of your code and is not clear from the function name.
Also try writing shorter comments. You can usually skip the logic behind using the function in the comments, unless it is like a very important part of your code and is not clear from the function name.
- instead of using different codes at different machines, use a single code. Save the port information in a separate file and read the port from that file.
Instead of using different code for different machines, use a single code. Save the port information in a separate file and read the port from that file.
from Gossip import GossipNode FILE_NAME = "randomFile.txt" port = read_port(FILE_NAME) connected_nodes = [5010] …
from Gossip import GossipNode FILE_NAME = "randomFile.txt" port = read_port(FILE_NAME) connected_nodes = [5010] ..
I I am also removing the comments from this code. It is clear from the code what you are tryigntrying to do and the comments are not adding any useful information.