Solved

Any issues with combining logic?

Posted on 2014-04-09
5
112 Views
Last Modified: 2014-04-09
I'm streamlining my code and I did the following;
    var currVarNm = aa.varMapping('deviceType','props');
    window[aa.prefix][currVarNm] = deviceType.toLowerCase();

Open in new window


and combined to:
window[aa.prefix][aa.varMapping('deviceType','props')] = deviceType.toLowerCase();

Open in new window


Any issues doing this? It works but I haven't checked on anything other than FF.
0
Comment
Question by:894359
  • 3
  • 2
5 Comments
 
LVL 82

Expert Comment

by:Dave Baldwin
ID: 39989534
I'm not sure what the point is since it doesn't speed it up any and makes it harder to read and maintain.  Almost all interpreters these days precompile the code, they don't run it exactly as you type it.  So any attempts at shortcuts are usually meaningless and just make it more difficult to maintain.
0
 

Author Comment

by:894359
ID: 39989757
I just wanted to minimize the # of lines for some code. So you think it is a bad idea then?
0
 
LVL 82

Accepted Solution

by:
Dave Baldwin earned 500 total points
ID: 39989823
Yes, I think it is a bad idea.  I never try to minimize the lines of code.  I try to make it easy for me, the human, to understand because I am the one who has to maintain and modify it.  And the machine doesn't care.  What you did does not minimize the code that is actually run.

In general, I say do not try to be 'clever'.  Write code that you can understand next week or next month.  That is especially true the first time around.  If you can get your code to work when it is clear you might be able to see things that you actually can do better.  But minimizing the lines is rarely going to do that.
0
 

Author Closing Comment

by:894359
ID: 39989931
Thanks!
0
 
LVL 82

Expert Comment

by:Dave Baldwin
ID: 39990001
You're welcome, glad to help.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now