Git Product home page Git Product logo

Comments (5)

shivam-mangla avatar shivam-mangla commented on July 28, 2024

Here, I've used GlobalVariables.java more as a Utility class because the
key is a string & therefore there is a high probability of using a wrong
key at places resulting in empty results (null). Even a small typo leads to
errors which is hard to figure out sometimes.

On Mon, Jun 17, 2013 at 1:34 PM, Shashank Mehta [email protected]:

Taking an example:
In HomeScreen.java, you are sending an intent to FilteredList.java

        Intent i = new Intent(HomeScreen.this, FilteredList.class);
        i.putExtra(GlobalVariables.HomeScreen_to_FilteredList,
                listItems[position]);
        // Log.i("extra", listItems[position]);
        startActivity(i);
        // HomeScreen.this.finish();

And then in FilteredList.java you are fetching the data using:

FilteredNamesList = new ArrayList<String>();
FilteredArrayList = new ArrayList<HashMap<String, String>>();
String value1 = getIntent().getStringExtra(
        GlobalVariables.HomeScreen_to_FilteredList);

What's the need for GlobalVariables.HomeScreen_to_FilteredList?
You are setting the key for the intent and you know the key. This key can
be directly used in both the files rather than being referenced from
GlobalVariables.java.

Any particular reason behind using this system rather than directly
setting the keys?

I think GlobalVariables should be used only for those cases where the
value of the variable will differ between developers.


Reply to this email directly or view it on GitHubhttps://github.com//issues/7
.

from muzi-android.

shashankmehta avatar shashankmehta commented on July 28, 2024
  1. Probability of typos occurring in key will be high only if you use complex names.
  2. Key can have any name. Normally when I keep a name I try to be descriptive about the value but in your case GlobalVariables.HomeScreen_to_FilteredList has no descriptive value at all.
  3. Key can be kept something as basic as data! Only problem is that it is not very descriptive about the value but by using your method you are in any case not concerned about description.
  4. If you use a convention of naming them as data you can hardly ever go wrong. Since separate intents can use same key name, using this convention shouldn't be a problem.

I think that you unnecessarily complicating something that can be very simple just to avoid typos!

from muzi-android.

shivam-mangla avatar shivam-mangla commented on July 28, 2024

HomeScreen_to_FilteredList makes it very clear that it's carrying data from
HomeScreen activity to FilteredList activity. Also, there are multiple keys
many times & sometimes you just change a key or add more keys in one
activity & forget to make changes in other (sometimes.. because trust me no
matter how careful you are, there are so many things going on at the same
time). So, I thought that it'd be a good idea to keep them in a separate
file.

Anyway, I have removed that already. Sorry, I haven't pushed it yet but
will do it tonight.

On Mon, Jun 17, 2013 at 3:43 PM, Shashank Mehta [email protected]:

  1. Probability of typos occurring in key will be high only if you use
    complex names.
  2. Key can have any name. Normally when I keep a name I try to be
    descriptive about the value but in your case
    GlobalVariables.HomeScreen_to_FilteredList has no descriptive value at
    all.
  3. Key can be kept something as basic as data! Only problem is that it
    is not very descriptive about the value but by using your method you are in
    any case not concerned about description.
  4. If you use a convention of naming them as data you can hardly ever
    go wrong. Since separate intents can use same key name, using this
    convention shouldn't be a problem.

I think that you unnecessarily complicating something that can be very
simple just to avoid typos!


Reply to this email directly or view it on GitHubhttps://github.com//issues/7#issuecomment-19536459
.

from muzi-android.

shashankmehta avatar shashankmehta commented on July 28, 2024

You don't need HomeScreen_to_FilteredList to tell you where the data is going from and to.
Intent i = new Intent(HomeScreen.this, FilteredList.class); tells me this already.

from muzi-android.

shivam-mangla avatar shivam-mangla commented on July 28, 2024

I believe in keeping variable names descriptive because there is no harm in
it. So, it's not about the need, it's more about clarity like it was easy
for you to understand what was this variable for. :)
Anyway later I found it redundant too. So, I've made the changes already
anyway. I'll push them by tonight & will close this issue. :)

On Mon, Jun 17, 2013 at 4:00 PM, Shashank Mehta [email protected]:

You don't need HomeScreen_to_FilteredList to tell you where the data is
going from and to.
Intent i = new Intent(HomeScreen.this, FilteredList.class); tells me this
already.


Reply to this email directly or view it on GitHubhttps://github.com//issues/7#issuecomment-19537110
.

from muzi-android.

Related Issues (10)

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.