Comments (11)
So... do you want to make the counters visible or make the class not final?
Also, what are you trying to monitor?
from jctools.
I want to access the counters. But there are two ways to achieve this:
- make the counters protected and the queue non-final
- 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.
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.
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.
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.
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.
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.
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.
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.
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.
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)
- O(1) insertion, fully non-blocking data structure HOT 4
- Publish test jar as part of the release
- any plans on fitting virtual threads HOT 1
- Missing `Automatic-Module-Name` in 4.0.1 (regression) HOT 2
- Add a parallel `forEach()` method in `NonBlockingHashMap` HOT 2
- Counters probe can be negative (and shouldn't?) HOT 3
- Add copyright information HOT 1
- MpscBlockingConsumerArrayQueue need override clear() method to avoid blocking when queue is empty HOT 2
- NonBlockingHashMap's computeIfAbsentc has a bug in a multithreaded environment HOT 11
- about spmc broadcast problem HOT 2
- the way of MpscBlockingConsumerArrayQueue provide offerFirst? HOT 1
- BaseMpscLinkedArrayQueue.peek() causes 100% CPU util [problem in caller code] HOT 2
- (cIndex - pIndex) / 2 == 0 return null;If it is being expanded, wait a little while for the expansion to succeed, there will be a JUMP, and should not return null HOT 5
- Question: "Emulating" Guava's Queues.drain on SpscLinkedQueue HOT 3
- New release to include JPMS module changes
- src/main/java/org/jctools/maps/NonBlockingHashMap.java:1415: error: missing reference label HOT 2
- Maven central 4.0.2 jar is compiled to Java 8, no longer supporting java 7 HOT 2
- unexpected MpscBlockingConsumerArrayQueue polling timeout behavior
- Unpadded variants could avoid using Unsafe HOT 3
- a question about mspc buffer array index HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jctools.