+ Reply
Page 4 of 8 FirstFirst ... 23456 ... LastLast
Results 61 to 80 of 141

Your favorite Apple, iPhone, iPad, iOS, Jailbreak, and Cydia site.


Thread: Improving our Coding Skills

is a discussion within the

File Mods

forums, a part of the

iPhone Modding

section;
Originally Posted by MamaJaay I'm here. Yay!!
...
  1. #61
    ----NewD 2.0---- NewdestinyX's Avatar
    Join Date
    Jan 2012
    Posts
    9,893
    Thanks
    4,218
    Thanked 9,026 Times in 4,531 Posts

    Quote Originally Posted by MamaJaay View Post
    I'm here.
    Yay!!
    Here to help if I can. If I can't I know someone who can!

  2. #62
    Evil Genius Developer GroovyCarrot's Avatar
    Join Date
    Jan 2012
    Location
    Liverpool, United Kingdom
    Posts
    545
    Thanks
    101
    Thanked 2,119 Times in 466 Posts

    I started out in web development myself but I'd just recommend following basic JavaScript tutorials and use the documentation to find functions if you don't know, or if like me your memory frequently doesn't hold it all in.

    Should also mention jQuery is the tits, there's a fair few awesome JS libraries that are free and opensource for both freeware and commercial distribution

    JavaScript is quite memory/battery intensive to run in some cases, especially on mobile devices since ARM has a lot less headroom than x86/64 processors, until recently with Apple ramping up the A chips to compete but remember not everyone is on an iPhone 5/S and if you're going to provide animations in widgets and stuff, it's good practice to provide an off switch for those that don't want to be running to the charger more than they need the toilet. Related note is that in most cases using a JS library like jQuery is likely more memory efficient that trying to build your own methods, unless you go about it with an understanding of memory expensive operations and forced acceleration hardware

  3. The Following 4 Users Say Thank You to GroovyCarrot For This Useful Post:

    King_O_Hill (10-22-2013), Krima (10-22-2013), rasputin007 (10-22-2013), RKO1195 (10-22-2013)

  4. #63
    ----NewD 2.0---- NewdestinyX's Avatar
    Join Date
    Jan 2012
    Posts
    9,893
    Thanks
    4,218
    Thanked 9,026 Times in 4,531 Posts

    Thanks for your input, Groovy. I found the tutorials on the Internet don't give enough examples.. They also don't explain things from the point of asking a question. "How do I search for whether a string contains a word".. You can put that in a Google search all day long and never find the code strand "indexOf"..

    That's why I started this thread.
    Here to help if I can. If I can't I know someone who can!

  5. #64
    Evil Genius Developer GroovyCarrot's Avatar
    Join Date
    Jan 2012
    Location
    Liverpool, United Kingdom
    Posts
    545
    Thanks
    101
    Thanked 2,119 Times in 466 Posts

    Quote Originally Posted by NewdestinyX View Post
    Thanks for your input, Groovy. I found the tutorials on the Internet don't give enough examples.. They also don't explain things from the point of asking a question. "How do I search for whether a string contains a word".. You can put that in a Google search all day long and never find the code strand "indexOf"..

    That's why I started this thread.
    Just need to be careful with terms, searching "check if sting contains string/substring" would likely get better results. Also StackOverflow is a great web service for programming help, I do post answers for people on there myself from time to time, but 99% of the time someone has already asked what you want to know

  6. The Following 5 Users Say Thank You to GroovyCarrot For This Useful Post:

    King_O_Hill (10-23-2013), Krima (10-23-2013), NewdestinyX (10-23-2013), RKO1195 (10-23-2013), Simon (10-23-2013)

  7. #65
    Superbad Modder-ator Simon's Avatar
    Join Date
    Nov 2007
    Location
    Bermuda
    Posts
    46,501
    Thanks
    6,794
    Thanked 15,203 Times in 6,978 Posts

    Stackoverflow is great, that's where I found most of the answers for the stuff I have done when learning how to do it.

  8. The Following 2 Users Say Thank You to Simon For This Useful Post:

    King_O_Hill (10-23-2013), NewdestinyX (10-23-2013)

  9. #66
    ----NewD 2.0---- NewdestinyX's Avatar
    Join Date
    Jan 2012
    Posts
    9,893
    Thanks
    4,218
    Thanked 9,026 Times in 4,531 Posts

    A lot of my searches would come up to the StackOverflow site. But each thread I read rarely gave me the answers I needed.. Is there a particular sub forum I should join if you remember? And thanks, Simon & Groovy!!
    Here to help if I can. If I can't I know someone who can!

  10. #67
    ----NewD 2.0---- NewdestinyX's Avatar
    Join Date
    Jan 2012
    Posts
    9,893
    Thanks
    4,218
    Thanked 9,026 Times in 4,531 Posts

    Can one of our veteran coders tell me how I can include multiple variables to search in a given IF statement.. I've tested the first one below and it doesn't work - but I want the proper syntax for achieving this:

    if (obj.statecode == 'PA', 'NJ', 'MN') {......}

    I know the OR separator.. ||
    But do I actually have to go:
    if ((obj.statecode == 'PA') || (obj.statecode == 'NJ') || (obj.statecode == 'MN')) {.....}

    If I have a list of 17 states I want.. Do I have to list them all as OR ' || ' substatements?
    Here to help if I can. If I can't I know someone who can!

  11. #68
    Evil Genius Developer GroovyCarrot's Avatar
    Join Date
    Jan 2012
    Location
    Liverpool, United Kingdom
    Posts
    545
    Thanks
    101
    Thanked 2,119 Times in 466 Posts

    Quote Originally Posted by NewdestinyX View Post
    Can one of our veteran coders tell me how I can include multiple variables to search in a given IF statement.. I've tested the first one below and it doesn't work - but I want the proper syntax for achieving this:

    if (obj.statecode == 'PA', 'NJ', 'MN') {......}

    I know the OR separator.. ||
    But do I actually have to go:
    if ((obj.statecode == 'PA') || (obj.statecode == 'NJ') || (obj.statecode == 'MN')) {.....}

    If I have a list of 17 states I want.. Do I have to list them all as OR ' || ' substatements?
    Stack Overflow is the subsite for Stack Exchange, I follow a few jailbreak related tags myself but it's more for actual programming languages rather than widgets HTML/CSS which is just markup, and the use of JavaScript is generally different than what would be used in web development, but if you structure your question appropriately and have an in-depth explanation as to the problem and what you have tried to solve it then you'll get good feedback but poorly constructed questions will get downvoted for not being constructive.

    In the case of your question you're looking at some basic principals (not being condescending, merely pointing out that the question need not be directed at a veteran coder, what ever that is) but you have provided yourself a solution that works, so if you're just looking for an approach that doesn't require you checking each possible result then you can assign an array containing possible results and use array.indexOf(element) to check whether the array contains the state code, so your code would look like this:
    Code:
    var statecodes = ["PA", "NJ", "MN", ... ];
    if(statecodes.indexOf(obj.statecode) > -1) {
        // Result is in the array
    }
    As I said though if you teach yourself some of the basic principals and data types you'll be able to work out ways to handle data with more ease, array.indexOf(element) returns the integer index of where the element is in the array you are checking, a result of not present is returned as -1 while the index of the first element "PA" will be 0. Therefore you need to be sure to compare that the result is greater than -1, rather than returning true of false. Again, some basic principals so I just suggest reading around JavaScript.

    Another tip would be that jQuery has a function built into the library $.inArray(value, array), in many cases the problem you have with JS is cross browser compatibility, see indexOf is a relatively new implementation so may not be supported in older browsers. Generally speaking though, since your deploying for iOS WebKit which is as modern as Safari, you don't really have to worry about those kind of things but it is good practice to know about them.

  12. The Following 4 Users Say Thank You to GroovyCarrot For This Useful Post:

    King_O_Hill (10-26-2013), Krima (10-26-2013), rasputin007 (10-26-2013), RKO1195 (10-26-2013)

  13. #69
    ----NewD 2.0---- NewdestinyX's Avatar
    Join Date
    Jan 2012
    Posts
    9,893
    Thanks
    4,218
    Thanked 9,026 Times in 4,531 Posts

    Thanks so much for the detailed explanation GroovyCarrot! You're a fountain of great info for us "new-intermediate" JavaScript learners.

    Right prior to your writing this method with array I did find a good article at StackOverflow after doing a better search string in Google and found the "in" command. So this IF statement worked for me to get rid of a zillion ORs.

    if (obj.statecode in {'PA':'', 'SC':''... etc}) {...}

    So listing the states in there works more cleanly than all the ORs . But arrays seem even cleaner and I guess I could put them in a different .js and call for that .js from the head of the HTML.. right?

    Tell me. How do I create a condition that filters out numeric integers?

    if (var x != a number) {....}

    How would I write the code so that condition returns true?

    TIA!
    Grant
    Last edited by NewdestinyX; 10-27-2013 at 03:49 PM.
    Here to help if I can. If I can't I know someone who can!

  14. #70
    Evil Genius Developer GroovyCarrot's Avatar
    Join Date
    Jan 2012
    Location
    Liverpool, United Kingdom
    Posts
    545
    Thanks
    101
    Thanked 2,119 Times in 466 Posts

    Quote Originally Posted by NewdestinyX View Post
    Thanks so much for the detailed explanation GroovyCarrot! You're a fountain of great info for us "new-intermediate" JavaScript learners.
    Well, I learned from the best (Google, actually)

    Right prior to your writing this method with array I did find a good article at StackOverflow after doing a better search string in Google and found the "in" command. So this IF statement worked for me to get rid of a zillion ORs.

    if (obj.statecode in {'PA':'', 'SC':''... etc}) {...}
    You'll find there's probably several solutions to every problem

    So listing the states in there works more cleanly than all the ORs . But arrays seem even cleaner and I guess I could put them in a different .js and call for that .js from the head of the HTML.. right?
    Seems unnecessary but you can include a separate js file, what you are doing above is creating an associative array, which is very unnecessary since you are assigning null values, or empty strings to array keys; somewhat of an overkill on system resources. I suppose to do it right you could do
    Code:
    if (obj.statecode in ['PA', 'SC', ...]) {
        
    }
    Essentially the same method I provided above but the index comparison is simplified

    Tell me. How do I create a condition that filters out numeric integers?

    if (var x != a number) {....}

    How would I write the code so that condition returns true?
    Pretty sure you can use typeof var == "number" to get a true/false response, a google search might give you a similar or better answer but it seems unconstructive for the two of us, for me to google your questions and present you with one of the many answers

  15. The Following User Says Thank You to GroovyCarrot For This Useful Post:

    RKO1195 (10-28-2013)

  16. #71
    ----NewD 2.0---- NewdestinyX's Avatar
    Join Date
    Jan 2012
    Posts
    9,893
    Thanks
    4,218
    Thanked 9,026 Times in 4,531 Posts

    Quote Originally Posted by GroovyCarrot View Post
    Well, I learned from the best (Google, actually)


    You'll find there's probably several solutions to every problem


    Seems unnecessary but you can include a separate js file, what you are doing above is creating an associative array, which is very unnecessary since you are assigning null values, or empty strings to array keys; somewhat of an overkill on system resources. I suppose to do it right you could do
    Code:
    if (obj.statecode in ['PA', 'SC', ...]) {
        
    }
    Essentially the same method I provided above but the index comparison is simplified


    Pretty sure you can use typeof var == "number" to get a true/false response, a google search might give you a similar or better answer but it seems unconstructive for the two of us, for me to google your questions and present you with one of the many answers
    Excellent. Well if Google is YOUR teacher - I'll keep learning from it as well. But, just so you understand my way - when I post a question here it's already after 30 minutes or more of searching Google and either not finding my answer or not understanding what I did get. So if anyone's too busy to help- no sweat.. All good.. .. but I've already done my homework first.

    And I find coders further down the road know how to simplify and "boil down".. That's why I started this thread - so that "further down" guys could mentor the rest of us.. Not just GIVE us answers but help us to think more focused about what we want to accomplish. I got the extra ' ' null values from the StackOverflow article - but I never would have known I didn't need them without your "too much resources" comment above.

    That's why I'm gonna keep asking here! .. And thanks!

    Ooo.. And is the var you give me above used within an if statement or set up at the beginning if a js?
    Last edited by NewdestinyX; 10-28-2013 at 06:03 AM.
    Here to help if I can. If I can't I know someone who can!

  17. #72
    Evil Genius Developer GroovyCarrot's Avatar
    Join Date
    Jan 2012
    Location
    Liverpool, United Kingdom
    Posts
    545
    Thanks
    101
    Thanked 2,119 Times in 466 Posts

    Quote Originally Posted by NewdestinyX View Post
    And I find coders further down the road know how to simplify and "boil down".. That's why I started this thread - so that "further down" guys could mentor the rest of us.. Not just GIVE us answers but help us to think more focused about what we want to accomplish. I got the extra ' ' null values from the StackOverflow article - but I never would have known I didn't need them without your "too much resources" comment above.
    With JS it's a bit more flexible than having to consider system resources, normally in web development since the scripts are executed by the browsers interpreter it isn't a problem, but widgets are a different case and so you should consider that you will have memory issues to take into account - and also that widgets run all the time on the device so sucking up resources will potentially lower the battery life

    Ooo.. And is the var you give me above used within an if statement or set up at the beginning if a js?
    Well the expression was for an if statement but var is any variable you want to check typeof result for

  18. The Following User Says Thank You to GroovyCarrot For This Useful Post:

    RKO1195 (10-28-2013)

  19. #73
    ----NewD 2.0---- NewdestinyX's Avatar
    Join Date
    Jan 2012
    Posts
    9,893
    Thanks
    4,218
    Thanked 9,026 Times in 4,531 Posts

    Quote Originally Posted by GroovyCarrot View Post
    With JS it's a bit more flexible than having to consider system resources, normally in web development since the scripts are executed by the browsers interpreter it isn't a problem, but widgets are a different case and so you should consider that you will have memory issues to take into account - and also that widgets run all the time on the device so sucking up resources will potentially lower the battery life


    Well the expression was for an if statement but var is any variable you want to check typeof result for
    Thanks, Groovy!

    Hey I just had a chance to check removing the "null" from the "in" command. And it fails the widget.. In the "in" command, evidently the :"" has to stay after each state code I list..for whatever reason. Just putting commas between them as you listed didn't work for me.
    Last edited by NewdestinyX; 10-28-2013 at 07:20 PM.
    Here to help if I can. If I can't I know someone who can!

  20. #74
    Evil Genius Developer GroovyCarrot's Avatar
    Join Date
    Jan 2012
    Location
    Liverpool, United Kingdom
    Posts
    545
    Thanks
    101
    Thanked 2,119 Times in 466 Posts

    Yeah apparently in checks array keys not values, indexOf is the one you should use

  21. #75
    ----NewD 2.0---- NewdestinyX's Avatar
    Join Date
    Jan 2012
    Posts
    9,893
    Thanks
    4,218
    Thanked 9,026 Times in 4,531 Posts

    Quote Originally Posted by GroovyCarrot View Post
    Yeah apparently in checks array keys not values, indexOf is the one you should use
    I'm aware of the indexOF command.. So you can put a string of different things to check for within the one syntax line?

    So something like:
    if (obj.statecode.indexOf('PA', 'CT', 'MN') != -1) {........} --->returns TRUE for PA, CT and MN

    Is that it?

    Thanks again for all your help,
    Grant
    Here to help if I can. If I can't I know someone who can!

  22. #76
    Evil Genius Developer GroovyCarrot's Avatar
    Join Date
    Jan 2012
    Location
    Liverpool, United Kingdom
    Posts
    545
    Thanks
    101
    Thanked 2,119 Times in 466 Posts

    No you'd have to check each result individually with ||

  23. #77
    ----NewD 2.0---- NewdestinyX's Avatar
    Join Date
    Jan 2012
    Posts
    9,893
    Thanks
    4,218
    Thanked 9,026 Times in 4,531 Posts

    Quote Originally Posted by GroovyCarrot View Post
    No you'd have to check each result individually with ||
    Don't you think the "in" command would be less resource intensive - even with it setting each entry to null?
    Here to help if I can. If I can't I know someone who can!

  24. #78
    Evil Genius Developer GroovyCarrot's Avatar
    Join Date
    Jan 2012
    Location
    Liverpool, United Kingdom
    Posts
    545
    Thanks
    101
    Thanked 2,119 Times in 466 Posts

    No it wouldn't cause the resources are always consumed when allocating memory - and null values in arrays still occupy more memory

    It's a mute point here but you'd understand if you read into data handling and types, I could go on forever but really you'd be better off googling

  25. The Following User Says Thank You to GroovyCarrot For This Useful Post:

    King_O_Hill (11-09-2013)

  26. #79
    King Kong ain't got nothing on me! King_O_Hill's Avatar
    Join Date
    Apr 2011
    Location
    USA
    Posts
    9,341
    Thanks
    41,385
    Thanked 17,483 Times in 6,391 Posts

    Yes Grant, it's not always the amount of code that is written, but more importantly its the resources that it is using that makes efficient code.
    Widget-Weather App Now Available! Also with MyLocation Support!
    Check out the thread here - Widget-Weather
    To install the Widget-Weather app, just go to Cydia and install. This will also remove MyLocation, as it is built in!
    Want to protect your JailBreak! Add this repo http://cydia.myrepospace.com/iLEXiNFO/ & Install "iLEX R.A.T."
    It will allow you to bring your phone back to a fresh jailbroken state!

  27. #80
    ----NewD 2.0---- NewdestinyX's Avatar
    Join Date
    Jan 2012
    Posts
    9,893
    Thanks
    4,218
    Thanked 9,026 Times in 4,531 Posts

    So one huge strand of || statements as compared to 1 neater looking IN command can't be the way you approach it. It's a matter of resources.

    Awesome input guys! Thanks!
    Here to help if I can. If I can't I know someone who can!

+ Reply
Page 4 of 8 FirstFirst ... 23456 ... LastLast
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts