Searching for clean code

Please help the ignorant...
I know there has to be a cleaner way to do this.
First of all, if you have a date field that is empty, the
database records 1900-01-01 00:00:00.0. So...i certainly dont need
to show this in my form.
Secondly, i know there is a smarter way so i dont need to
write a cfinput 3 times. I am hoping for ... more like once...
Thirdly, if there is anything else that you can pick out of
this that i am not advanced enough to see, that would be GREAT!
I thank you in advance for any efforts on my behalf...
Matt

Yes, you could make it a little "cleaner", but it's not bad.
The logic is fine.
You can however, consolidate a few things and in doing so,
separate the logic from the presentation a bit (always a good thing
to do). Look for things that are common among all the
<cfinput> tags. For example, the message is the same for each
version of your <cfinput> tag. Good practice would be to
create a single copy of the message and then use it in the three
places. That way, if you have to change the message, you only have
to change it in one place. Like this:
<cfset variables.errMsg = "The last field that you have
entered, requires a valid date">
Then, within each <cfinput> tag, do:
message="#variables.errMsg#". (BTW, you can make your messge more
succinct. Do you really need to say "the last field you entered"?
After all, this message pops on-blur, so the user knows which
field.)
You could do the same for the other attributes. However, I
notice that all three instances of the <cfinput> tag have the
same attributes, except for the value attribute. But, the tags that
have no value attribute could have been written with value="". If
they were written that way, then the only difference between the
tags is the value of the "value" attribute. I'll show you how to
exploit that, below.
If you are sure that the query always returns a single
record, then you can eliminate the <cfoutput query=...>
element. That save two lines. (if you're not sure, then you should
add some error-checking.)
Also, your if-then should have an else clause. What happens
if the action is something other than "existing" or "new"? You
might say that could never happen, but you might have an error in
your program, or a user could submit his own form to this page with
the wrong action value. Usually, the last thing that a programmer
adds is error-checking. Here, you could add '<cfelse>Unknown
action: <cfoutput>#action#</cfoutput></cfif>'
which might come in handy while developing the program (or you
could put a <cfthrow> tag in there and throw your own
exception). Alternatively, just eliminate the 'action is "new"'
condition. That way, all actions, other than "existing", are
treated as "new".
Taking it all together, here is another way to write your
code. Notice how the logic is separated from the presentation:

