How to get all image tags from an html - php code
I wanted to fetch all image tags from a big html, and wanted to perform some…
July 03, 2018
While doing code review of one of junior, I encountered following code:
class Test:
logger = MyLogger.get_instance()
def __init__(self):
client = Jira.get_instance()
def do_process(self):
self.logger.info('Hey test')
# some other code
What bothered me was
*What was the need of declaring it to be class variable
Lets consider below code:
class Test:
a = 20
def __init__(self):
self.a = 10
test = Test()
print(test.a)
test.a = 10
Test.a = 30
print(test.a)
print(Test.a)
### Output
10
10
30
These are the variables that are associated with class not with the instance of class. Which means, static or class variables are shared across all instances of the class. There can be an instance variable with the same name as static one. But, both will have a different identifier and can have different values.
Now, you should always refer class or static variable with class name. Although, you can also refere a static variable with class instance. But, it will result into nighmares of your debug life if you declare same name instance variable. Also, if some new developer joins your team and try to read your code. If you have not refered class or static variable with class name, he might consider it an instance variable which it is not.
Always refere statics like:
Test.a
I wanted to fetch all image tags from a big html, and wanted to perform some…
Introduction While this topic may applicable to all mysql/mariadb users who…
Introduction We will list few interesting automation techniques with powershell…
Introduction In this post, I will show how to validate your json schema…
hook_cron() suggests to put tasks that executes in shorter time or non-resource…
Introduction I was having a private artifactory, and has my custom modules…
Introduction In this post we will see following: How to schedule a job on cron…
Introduction There are some cases, where I need another git repository while…
Introduction In this post, we will see how to fetch multiple credentials and…
Introduction I have an automation script, that I want to run on different…
Introduction I had to write a CICD system for one of our project. I had to…
Introduction Java log4j has many ways to initialize and append the desired…