Giter Club home page Giter Club logo

Comments (11)

nitsanw avatar nitsanw commented on May 16, 2024

So... do you want to make the counters visible or make the class not final?
Also, what are you trying to monitor?

from jctools.

ChristianWulf avatar ChristianWulf commented on May 16, 2024

I want to access the counters. But there are two ways to achieve this:

  1. make the counters protected and the queue non-final
  2. make the counters public

I like the second solution.

I want to monitor the number of pushes and pulls to get the number itself and to compute the throughput for a given time interval.

from jctools.

ChristianWulf avatar ChristianWulf commented on May 16, 2024

Thank you very much! Just one additional note: please adhere to the Java naming conventions. Rename currentProducerIndex to getCurrentProducerIndex and currentConsumerIndex to getCurrentConsumerIndex.

from jctools.

mjpt777 avatar mjpt777 commented on May 16, 2024

Just because a lot of people name things a certain way in Java does not mean it is right ;-)

I'd recommend Nitsan sticks with non get/set options. I'd recommend everyone watches this great presentation by Kevlin Henney who provides great analysis on the subject. As a dyslexic I find the dogma that goes with bad naming and brackets so annoying and hard to read.

http://www.infoq.com/presentations/7-ineffective-coding-habits

from jctools.

ChristianWulf avatar ChristianWulf commented on May 16, 2024

Oh, a discussion about clean code. Great! ...Let me comment on your statement with a few questions:

What do you mean by "right"? Let us assume it is right, why should "getXXX" be wrong? If you mean "it is three letters shorter" then I agree. If you conclude "it is-for this reason-faster to understand", then I ask you why? As far as I know, our eyes recognize and interpret words, not letters.

Anyway, let us now consider the following: in general, a method comprises a number of statements and thus does some computation on an object. To tell a human what a method does, we can, e.g., give it a meaningful name. Such a meaningful name must always contain a verb. Otherwise, it does not express what is done, but only "who", "what", "where", "when" etc.

I agree with Henney. Programmers should avoid superfluous text. But why are "get" and "set" superfluous within accessor method names? I claim "get" (or let it be "read" or "return") and "set" (or "write") are absolutely necessary in this context since they express what is done, i.e., they represent the verbs.

If a programming language provides the concept of properties, then programmers should use them in the way Henny tells in this talk. However, if a programming language does not support properties (as, for example, Java), programmers should not try to represent them by means of methods in the same way. And if so, then ask yourself: why did M$ introduce properties at all?

In summary, a method represents an action which can only be described exactly by using a verb.

from jctools.

mjpt777 avatar mjpt777 commented on May 16, 2024

To me properties are things and not directives to the object to do something. They do not mutate state or perform a computation so they do not require a verb. If you take a step further with a fluent API then the "set" prefix makes for very strange reading.

Now in this specific case get means nothing. What is important is the memory ordering semantics of the load from memory. Nitsan indicates this with an "lv" prefix which I believe stands for load volatile. I would personally expand this or make it explicit in another way, such as acquireXXX as used in memory models. Get does not convey this important semantic.

from jctools.

ChristianWulf avatar ChristianWulf commented on May 16, 2024

Yes. Properties represent a subset of the object's state. I agree. But Java does not provide properties! If you use methods for properties, you cannot distinguish an ordinary method and a property.

Anyway, a property may perform a computation. For example, consider a property that represents the full name of a person. This person object stores its first name and its last name as attributes, but does not own a full name attribute. The full name property can be computed from the first and the last name. That's a legal and reasonable use case for a property.

And concerning Nitsan's code style, I don't mind how he organizes the code internally. But I do mind how the public API looks like. So I talk about currentProducerIndex, not about lvProducerIndex.

from jctools.

mjpt777 avatar mjpt777 commented on May 16, 2024

What does "index" really mean in this case? Index of the array, index as a offset in memory, index over time.

How about the counters are simply renamed to be elementsAdded() and elementsRemoved() to be more explicit?

from jctools.

nitsanw avatar nitsanw commented on May 16, 2024

ooooh, everyone has been having such fun while I was asleep.
So... naming is a sensitive topic, and public APIs require thought.
I'm not of the get/set religion. I like the clarity of properties personally.
I picked current* because I want the API to express the temporal nature on these indexes. I also left it as *Index because I'm only exposing these on queues which have them and have no plan currently to add such API to all queues. I'll give the elementsAdded/Removed option some thought, but I'm reluctant to add semantics to offer/poll.
I will add some javadoc to also express the fact that they guarantee no concurrency related semantics and the long value returned may be negative. In fact they may not reflect elementsAdded/Removed if we chose to implement sparse elements by changing the index increment.
To directly answer @ChristianWulf original comment: "please adhere to the Java naming conventions"
"No, thank you"

from jctools.

ChristianWulf avatar ChristianWulf commented on May 16, 2024

Sounds better. But does this method represents a property, or a listener, or does it set a flag, or does it even triggers an event that is called elements[has been]Added? What ever you try, you cannot represent a property by a method. You always need to append the brackets () that indicate a method call and thus an action requiring a verb.

from jctools.

nitsanw avatar nitsanw commented on May 16, 2024

This is the wrong place for Java code conventions flame fights, please take this up on some relevant mailing list. Fill free to express your interest in enforcing some checkstyle rules in another ticket.

from jctools.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.