Similar Messages

  • I have this formatted search for WharHouse Code in Document

    Hello Experts,
    I have this formatted search for WharHouse Code in Document
    declare @WhsCode char(8)
    if $[ODLN.Series] = '1077' set @WhsCode = '970'
    else set @WhsCode = '01'
    select @WhsCode
    and i would like to add to it:
    If an item has a default warehouse so it is to appear in a row (when not '1077' series) and if the item does not has a default warehouse then the  warehouse  eill be 01.
    Your Help Please!
    Thank You
    Meital

    Hi Meital,
    Try this:
    SELECT CASE WHEN $[ODLN.Series\] = '1077' THEN '970' ELSE ISNULL(T0.DfltWH,'01')
    FROM dbo.OITM T0 WHERE T0.ItemCode = $[$38.1.0\]
    Thanks,
    Gordon

  • Dreamweaver cs5.5 opening files after searching for text code

    This just occured this afternoon.  I was working on a page and when I went to search for text in the code (ie "/head") dreamweaver would open a previously opened page.  In other words I was working on "walk.php" and when I did the search for "/head", dreamweaver opens "add_rsurvey_data.txt".  I know what the 2nd file is but I haven't opened it in months.  It's just a temp data file that my partner sent me.
    I'm using cs5.5
    Adobe will not help me.
    Thanks
    Glenn

    We don't get attachments from email replies here.  You would need to use the Camera icon in the actual web forum to a post screen shot.
    If this began yesterday, try deleting your Cache & restarting DW.
    http://forums.adobe.com/thread/494811
    Nancy O.

  • FCP Searching for time code break on capture

    Hi. I've been filming a few live events and capturing fine. This morning i went to follow the same procedure and Final cut Batch capture keeps searching for a timecode evert couple of minutes. It's looking for a break that isnt there. This means my footage is sticking.
    Any suggestions?

    Do you have a tape that you captured successfully in the past?  If so, try and capture from it.  If it captures properly, the new tape with the problem may be defective.  
    You might try getting a head cleaning tape and see if that helps. 
    What kind of drive are you capturing to?  You might try another drive.   Make sure you have plenty of empty space on all drives connected to the computer including the computer's startup drive.
    Do you have any antivirus software installed on the computer?  if so, turn it off or uninstall it. 
    Have you installed any software or system hacks since you last successfully captured material from this camera?
    You might run diskrepair and disk warrior (if you've got it) on all drives.  You might repair permissions on the startup drive.  You might try deleting fcp preferences.

  • Are you using Blueprints search for Flex Code?

    Blueprints (aka Code Search) is one of the options we provide with Community Search with Flex, in both the browser and the CHC. With Blueprints, your search results are restricted to code samples and a brief blurb.
    You can access the Community Search through the Flash Builder help system.
    We're curious to know how people are using Blueprints/Code Search, so can you please reply telling us:
    * Do you use Code Search in the CHC or the Browser?
    * Do you use the Blueprints Flash Builder/Eclipse plugin?
    * If you use Blueprints, do you find the results useful?
    Thanks very much!
    Stephen Gilson
    Flex Doc Team

    I didn't even know it existed. I'm installing the plugin now. Thanks for putting this out there, it sounds very useful!

  • Local variables for clean code

    A question of style and LV correctness: 
    I'm quite aware of the risks of these guys, but I see no option here. Right now I have a program with ~35 events in an event structure. I have a wire that contains many device settings that only 2 of these events can change. About 6 events in total require the use of the data on this wire.
    Now, I see two choices:
    1) I can use a shift register and drag the stupid wire across 35 frames and then remember to do it in any additional frames when I add more
    2) I can use a local variable.
    This seems much, much cleaner to me, and I see no better way of doing it. My question is, is there? I've looked up feedback nodes, but I think I can only use them in single event cases. Their data doesn't seem accessible beyond one event case. is there some better option? The data on the wire is an array of objects (classes), if that helps. 

    pobrepablo1 wrote:
    Still though, I object on principle to having a wire across every one of my diagrams, it's cluttersome .
    I thought of a compromise, how about I use a shift register but wire it around my event structure, through a case structure breaking the wire only when I need to? i.e. see attached
    So a single thin 1D object across all event cases is more cluttersome than an additional external 2D case structure, partially wired extra tunnels, and all the extra convoluted logic holding it all together? You priorities seem to be biased.
    A nice wire across all cases is much better. It can be read and written in any event case that needs to, and can always be found in exactly the expected location. Remember that a shift register is very efficient. If the data size does not change, it operates fully in place for the duration of the run. It also often contains data that is not directly of interest to the operator so it does not need a display. A local variable requires a front panel object that needs to be updated in the UI thread. In needs a data copy in memory memory for the control/indicator itself as well as another copy for the transfer buffer (because the FP update is asynchronous). Then we have a third copy in the wire itself. Than makes it three copies of your potentially large array. Add another copy for each local variable instance, and you probably end up using 10x more memory compared to a simple shift register. It all adds up!
    Local variables can be placed anywhere and keeping track of them is like herding cats. The next programmer to work on your project will have a hard time tracking them all down. In properly designed code, it is just "follow the wire". Much more clear and almost self documenting.
    LabVIEW Champion . Do more with less code and in less time .

  • UME search for users code problem

    Hello All ,
    i am trying to develop an iview that contains a textbox that get a part of  a userName or User display name and search using UME api`s i wrote the following code:
    public void onSubmit (Event event)throws UMException
           IPortalComponentResponse response = (IPortalComponentResponse)this.getResponse();
         IPortalComponentRequest request = (IPortalComponentRequest)this.getRequest();
    IUserFactory userFactory = UMFactory.getUserFactory();
    IUserSearchFilter sf =userFactory.getUserSearchFilter();
    sf.setDisplayName("p*",1,true);
    ISearchResult sr = userFactory.searchUsers(sf);
    if (sr != null) {
    String uniqueId = (String) sr.next();
    IUser user = userFactory.getMutableUser(uniqueId);
    int i = sr.size();
    Vector users = new Vector();
    IUserFactory userFact = UMFactory.getUserFactory();
    while (i>=0) {
    IUser usr = null;
    usr = userFact.getUser("diana");
    users.addElement(usr);
    i=i-1;
    but i get stuck when i am trying to iterate thro the result set can any one enlighten my eyes of what i am doing wrong or about the right way to approach the Problem
    Thanks
    Ronen

    Hi Ronen,
    first, to make code more readable, please use [ code ] and [/ code ] (without the spaces) to format pure code.
    ISearchResult is to be used like every other Iterator, so:
    ISearchResult sr = userFactory.searchUsers(sf);
    ArrayList users = new ArrayList(); /* instead of Vector! */
    while (sr.hasNext()) {
      String uniqueId = (String) sr.next(); /* if this is the case, I don't know */
      IUser user = userFactory.getMutableUser(uniqueId);
      users.add(user);
    Hope it helps
    Detlev

  • Search site wide for invalid code

    I have over 1000 pages on my website. occasionally  i open a page and find a dialogue box stating invalid code (with no option of fixing) how can i do a site wide search for invalid code displaying the results such as in the search or site wide properties box. For example which page has problems with a click to the source

    Deutschy,
    If you actually have a local copy of the site, you can do a Validate Entire Local Site right in Dreamweaver, though you might actually want to Validate Selected Files, if you have that many pages!
    That will show you file and line numbers and what the errors are, for everything it turns up.
    Within the Validation Results Window, you can double click on an error citation to open the file and highlight the code error.
    That's the beauty of working within Dreamweaver to Validate..instant access to the code you need to change.
    Z

  • Search for RFCOMM implementation

    Hi, I'm developping some apps. for transferring files from a Set-top-box to a cell phone.
    The STB runs JavaTV, with no BT stack implementation (no BT hardware too), but I'm managing to attach a serial BT dongle to it and run the JavaBluetooth (javabluetooth.org) stack over it.
    Currently I'm runing the JavaBT on a PC, but the RFCOMM and other high-level layers were not implemented on this stack.
    I need only the an outputStream (SPP) over the BT link, wich is implemented in the RFCOMM layer.
    JavaBluetooth currently supports L2CAP, fully as far as I know, so before starting to write an RFCOMM over the L2CAP layer provided I'm searching for some code already builded.
    Does anyone knows where can I get the sources from a RFCOMM implementation over a JSR82 L2CAP connection.
    any ideas may help, thanks

    Hi,
    I am working with the Minshara, but I find it like a black box.. nothing is transperant except the RFCOMM layer. They had infact built the entire RFCOMM on top of the javabluetooth.org.
    There is the BCC implementation as recommended by the JSR-82 spec. I tried to discover devices and services, it does it although a bit of work around is needed.
    I was able to retrive the serviceURL which is supposed to open a StreamConnection. I am stuck at this point. It just hangs up there. doesnt open me a StreamConnection.
    Would be nice to know if there is anyone who had tried this.
    Cheers
    Domnic

  • Field for packaging code

    Hi all,
    i am searching for packaging code field.my packaging code data is comming in the table THM073-pacod or THM074-pacod.
    but how to relate this table with packaging material which is present in mara table.
    i am writing a report for delivery order.here we are using packaging material like carton & pallet.we have created this packaging materials in material master.for this packaging material, i have to refer a packaging code which is present in THM073 table.
    plz suggest me how i can extract that data from that table.it is very very urgent.
    any help is highly appreaciated.
    Regards
    pabitra

    Hi Pabitra,
           You can find the relationship between Dangerous Goods Regulation and Material in table DGTMD. Using this relationship you can link Material and PACOD using table THM073.
           Hope this will solve your problem.
    Regards,
    Sathish
    Note : Reward useful Answers

  • Any way to search for casts in java source code?

    Anyone know of a decent way to search your java source files to find all the casts?
    I ended up doing a simple text search for
         " = ("(quote marks not included) which works for my code because I am strict about writing my casts with spaces like
         String s = (String) iterator.next();Unfortunately, the above search has all kinds of problems with both false positives and negatives. It picks up lots of irrelevant lines like
         int index = (number > 0) ? 0 : 1;as well as misses casts that appear nested inside expressions like
         ((String) iter.next()).charAt(...)I suppose that one could do a regular expression search for any pair of open and close parens which bound non-blank text, but that would pick up even more non-cast expressions in typical java code.
    I think that the only way to properly do this is to have a tool which understands java syntax.
    Anyone know of an IDE which will do this? Does IntelliJ or Netbeans support this kind of search?
    In case you are wondering why I am interested in this, it is because I am refactoring some code to fully use generics, and searching for casts is one source of identifying candidates for genericity.

    cliffblob wrote:
    Better late than never?Yes!
    cliffblob wrote:
    ...The answer I found to ID unnecessary casts was, using Eclipse IDE, In compiler error and warning preferences to warn on unnecessary casts.Thanks for pointing IDEs out. I just opened IntelliJ, and going back to at least version 7.04 (maybe earlier) they have an inspection for "Redundant type cast".
    cliffblob wrote:
    I would still be interested to know if there is a way to identify casts in general in your source, perhaps now four years later there is a way?The only solutions that I can think of are either a complicated regex search, or you must use some tool like an IDE that understand Java syntax and can determine if a cast is happening.

  • How do I search for a specific word in the code using Dreamweaver?

    I need to search for a specific word in the code for all of my website pages. How can I do that using Dreamweaver?

    To search local files of a Defined Site in DW...
    Open the Find & Replace tool with Ctrl + F
    Change the Find In dropdown to Entire Current Local Site
    Change the Search dropdown to Text or Source code
    Add the text to find in the Find field
    Add the text to replace in the Replace field (or nothing if you just want to delete the text)
    Hit Replace All

  • BP search for General and Company Code roles

    Hi
    On the modify Money Market Transactions (TM_52) (and some similar to it for other products TS02, TM32, TO02), if i go to the Partner Assignment Tab and I try to assign a bp for the General or the Company Code roles, the bp search program give me no results.
    If i try to do the search for the Counterparty role it gives me the results I expect.
    Is there any reason for do not give any result when these roles are the primary roles that, of course, the bp I choose has? Is it a program problem (this program has returned me some dumps and I implemented some Notes on it before)? If so, is there any solution?
    I want to assign these roles because I hope that these assignments with these roles modify the payment data or the master data of the transaction.
    Thanks

    Hi
    This is a very common topic.
    look at this thread:
    Authorization in reports
    Here's a starting point ...
    http://help.sap.com/saphelp_bw33/helpdata/en/72/eeb23b94c6e54be10000000a11402f/frameset.htm
    Outline steps...
    In RSSM:
    Create authorization object
    Make authorization object applicable to relevant InfoProviders
    In PFCG:
    Add authorization object to new or existing Roles with appropriate field assignments
    Make User/Role assignments
    Reg's
    Edan

  • How to search for a string in ALL Function Modules source code

    Hello,
    I want to search for the string "HELLO" in all FUNCTION MODULES source code(FM, no reports/programs).
    Is this possible? How?
    Cheers,
    Andy

    hi,
    Execute RPR_ABAP_SOURCE_SCAN to search for a string in the code ... Press where-used-list button on the program which takes to the function group or the function module where it is used ..
    Regards,
    Santosh

  • Search for users in a particular LDAP through Web Dynpro code...

    Hi Experts,
    Let me try explaining my problem. In my project we are using two ADAM LDAPs. One for storing internal users and the other for storing external users. I have configured the portal to connect to both the LDAPs. I am able to search for the users created in both the LDAPs through portal Indentity Management.
    I am trying to search for the users in a specific LDAP through Web Dynpro coding... I am not lucky enough to get it done. Let me explain you what I did.
    I created a custom attribute for UME through config tool. Gave a physical mapping for the custom attribute in dataSourceConfig_xxx.xml to the LDAP attribute distinguishedName which returns the distinguished Name for the user in ADAM LDAP.
    For Example: Custom attribute in UME is ldapuser which is mapped to distinguishedName attribute in ADAM LDAP in dataSourceConfig_xxx.xml.
    When I do a search for the users in a particular LDAP, I am trying to put a filter to the newly created ldapuser attribute to distinguish between the two LDAPs.
    The search will result if I pass the value as '*'. If I try to specify the user path for the LDAP in this attribute it doesnt result any data.
    For example:
    userSearchFilter.setSearchAttribute(
         "com.sap.com.cust.admn",
          "ldapuser",
         "OU=16482515,OU=Members",
         ISearchAttribute.LIKE_OPERATOR,
         false);
    The above code will not return the data, whereas
    userSearchFilter.setSearchAttribute(
         "com.sap.com.cust.admn",
          "ldapuser",
         ISearchAttribute.LIKE_OPERATOR,
         false);
    Will result with user list from both the LDAPs.
    If anyone tried searching for users in a particular LDAP through code, please help me with this issue.
    Thank you in advance.
    Regards,
    Rekha Malavathu

    I just figured it out. Under "group-policy GroupPolicy_COMPANY_SSL_VPN attributes", I had to add "vpn-simultaneous-logins 15". Apparently, it was using the value "vpn-simultaneous-logins 0" under the NOACCESS group policy.

Maybe you are looking for