Keyword arguments for java? What do you think? [closed] - java

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 11 years ago.
This really isn't so much an answerable question as a 'What do you think' question.
In python, the programmer has the option to use keywords arguments in their function calls. For example
def doSomething(test=True, numBacon=5, ...):
Does any one other than me think that would be a fantasic idea for java? I know that varargs can do a lot, but it doesn't come close to being as useful are keyword arguments. So I ask the world, what do you think?

It might - if you could pass a map into a method, which would look up the map's keyed entries. It would require an inline, typeless map declaration, which wouldn't be very useful outside of this kind of limited scope - and since it'd be very limited, I'd end up saying "No, not required." If you want the facility, use Python. If you want the capability in a JVM, use Jython or JRuby.

Related

Map is better or enum is better on performance grounds? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 9 years ago.
I am new to using Enum.I am using Maps since long time.
I am not to sure and not too clear about Enum performance and capabilities.
Is it something to do with the performance if i use enum?
is it more kind of ObjectOriented using Enum?
Wanted a clear Idea about both of it on the grounds of their internal structure.
Maps and enums are completely different data structures. Maps are for associating a value with a key. Enums are for make typesafe constants. Comparing the two is impossible!

Is it a bad idea to put an array of objects in its class as a data member? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
I mean, I have a class A, and I have an array of A as a static data member of class A. Is is a bad practice?
In Java, it will result in a memory leak ... unless you do something messy and complicated with finalizers or Reference objects.
If your aim is to keep a collection of all instance ever created, you need to be very careful!! A collection of all instances created is going to leak memory, no matter how you implement it. (This is only really acceptable if the leak is either bounded, or small enough to not matter in the context of the entire application.)
If your aim is to keep a cache of existing instances to (for instance) to offset some particularly large object creation / initialization overheads, then you should use a WeakHashMap or an existing 3rd-party cache class rather than trying to implement it from scratch using arrays.

Observer vs. Registering callbacks [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
What are the pros and cons of using Observer versus just registering callbacks like:
worker.setOnJobIsDone(func);
If you use function pointers, the object is completely unaware of its users; it just calls a function which allows for more flexibility (the users don't need to inherit anything, you can wire users of this object as you like).
Observer pattern requires you to define an interface. This is less flexible but more explicit.
I prefer the observer pattern strongly for the sake of readability; it is much easier to track workflow if you've never seen the code before. Also C++ syntax for passing member functions is kind of hard on the eyes.

Why wasn't the diamond operator implemented when generics were introduced? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 11 years ago.
With Java 7 they finally implemented the diamond operator which lets you omit the repetition on initialization when working with generics.
E.g. List<String> list = new ArrayList<>();
This looks pretty convenient as it avoids writing "useless" code. It seems so useful that I'm curious why wasn't this implemented when generics were introduced.
It is a question similar to asking "why was the cordless ever developed? Why didn't we just develop the cell phone instead?". The answer is "necessity is the mother of invention". When generics were designed the necessity was to design a programming construct that did what generics so successfully did. Now the necessity was to maximize developer productivity, hence the invention of the diamond operator.

Function Name Conventions(Any Kind of PL) [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 11 years ago.
Is it bad to use Underscores in Function Names? Can I know the reason why?
ie:
Function GET_NAME(byval sword as string) as string
Not at all. The coding convention is a very subjective term. One might feel one coding style great and another find it worse. The key point is maintain one coding style only throughout your code for ease of upcoming developers and maintainers.
However, avoid all caps for function names (as shown in your example). It's generally reserved for macros (C/C++) / constants.
I would use them sparingly in my own API, but to say that they are bad is simply untrue. If so, .NET specifically would have problems with default naming for event handlers!
void Form_Load( //...
void Page_Load( //...
void btn_Click( //...
// etc.
In this specific case, all caps with underscore separators are generally understood to be constant values.
Firstly, its very subjective matter and depends from Person to Person. One may feel like using _ in function, others may not. There's no harm if you use it.
Frankly speaking, you don't usually use _ sign. But, you can to use this '_' in the variable declaration.
Note : You can check out the msdn link ( atleast for C#,
Visual Basic, C++ )

Categories