HiveBrain v1.2.0
Get Started
← Back to all entries
patternjavaspringMajor

You are being watched! - Comments of Interest

Submitted by: @import:stackexchange-codereview··
0
Viewed 0 times
youarewatchedbeinginterestcomments

Problem

You are being watched

Code Review has an open system

A machine that spies on you on every hour of every day

I know because I built it.

I designed the machine to detect suggestions to post on Code Review but it sees everything

Horrible comments involving ordinary users

Users like you

Comments that Stack Exchange considers irrelevant

They wouldn't act so I decided I would

But I needed some partners

Regulars with the skills to intervene

Loved by the moderators, we work in chat

You can easily find us

But on-topic or off-topic, if your comment's up

We'll find you

(Person of Interest intro, adapted to Comments of Interest)

For quite a while, users on Stack Overflow have posted comments directing people to post on Code Review. It has been noted several times on Stack Overflow Meta that users should be careful when doing that. In an effort to educate Stack Overflow users on which posts that belong here, and which does not, I decided to include the feature in my SE-chatbot named Duga.

The bot is running on a Spring MVC environment. It uses the Stack Exchange API to check Stack Overflow comments once every two minutes. It scans through the retrieved comments and posts them in The 2nd Monitor where regulars can check the Stack Overflow question to determine if it belongs on Code Review or not. It also sends some information in a special chatroom when there is a message that I am interested in - when there has been an excessive amount of comments recently or when the mysterious rate quota is reset. (I am not expecting it to be 100 comments very often. So far it has never happened within two minutes)

If you want to see an example of the API result, you can use this link.

Github repository for the whole bot can be found here

ScheduledTasks.java (relevant parts of it)

```
@Autowired
private ChatBot chatBot;

@Autowired
private StackExchangeAPIBean stackAPI;

private Instant nextFetch = Instant.now();
private long lastComment;
priv

Solution

I have one in the "any other comments" category :)

Localization?

I know, that's not a concern. Or is it? Localization always seems to get left behind! Ironically, it's exactly for that reason that localizing an application is more often than not, a pain in the neck.

But then, how much harder is it, really, to write this:

if (items.size() >= 100) {
    chatBot.postMessage(debug, Instant.now() + " Warning: Retrieved 100 comments. Might have missed some. This is unlikely to happen");
}


Like that:

if (items.size() >= 100) {
    chatBot.postMessage(debug, Instant.now() + Resources.Warn100CommentsReceived);
}


I'm assuming java has something like c# resources here, apologies if I just stuck a foot in my mouth. It does look cleaner though :)

'100' is a magic number

That said, items.size() >= 100 isn't "100 comments received" - the message doesn't reflect what the code is doing, and this means it's ever so slightly possible that the cake message is a lie. And if you ever bust that limit, you would probably want to know by how much.

How about extracting a variable out of items.size(), and concatenating it into the message instead of the hard-coded 100?

Based the last 26 weeks of activity on Stack Overflow, the numbers would be:

  • 4,320,919 comments.



  • Between 116,900 and 188,280 comments - 166,190 on average, per week.



  • 52-week average is 177,757 comments per week: the months ahead will be likely more busy than the ones behind us.



  • That's 16.5 comments per minute, 32.97 in two minutes.



I agree that 100 is a reasonable number to use. But... '100' is a magic number! While you received 30-some comments in two minutes, at least 4-5 new users have joined Stack Overflow (~23K new users per week) - at that rate 100 may possibly, eventually, need to be replaced with a higher number. The value is completely arbitrary (why not 255?) and clearly belongs as a private static final field - that's where I'd expect to find it, if not in an application settings / configuration file.

Code Snippets

if (items.size() >= 100) {
    chatBot.postMessage(debug, Instant.now() + " Warning: Retrieved 100 comments. Might have missed some. This is unlikely to happen");
}
if (items.size() >= 100) {
    chatBot.postMessage(debug, Instant.now() + Resources.Warn100CommentsReceived);
}

Context

StackExchange Code Review Q#79408, answer score: 31

Revisions (0)

No revisions yet.