Any usefull examples of good coding practice in large programs
Hi, ive been writing code for about 10 years now. Know a good bit about labview now lmao! But want to get to know good code practices e.g. in creating large programs, code templates, avoiding race conditions, use of multiple loops and to be able to write code for clients as a contractor. Any one help me??
Stu
Solved!
Go to Solution.
Check out thelargeapp community and this KB article
Message Edited by Jeff Bohrer on 06-14-2010 04:49 PM
Jeff
Similar Messages
-
Example of a nonsense code below
for (int i=0; i < 10; i++)
int total = i + 1;
System.out.println(total);when excute, total will be redeclared 9 times, compiler doesn't complain. But is this clean?
A better code below?
int total;
for (int i=0; i < 10; i++)
total = i + 1;
}My query is whether the "buffer" inside the loop ok?It's fine where it is. The compiler calculates how many slots on a stack
are needed for all local variables. Those slots are allocated from the
stack upon entry of the method and removed when the method returns.
Note that the amount of slots needed is not necessarily the same as
the total number of local variables:void foo() {
int i; // slot 1
for (int j= 0; j < 10; j++) // slot 2
for (int k= 0; k < 10; k++) // slot 2 again
}kind regards,
Jos -
Good coding practice for object init
We have a code that requires initializing instance of the object for each item in the loop. I have following option in mind. Please advice which one is the best option. TIA
Option 1
=======
public class AThread extends Thread {
private ObjectA var1 = null;
private ObjectA var2 = null;
public AThread() {
this.var1 = new objectA();
public void run() {
while ( ... ) {
if (var2 != null) {
var2 = null;
var2 = var1;
var2.callmethod();
Option 1
=======
public class AThread extends Thread {
private ObjectA var1 = null;
public AThread() {
public void run() {
while ( ... ) {
var1 = new objectA();
var1.callmethod();
var1 = null;
}1. If in the future, you post code, you can make it much more readable by enclosing it in the [code][/code] tags.
2. Why not implement Runnable instead of extend Thread? You're not creating a new type of thread, so it is more "OO"-sensible to create a new Runnable and run it.
3. In the first Option 1, you might as well just be doing
while (...) {
var1.callMethod();
}Assigning the reference to another variable does not create a new instance of the object, so it is not worthwhile to create a new reference to it just to call its methods.
4. In option 2, setting the object's reference to null at the end doesn't really help anything, because the object is going out of scope anyway and will be destroyed.
Your question, really, between the two options, is as follows: should you recreate and destroy the object for every iteration through the loop, or just call the method multiple times? -
Coding Practice for Bound Property Names
I think this simply an issue over coding practices, but if I am right then all the tutorials and documentation on how to write Beans are promoting poor coding practices. Speicifcally, it bugs me that String literals are always used in all the code I see. As in the following code:
class MyBean {
public void setValue(value newValue) {
beansupport.firePropertyChange("value", oldValue, value);
}the practice that I have starting using is:
class MyBean {
public static final String propertyValue = "value";
public void setValue(value newValue) {
beansupport.firePropertyChange(propertyValue, oldValue, value);
}This way, a PropertyChangeListener can refererence MyBean.propertyValue instead of using the literal "value" -- eliminating the chance for error and also there don't have to be multiple literals floating around using up space. Is there any reason this isn't commonly accepted practice or did I miss something?Strings appearing in source code can be reduced to a constant, like an enum. So it is likely that the code with strings is actually faster, as the value is known before compilation. It is easier to read. Keep in mind that strings get interned every now and then and thus get reduced to this equivalency:
public method blah( "value", some stuff )...
public method nah(*){ do stuff; let x = "value"; more stuff with "zoiks!" }
ends up like
key k1 = "value"
key k2 = "zoiks!"
what the jvm sees;
public method blah( key1, some stuff )...
public method nah(*){ do stuff; let x = key1; more stuff with key2 }
The string values get "inlined" and can be checked during compilation, allowing for many optimisations not otherwise possible.
Hope that helps a little.
Andrew -
Coding Practice(GV$SESSION)
Hi
Recently there was an issue of 1 procedure running in parallel through 2 different sessions and causing some irregular results.
So, I changed the code in such a way that when the procedure runs then it sets the module and action in the GV$SESSION view.
exec DBMS_APPLICATION_INFO.SET_MODULE ('MOD', 'ACT3000');
So whenever the procedure runs it first checks in GV$SESSION whether ACTION with the name ACT3000 is running or not, if not it runs,else it exits.
The question I have here is that is it a bad coding practice to select from the view GV$SESSION or any other system views in a procedure or an anonymous block?
Regards
AnkitThe question I have here is that is it a bad coding practice to select from the view GV$SESSION or any other system views in a procedure or an anonymous block?Probably there's no general answer to this. Sometimes it is just necessary to to query system views, sometimes you might think it over again - in particular for performace reasons.
In your case you also have the alternative of querying sys_context to get the information you wanted:
SQL> select sys_context('userenv','module') module, sys_context('userenv','action') action from dual;
MODULE ACTION
SQL*Plus
SQL>..whereby dual itself is a system view/table ;) -
Hi
are there any best coding practices for EP development?can anybody suggest the material?
PrasadEP, as in Enterprise Portal?
James -
I got an iphone today....and I love it!!!!!!!!
I turned it on and have used it today and the battery is almost gone....should I wait until the battery is completely drained before I plug it into the wall socket? Also, is it good for the battery and the phone in general to leave it plugged into the wall all night long, like I did with my old cell phone?
What are good battery practices in general for the iphone? I want to be able to use it without it dying out on me everyday, especially when I need to call someone. I don't know how to use it much....are there application or web things that I could turn off while they are not in use in order to conserve battery power? (How do I turn off edge? The E is constantly on the top of the screen...if I could turn it off, wouldn't that conserve power?)
Any other conserving of power practices would be appreciated!
Thank you!!!Apple put together a great page on the iPhone battery, check out the link below
http://www.apple.com/batteries/iphone.html
hope this helps -
I've just recently ordered my MacBook-- and though I haven't received it yet, I am still curious about good battery practice. If anything, I really want mine to last, and typically if asking just anybody off the street you'll get everything from "put your battery in the freezer" to "take out your battery, when not in use".
Any thoughts? Should I charge it fully, then let it run out before I recharge? Should I use the adapter whenever I have the chance, regardless of the battery charge?
I'm also curious whether I have to charge the battery before first use out of the box-- I looked through manual online, and I didn't see anything on that topic.intheam wrote:
Any thoughts? Should I charge it fully, then let it run out before I recharge? Should I use the adapter whenever I have the chance, regardless of the battery charge?
It is OK to leave your battery hooked to the charger most of the time. The only time I unhook mine from the charger is when I calibrate or for a few minutes to use in another room. You should calibrate every two months or so to keep the battery fully functioning. If you use your MacBook infrequently, it’s best to re-calibrate the battery at least once a month.
It is best not to use your battery unless you need to. Some people have hurt their batteries by charging then discharging every time they use the MacBook. This will age a battery very fast and cause you to buy a battery sooner than you should have too. Don't discharge the battery just because you used it. Li-Ion batteries prefer small charges over big ones. Use it and then plug it in as soon as you can. The only time my Battery is ever fully discharged is when I'm doing a calibration.
The following links have good information about the MacBook and the care of it's battery.
Apple: Tips for maximizing your Notebook battery charge
Apple MacBook and MacBook Pro: Reduces processor speed when battery is removed while operating from an A/C adaptor
Apple portable computer's battery does not show a full charge in Mac OS X
Look here and here for some good tips about battery care.
Apple MacBook: How to remove or install the battery
Apple: Determining Battery Cycle Count
Apple: Use and cleaning of MagSafe power connector
I'm also curious whether I have to charge the battery before first use out of the box-- I looked through manual online, and I didn't see anything on that topic.
No just plug in your power supply and have fun. It will charge whie your using it. If you follow my other tips you should get long life out of the battery. -
I am looking for free newsletter templates or free editable examples of good newsletters made using InDesign CS3. Anyone know of a great spot for finding these?
That would make sense if it opened a template folder but it opens the most recent Bridge folder I had open.
Edit: Just tried it again and the template folder came right up. Thanks. -
How to follow best coding practices and make this code runable.
How to change this code to make it work and follow best coding practices.
This code is to add fields to internal table LIST which already exist.
In the loop are all the selections which are to be made.
But i am new to ABAP and not sure how to make this work.
please help me.
DATA: wa_list LIKE LINE OF list,
l_v_index TYPE i.
DATA: t_price_result1 TYPE STANDARD TABLE OF komv WITH HEADER LINE INITIAL SIZE 0.
DATA: wa_result LIKE LINE OF t_price_result1.
LOOP AT list INTO wa_list.
l_v_index = sy-tabix.
*GET MATERIAL DOCUMENT(MBLNR) AND DELIVERY NUMBER(XBLNR)
SELECT mkpf~mblnr
mkpf~xblnr
into (wa_list-mblnr, wa_list-xblnr )
* INTO i_list
from mkpf inner join mseg
* up to 1 rows
on mkpf~mandt = mseg~mandt
and mkpf~mblnr = mseg~mblnr
and mkpf~mjahr = mseg~mjahr
where mseg~matnr = wa_list-matnr
and mseg~charg = wa_list-charg
and mseg~kunnr = wa_list-kunnr
and mseg~sobkz = wa_list-sobkz
and mseg~werks = wa_list-werks
and mkpf~budat in budat.
"RFC3762
ENDSELECT.
wa_list-mblnr = list-mblnr.
wa_list-xblnr = list-xblnr.
* GET POSNR FROM TABLE LIPS
SELECT posnr
FROM lips
INTO list-posnr
up to 1 rows
WHERE vbeln = wa_list-xblnr AND
matnr = wa_list-matnr.
ENDSELECT.
wa_list-posnr = list-posnr.
* GET SALES ORDER #
SELECT vbelv
FROM vbfa
INTO list-vbelv
up to 1 rows
* INTO wa_list
WHERE vbeln = wa_list-xblnr.
ENDSELECT.
wa_list-vbelv = list-vbelv.
*GET PO
SELECT bstkd
FROM vbkd
INTO list-bstkd
up to 1 rows
WHERE vbeln = wa_list-vbelv
AND posnr = 0.
ENDSELECT.
wa_list-bstkd = list-bstkd.
*get serial number
SELECT SINGLE obknr
FROM ser01
INTO list-obknr
WHERE lief_nr = wa_list-xblnr
AND posnr = wa_list-posnr.
wa_list-obknr = list-obknr.
SELECT sernr
FROM objk
INTO list-sernr
up to 1 rows
WHERE obknr = wa_list-obknr.
ENDSELECT.
wa_list-sernr = wa_list-sernr.
*get date
SELECT budat FROM mkpf
INTO list-budat
up to 1 rows
where mblnr = wa_list-mblnr.
ENDSELECT.
wa_list-budat = list-budat.
*get CLP
SELECT vkorg vtweg spart
INTO (list-vkorg, list-vtweg, list-spart)
up to 1 rows
FROM vbak WHERE vbeln = wa_list-vbelv.
ENDSELECT.
wa_list-vkorg = list-vkorg.
wa_list-vtweg = list-vtweg.
wa_list-spart = list-spart.
SELECT pstyv
INTO list-pstyv
FROM vbap
up to 1 rows
WHERE vbeln = wa_list-vbelv AND posnr = wa_list-posnr.
ENDSELECT.
wa_list-pstyv = list-pstyv.
CALL FUNCTION 'Z_SD_PRICING_CONDITION'
EXPORTING
i_organization = wa_list-vkorg
i_dist_channel = wa_list-vtweg
i_division = wa_list-spart
i_customer = wa_list-kunnr
i_plant = wa_list-werks
* i_pricng_date = sy-datum
i_material = wa_list-matnr
* I_SALES_UNIT = 'EA'
* I_QUANTITY = '1.000'
i_stor_loc = '0001'
i_item_cat = 'TAN'
* I_AUART =
* I_REFRESH = 'X'
* I_KOMP =
* I_KOMK =
* IMPORTING
* E_MES_TYPE =
* E_MES_NUMBER
* E_MESSAGE =
TABLES
t_price_result = t_price_result1
* EXCEPTIONS
* CUSTOMER_NOT_FOUND = 1
* PLANT_NOT_FOUND = 2
* MATERIAL_NOT_FOUND = 3
** PLANT_MATERIAL_NOT_FOUND = 4
* SALES_DATA_NOT_FOUND = 5
* ORG_UNIT_NOT_FOUND = 6
* UNABLE_TO_CALCULATE_PRICE = 7
* UNABLE_TO_FORMAT_PRICE = 8
* MANDATORY_INFOR_MISSING = 9
* OTHERS = 10
LOOP AT t_price_result1.
IF t_price_result1-kschl = 'ZPR2'.
wa_list-kbetr = t_price_result1-kbetr.
ELSE.
wa_list-kbetr = 0.
ENDIF.
ENDLOOP.
MODIFY list FROM wa_list INDEX l_v_index.
ENDLOOP.Hi,
Lets first start from your Select Statement.....Replace your SELECT ....ENDSELECT by SELECT Into Internal Table
Your program is having a SELECT...ENDSELECT within LOOP...ENDLOOP........One should avoid doing this as far as possible.
SELECT mkpf~mblnr
mkpf~xblnr
INTO itab
for all entires i_list
from mkpf inner join mseg
on mkpfmandt = msegmandt
and mkpfmblnr = msegmblnr
and mkpfmjahr = msegmjahr
where mseg~matnr = i_list-matnr
and mseg~charg = i_list-charg
and mseg~kunnr = i_list-kunnr
and mseg~sobkz = i_list-sobkz
and mseg~werks = i_list-werks
and mkpf~budat in budat.
Restructure youe complete code with this approach and Share your Finding's.
You can also think of using a SAP Standard FM.
Anyway..What is the objective/Output of this report? -
Any setting example in congig.xml to create a NTRealm?
Hi,
Is there any setting example(in config.xml) for NTRealm since I am not able
to create one from the admin console?
Thanks!Hi,
Is there any setting example(in config.xml) for NTRealm since I am not able
to create one from the admin console?
Thanks! -
I need to use sigma plot in my Mac, does any one has a good advise for alternatives. If not, will it be ok to install windows in my mac?
See if Deltagraph is still around. We used to use that for plotting scientific data on Macs. I don't know if it is at all transferrable with Sigmaplot if you have a colleague who uses it, but if you're doing this on your own I would look at getting DG vs, doing a dual boot etc.
-
MQ + OpenLdap: Any working example of LDAP configuration?
MQ + OpenLdap: Any working example of [LDAP configuration], [LDIF initial data] and [imobjmgr addTopicFactory/addTopic command] files ?
I'm using Sun MQ3.5 + OpenLdap2.2.20 as jndi remote binding mechanism.
I've unsuccessfuly tryed to add a Topic Factory!
Running the command
imqobjmgr -i add_ldap_topic_factory.poperties
I get such an exception:
javax.naming.OperationNotSupportedException:
[LDAP: error code 53 - no global superior knowledge];
remaining name 'cn=myTopicConnectionFactory'
This is the test configuration adopted using rootdn user to write to LDAP repository:
#slapd.conf
include /usr/local/etc/openldap/schema/core.schema
database bdb
suffix "dc=imq,dc=com"
rootdn "cn=Manager,dc=imq,dc=com"
rootpw secret
directory /usr/local/etc/openldap/var/openldap-data
index objectClass eq
#test.ldif
dn: dc=imq,dc=com
objectClass: dcObject
objectClass: organization
dc: imq
o: imq
#add_ldap_topic_factory.poperties
version=2.0
cmdtype=add
obj.type=tf
obj.lookupName=cn=myTopicConnectionFactory
obj.attrs.imqAddressList=mq://localhost:7676/jms
objstore.attrs.java.naming.factory.initial=com.sun.jndi.ldap.LdapCtxFactory
objstore.attrs.java.naming.provider.url=ldap://localhost:389/o=imq
objstore.attrs.java.naming.security.principal=cn=Manager,dc=imq,dc=com
objstore.attrs.java.naming.security.credentials=secret
objstore.attrs.java.naming.security.authentication=simple
Thanks for any suggestion,
SilvanoAgreed.
I've been wanting to test the steps and write a tech article on this
and post it to somewhere on sunsolve.sun.com but have not had
time yet.
In any case, the instructions Ken-shi gave are below including
the 3 files (etang.ldif objectstore.properties slapd.conf). Not sure
how messy this posting can get due to size of files.
I'd much rather point you to a sunsolve article but don't want
to make you wait. When I do post the sunsolve article, this thread
will be updated with a ptr to it.
===Begin instructions===
Attached please see my working configuation files.
1.Modify your OpenLdap configuration. (see slapd.conf)
start OpenLdap: ./slapd
2.Modify you initial data.( see etang.ldif)
load initial data: ldapadd -x -D "cn=Manager,dc=etang,dc=com" -W -f
etang.ldif
3.ObjectStore properties ( see objectstore.properties )
create your object store with "Administration" GUI on windows;
while creating destinations or connection factories, be sure that the
lookup names start with "cn=".
===End instructions===
===Begin etang.ldif===
dn: dc=etang,dc=com
objectClass: dcObject
objectClass: organization
dc: etang
o: Etang Corporation
description: The etang corporation
dn: cn=Manager,dc=etang,dc=com
objectClass: organizationalRole
cn: Manager
description: Directory Manager
dn: o=IMQ,dc=etang,dc=com
objectClass: organization
o: IMQ
dn: ou=imqusers,o=IMQ,dc=etang,dc=com
objectClass: organizationalUnit
ou: imqusers
dn: cn=admin,ou=imqusers,o=IMQ,dc=etang,dc=com
objectClass: person
cn: admin
sn: admin
userPassword: admin
dn: cn=guest,ou=imqusers,o=IMQ,dc=etang,dc=com
objectClass: person
cn: guest
sn: guest
userPassword: guest
===End etang.ldif===
===Begin objectstore.properties===
java.naming.provider.url ldap://10.1.0.195:389/o=IMQ,dc=etang,dc=com
java.naming.factory.initial com.sun.jndi.ldap.LdapCtxFactory
java.naming.security.principal cn=admin,ou=imqusers,o=IMQ,dc=etang,dc=com
java.naming.security.authentication simple
java.naming.security.credentials admin
===End objectstore.properties===
===Begin slapd.conf===
# See slapd.conf(5) for details on configuration options.
# This file should NOT be world readable.
include /usr/local/openldap/etc/schema/core.schema
include /usr/local/openldap/etc/schema/cosine.schema
include /usr/local/openldap/etc/schema/inetorgperson.schema
include /usr/local/openldap/etc/schema/dyngroup.schema
include /usr/local/openldap/etc/schema/java.schema
include /usr/local/openldap/etc/schema/nis.schema
include /usr/local/openldap/etc/schema/misc.schema
# Define global ACLs to disable default read access.
# Do not enable referrals until AFTER you have a working directory
# service AND an understanding of referrals.
#referral ldap://root.openldap.org
pidfile /usr/local/openldap/var/run/slapd.pid
argsfile /usr/local/openldap/var/run/slapd.args
# Load dynamic backend modules:
# modulepath /usr/local/openldap/libexec
# moduleload back_bdb.la
# moduleload back_ldap.la
# moduleload back_ldbm.la
# moduleload back_passwd.la
# moduleload back_shell.la
# Sample security restrictions
# Require integrity protection (prevent hijacking)
# Require 112-bit (3DES or better) encryption for updates
# Require 63-bit encryption for simple bind
# security ssf=1 update_ssf=112 simple_bind=64
# Sample access control policy:
# Root DSE: allow anyone to read it
# Subschema (sub)entry DSE: allow anyone to read it
# Other DSEs:
# Allow self write access
# Allow authenticated users read access
# Allow anonymous users to authenticate
# Directives needed to implement policy:
# access to dn.base="" by * read
# access to dn.base="cn=Subschema" by * read
# access to *
# by self write
# by users read
# by anonymous auth
# if no access controls are present, the default policy
# allows anyone and everyone to read anything but restricts
# updates to rootdn. (e.g., "access to * by * read")
# rootdn can always read and write EVERYTHING!
access to * by * write
# ldbm database definitions
database bdb
suffix "dc=etang,dc=com"
rootdn "cn=Manager,dc=etang,dc=com"
# Cleartext passwords, especially for the rootdn, should
# be avoid. See slappasswd(8) and slapd.conf(5) for details.
# Use of strong authentication encouraged.
rootpw secret
# The database directory MUST exist prior to running slapd AND
# should only be accessible by the slapd and slap tools.
# Mode 700 recommended.
directory /usr/local/openldap/var/openldap-data
# Indices to maintain
index objectClass eq
===End slapd.conf=== -
Is there any code example for "Web Survey"?
Hi buddies,
In the standard SRM Web Survey scenario, the experts submit questionnaire online. But our custmer want it offline.
So we use offline Adobe Forms, the problem is after we get the data by uploading the offline PDF, how we put the data into the standard Web Survey. Is there any function moudle , BAPI, class for this purpose? Is there any code example?
Thanks!
HaoI have tried to write some report using pch logical database and successed.
在报表自身中,从 GET OBJEC 点,作为规定,数据库驱动程序将文件 PLOG 中的选定的选择恢复为规定的并检查权限。
指令 TABLES 中结构声明是前提。若除了结构 OBJEC,还定义结构 GDSTR,则将结构评估的参数添加到标准选择屏幕。这可以通过评估路径进行结构评估。
REPORT ZPHC_TEST.
TABLES : objec.
infotypes: 1000.
INITIALIZATION.
START-OF-SELECTION.
get objec.
WRITE : p1000-objid.
end-of-SELECTION. -
Any recomendation to a good Converter Software? .MOV to .M4P .WMP?
Any recomendation to a good Converter Software? .MOV to .M4P .WMP?
I have a .mov file of 2.44GB... and I need to reduce that by converting it to other format... So I was looking for a good software free for Mac.
Thanks'You'll need additional for .wmv conversion. Flip4Mac isn't free (the player is free, but not the upgrade to convert).
Maybe you are looking for
-
so I have an iPhone 5c bought last summer, so it's not even a year old. I have never had any problems with the wifi until a day ago. Yesterday I updated to ios8.2 and my pone became really slow and buggy. And it won't connect to the wifi. I checked o
-
How to restrict the charactersitic values in reporting
Hi All, I have a CCA report with characterstic "GL Accont". Instead of displaying the complete characteristic values i want to display the first 3 characters out of EIGHT characters in that report( say "10003WW", i need to display it as "100" only).
-
Commandbutton inside popup does not fire action/actionlistener methods
Hi, I am using 11.1.1.4.0 I have a page and on click of a button on that page, I launch a popup (using showpopupbehaviour, triggertype="click") which has a region (taskflow) inside it. The region is within a af:panelWindow inside the popup. I have al
-
Hi I have a requirement of creating a user identity in OIM 11gR2 only when few set of attributes say FirstName, MiddleName and Lastname. If this set of attributes are not exist in OIM then only we have to create the user otherwise not. So for this pu
-
Change date/time layout in server.log to show milliseconds
Hi, I need to debug the JDBC session to find delays in my source. I used following to get the JDBC debug info: -Dweblogic.Debug=weblogic.JDBCConn,weblogic.JDBCSQL My problem is that the layout of the server log file does not show the milliseconds, it