Skip to content

Ya vse.#1

Open
vloooo wants to merge 4 commits into
SlobodaStudio:masterfrom
vloooo:master
Open

Ya vse.#1
vloooo wants to merge 4 commits into
SlobodaStudio:masterfrom
vloooo:master

Conversation

@vloooo

@vloooo vloooo commented Dec 12, 2018

Copy link
Copy Markdown

No description provided.

Comment thread main_ovs.py
class JsonWriter:
@staticmethod
def write_json(name, jsn):
with open(name, 'w') as file: # serialization

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This class is very good in terms of SRP, but this comment is redundant - the code is pretty self-documenting.

Comment thread main_ovs.py

class CheckerForMeaning:
@staticmethod
def find_trash(clean_line, inf_dict):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea to mutate the data passed as an argument is as bad as mutating the internal state. That means, instead of doing

def find_trash(clean_line, inf_dict):
# ...
inf_dict['orphan_tokens'].append(i)
# ...

a much better strategy could be

def find_trash(clean_line):
# ...
    return clean_tokens, orphan_tokens

# somewhere higher the call stack
clean_tokens, orphan_tokens = find_trash
response["orphan_tokens"] = orphan_tokens

Don't ever mutate the data passes to your methods as an argument.

Comment thread main_ovs.py
for i in clean_tokens: # check for meaning
if nltk.wsd.lesk(tokens, i) is None:
inf_dict['orphan_tokens'].append(i)
return inf_dict

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you absolutely have to mutate the data sent you as an argument, don't return this very data from your method - your method should either have an "out" parameter to mutate, or a return value, not both. Having both, you confuse a reader of your method.

Comment thread main_ovs.py

result = {'records': []}

for i in data: # tweet handling

@vittorius vittorius Dec 19, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i could be line for better readability.

Comment thread main_ovs.py
def __init__(self, line):
self.line = line

def explore(self):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The responsibilities distribution between lines is done well enough.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And the idea to get parts of the response data and merge them in a single place is also a very good way to go. Just remove any mutations of the input data in your methods (see my comment above).

Comment thread main_ovs.py
def find_urls(clean_line, raw_line, inf_dict):
""" find URL """
urls = re.findall('http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+', raw_line)
funk_for_clean = RemoverUnwantedWords.remove_words

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Unnecessary indirection.
  2. English: func instead of funk.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants