How to set block data value? [closed] - java

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Bukkit's setData(data) and getData() are deprecated. But there's no replacement.
Bukkit/Spigot JavaDoc says this about setData():
Deprecated. Magic value
Why is that?

So far, the only way to do it is by using:
Block.setData(byte data);
So, you could do something like this:
myBlock.setData(2); // Set block data to 2
Although Block.setData() is deprecated, it still works, and will continue to work (deprecated methods in Bukkit are rarely removed, especially those for which there is no alternative).
I wish I could give a better answer, but that's the only thing that you can do, as of now.
The reason it is deprecated is because Minecraft is moving away from item IDs, and switching to item names, to make it easier to expand in the future. Where you used to have to run /give player 19, you are now supposed to run /give player minecraft:sponge (although the ID still works). The same thing is going to happen to data values, instead of giving someone 35:14, you now give them red wool.
To get rid of the warning given by using a deprecated method, put #SuppressWarnings("deprecation") above the deprecated method when you use it, or above the method in which it is used.
To set the type of the block, you could use:
Block.setType(Material type);
An example is:
myBlock.setType(Material.GOLD_BLOCK); // Set block to gold block
You could also use MaterialData, but no one really knows how to use it (as far as I know). It's one of the things included in the Bukkit API, but no one knows why.
The source of WorldEdit and most other big plugins look messy because they use a lot of interfaces. To the developers, it seems very organized, but to someone reading it, it looks very messy, unless you can actually visualize the hierarchy.

Related

Trying to think an approach for creating a feature flag in React [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 11 months ago.
Improve this question
I'm trying to create a feature flag in my react project (I believe I have to add a feature flag in the appsettings.json file), the flag is to hide the features that are currently being developed as we don't want users to have those features when those are yet to be tested fully. So the current approach I have is to wrap the newly developed code with a condition like if(flag){new code} I'm sorry if the approach looks silly but that's all I can come up with as a rookie, so can you guys help with some feasible approach if possible?
So I've tried adding the if condition to an existing feature in the code base as the newly developed code is yet to be committed but it didn't work.
Based on your comment from three hours ago I was able to figure out what exactly you wanted to do.
So: already having the flag all there is to do is to use it. There are at least three ways you can do it:
make it hidden - i think MDN docs explain it well enough
make it transparent - this is what you did: setting opacity to 0
not render it at all
not rendering is achieved like this:
return (
<SomeParentComponent>
{EnableDivision &&
<Division/>
}
</SomeParentComponent>
)
It's not like one of them is better than others: they are all situational.
hidden element is rendered, and therefore has state and can be found in the DOM tree, but doesn't take any space
transparent is like hidden, but takes up space
not rendered on the other hand can't be found in the DOM tree, doesn't take any space, the funcion or class creating it is never run and therefore it also can't have any state
Hopefully this should dispel your doubts about how to do it.
Also if you ever needed use some flags in many different components in various places of your component tree take look at what React Context does.

How do you make changes in dynamic languages, and find all of the places that will be broken by that change? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I am used to programming in static languages like Java, where changing the signature of a method will cause a compilation error for every line of code that calls the method I changed. This makes modifying large projects much more easy, because I can make a change, and then let the compiler tell me about all the places that I need to fix.
When dealing with a large project in a dynamic language like Python or Ruby, how do you make code changes, and still remain confident that you are not going to be surprised with a run-time error in production because of some scenario you forgot about?
I've seen my fair share of NullPointerExceptions and ArrayIndexOutOfBoundsExceptions in Java, so it's not like these things never happen in a static language, I would just think they happen a lot less.
Here are some ideas for providing some level of the protection that you are used to in Java:
As stated in a previous comment, you should definitely provide adequate unit and integration testing to prevent any issues during a refactor. Testing is even more important in a dynamic language than in a statically-typed language. You should check that values are properly passed and handled in each of your functions.
Use PyCharm and search for usages on a method prior to making the update. This is not full-proof, but does find a good amount of method usage to allow for an easier refactor.
Do a global find for the method name in your editor or search program of choice.
Provide exception handling in your functions for cases where the type is incorrect or a value is unset.
Handle args and kwargs passed into your function carefully. Perhaps provide an error or debug log if you receive an unexpected input.
Provide default values for undefined parameters to a function.
Here is an example of providing a default value for a parameter to ensure that it is defined and initialized to None (similar to null) in the function if it is not passed in with a value:
def my_function(my_parameter=None):
# Do something with my_parameter

Java: Is creating a "System" class a bad thing? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
I recently started a project in Java, that contains a class called System. This class (Luckily) contains methods for output management, so in the rare cases where I need to use the System. methods (Or the System object in general) I just reference it as java.lang.System.. I believe that this could be looked down upon, as System could be looked at as a reserved name. I currently am in the beginning stages of this program, and could change it accordingly quickly, as there are little calls to the class itself.
While it's not illegal, you don't want to do this. If I were the next person working on your code, the first thing I would do is try to remove "java.lang" from "java.lang.System" and then get miffed when it wouldn't compile.
The idea is to go toward brevity and only write what you need to write, while making sense of it all for the next person. It's more an art than a science.
You could always name it something like ProjectnamehereSystem or OutputManager or something to that effect.
I would not create something so similarly named as an important class. While everything is easy to edit, you may be able to keep up with all the changes you are making.
But when the project evolves things will get messy and complex. I would suggest naming it something else that can be easily distinguished.

JAVA: Create boolean variable or put argument within If statement? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
I've been running through a lot of code reviews and keep running into a situation where I see conflicting coding standards regarding boolean variables and if statements.
Here is an example of one method(1):
boolean isXTrue = getBooleanValue(DataSetX);
if (isXTrue) {
//do code
}
Here is an example of the other method(2):
if (getBooleanValue(DataSetX)) {
//do code
}
Both do the same thing and function just fine. In some cases, method 1 is a lot more readable since the boolean variable can be named something meaningful, while method 2 saves more lines and unnecessary boolean variable creations.
Maybe I am reading too deep into a simple coding standard, but I'm rather curious that if we use method 1 more often, we could have unnecessary booleans being made.
Sorry if this is a stupid question, but I wanted to get some opinions anyway :)
It's likely that the compiler will optimize both cases so that either way is identical at run time. Of course, that depends on code outside the context that you've provided.
As for the question at large: it's something that you and your coworkers or group need to come to a consensus about. If you're looking for a definite answer about which one to choose, I don't think you're going to get anything convincing other than personal preferences of readability vs line count.
Discuss this with the others that maintain your code base and decide on which should be preferred. Clearly explain why. Then move on to more...err...important issues.
As for my preference? I like option 1. To me, it's more readable, the variable name can be something descriptive like isActive, which makes the code easier to read. Also, inspecting values during debugging is probably easier as you have a definite variable with which to reference prior to its use later in the chain. Again, that's my preference.

View Java functions inlined [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
First off all, I know there are several questions about "Java inline". But they are all about how the compiler or JVM inlines function calls. I'm interested in doing this myself, or create some kind of a View for it. I want to define a function call of a class, and want to see everything inlined. Every method call should get inlined. I'm not sure how to handle instantiation of new objects, but it doesn't matter as much.
The goal is manual optimization, i.e. if a parameter is checked too often against null. Is there a tool to to something like this? I would prefer a GUI, but some kind of command line tool where I can specify a class function and it dumps some text somewhere will suffice, too.
EDIT:
For clearification:
Today I argued to use the NullObjectPattern, because some are defensively overchecking for nulls everywhere. This makes the code unreadable and unclean. I dont like it and wanted to have some kind of a tool, to show them how often they are actually checking the very same parameter again and again for null.
As was said: Don't guess, especially when you don't know what the JIT compiler will do after the code has been running for a while. You can waste infinite time infinitely improving something that accounts for 1% of runtime and only save 1%, or you can spend a short time getting a 10% improvement of something that accounts for 20% of your runtime and save 2%; the latter is by far a better choice.
The way you determine what's worth improving is by properly profiling your code after it has been fully warmed up.
And the way you get a significant improvement generally has more to do with improved algorithms than with microtuning of single instructions.

Categories

Resources