Solved

Any issues with combining logic?

Posted on 2014-04-09
5
114 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 83

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 83

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 83

Expert Comment

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

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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. …
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…

778 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