How to deal with poorly designed code

Hello, everyone.
I have a problem with some program that I wrote starting my career as a programmer.
At first I studied a lot and wrote this program in java with poor design solutions in mind.
My code looked like procedural(I studied c before) object oriented freak.
And as a result even I could hardly modify my code. I had to spend hours
remembering what each function in class did.
And some time after that my boss asked me to write one new feature which actually changes
architecture a lot. Even if it was good object oriented code, it would take some time. But now
it takes a great amount of struggle and patience to rewrite my ugly code and implement this
new feature.
So I'm asking you developers out there: How do you deal with such situations when for example
someone wrote very bad piece of code and you have to change/modify it to support new requirements?

Dusty wrote:
Xyne wrote:Refactoring isn't fun
I'm filing this under 'complete and utter bullshit' I read on the first of the fourth month. :-P
I love refactoring, taking something good and making it great. The eternal search for perfection just outside your grasp.
Dusty
Yarrrr, because what's more fun than pouring effort into something to end up with the exact same functionality that you started with?
Finding new and better ways to do things is fun and you definitely improve your coding skills when you go back and pick apart the hack-n-slash stuff you've written before, but overall I don't think it's fun (unless you're truly doing it only for yourself, i.e. no obligations, no deadlines, etc).

Similar Messages

  • How to deal with context dependant code lists?

    Hi ByD studio forum,
    recently one of the ByD solution partner raised an interesting questing regarding context dependant codelists. I create this thread to share the question and the answers (provided by Thomas Schneider) to it with the community.
    Most of the ByD codelists are context independant and contain a list of unique values. Some of the codelists (i.e. WorkAgreementAdministrativeCategoryCode) are context dependant and the code value is only unique within a certain context, i.e. country, region.
    Example - WorkAgreementAdministrativeCategoryCode:
    List ID
    Code Value
    Description
    AT
    1
    Hourly
    AT
    2
    Salaried Employee
    AT
    3
    Manager
    AU
    1
    Hourly
    AU
    2
    Salaried Employee
    AU
    3
    Manager
    BE
    1
    Hourly
    BE
    2
    Salaried Employee
    BE
    3
    Manager
    BR
    1
    Salaried Employee
    In a custom BO a element typed with an context dependant codelist is defined and should be placed on a custom UI.
    import AP.Common.GDT as apCommonGDT;
    businessobject CodeListMapping_Test {
                 element CustomerWorkAgreementAdministrativeCategoryCode : WorkAgreementAdministrativeCategoryCode;
    In UI-Designer however is the required ListID not available by default:
    So how can a ByD studio developer deal with context dependant codelist?
    Best regards,
    Ralf

    Hi Ralf,
    you need the contxt of the GDT in the BO: 
    import AP.Common.GDT as apCommonGDT;
    businessobject CodeListMapping_Test {     element CountryCode : CountryCode;
       element CustomerWorkAgreementAdministrativeCategoryCode :
                    WorkAgreementAdministrativeCategoryCode;
    As a next step, go to the UI designer, select the data element CustomerWorkAgreementAdministrativeCategoryCode.content, and select "Codelist Context Mapping" from the context menu. You can maintain the context of the structured code as shown in the following figure:
    Save and activate the UI model. The result is as follows:
    If you set the CountryCode field (via UI or via coding) the Customer....Code code list is filterted by the country code. You can also set the Customer....Code.listID in ABSL code if the element is filled via code.

  • How to deal with the growing table?

    Every tables are growing in any applications. In some applications, tables become larger and larger quickly. How to deal with this problem?
    I am developing an application system now. Should I add a lot of delete commands in the code for each table?

    junez wrote:
    Every tables are growing in any applications. In some applications, tables become larger and larger quickly. How to deal with this problem?
    I am developing an application system now. Should I add a lot of delete commands in the code for each table?Uh, well, yes if you continually add rows to a table the table will grow ... sooner or later you will want to delete rows that are no longer needed. What did you expect? You have to decide what the business rules are to determine when a row can be deleted, and make sure your design allows for such rows to be identified. This is called ..... analysis and design.

  • How to deal with OpenCL grey out issue.

    First off, I'm not native english speaker.
    I have Nvidia GeForce 550 Ti video card, and its support OpenCL v1.1.
    I'm also face a "random" OpenCL grey out issue like other people here, but I found the "issue" and how to deal with.
    open a command windows (using WinKey + R, and type cmd <enter>)
    type "cd C:\Program Files\Adobe\Adobe Photoshop CS6 (64 Bit)" <enter>
    type "sniffer_gpu" <enter>  -->> to check your GPU has OpenCL in Photoshop?
    When GPU is in power-saving mode (core running in 51Mhz, using MSI Afterburner monitor), I running sniffer_gpu, got this report
    C:\Program Files\Adobe\Adobe Photoshop CS6 (64 Bit)>sniffer_gpu
    Device: 0000000000328D68 has video RAM(MB): 1023
    Vendor string:    NVIDIA Corporation
    Renderer string:  GeForce GTX 550 Ti/PCIe/SSE2
    Version string:   3.0.0
    OpenGL version as determined by Extensionator...
    OpenGL Version 3.0
    Has NPOT support: TRUE
    Has Framebuffer Object Extension support: TRUE
    OpenGL ok
    Return code: 1
    C:\Program Files\Adobe\Adobe Photoshop CS6 (64 Bit)>
    No OpenCL support
    Then, I switch GPU back to normal status (core running at 900Mhz)
    C:\Program Files\Adobe\Adobe Photoshop CS6 (64 Bit)>sniffer_gpu
    Device: 00000000001F8D68 has video RAM(MB): 1023
    Vendor string:    NVIDIA Corporation
    Renderer string:  GeForce GTX 550 Ti/PCIe/SSE2
    Version string:   3.0.0
    OpenGL version as determined by Extensionator...
    OpenGL Version 3.0
    Has NPOT support: TRUE
    Has Framebuffer Object Extension support: TRUE
    OpenGL ok
    OpenCL ok, version=1.1 CUDA 4.2.1
    Return code: 3
    C:\Program Files\Adobe\Adobe Photoshop CS6 (64 Bit)>
    OpenCL support !!
    Nowadays, most of new GPUs were support power-saving, but when sniffer_gpu running at GPU power-saving state, the OpenCL computing report maybe "time-out", cause the detector "guess" the GPU does not support OpenCL. This is why many people says "OpenCL" sometimes work, sometimes grey-out.
    I hope this bug can be fixed, or at least people can understand how to "enable OpenCL everytime when you launch photoshop".
    Bye.

    Do check the following link
    http://blogs.oracle.com/soabpm/2010/01/soa_suite_11g_weblogictransact.html

  • How to deal with "Error 1001. The specified service already exists" when install a service using installer package?

    Hi everybody,
    I wrote a "Class Library" project which is a service using Visual Stodio 2008 recently, then tried to use a Visual Studio 2008
    Setup Project to install it.
    Here is what I did for the "Class Library":
    1. Finish the program.cs, Service.cs
    2. Add Installer
    3. Change the serviceInstaller so that "StartType" to be Aotumatic
    4. Change the ServiceProcessInstaller2 so that "Account" to be LocalSystem
    5.
    6. Click in F5 (Start Debugging)
    Here is what I did for the Setup Project:
    1. Add the exe file built from the "Class Library" project to the Application Folder
    2. On the Custom Action Editor, add the exe file from 1 to Install and Commit
    3. Change the property of the project so that "RemovePreviousVersion" to be true
    4. Click on F6(Build Solution)
    Then I tried to run the msi file from the built of the Setup Project. Because I modified the two projects serveral times, I uninstalled the Class Library using "Control Panel->Add or Remove Programs" before I reinstall. Two things I notived:
    1. After unstall, the registry was not cleaned up about the installed program
    2. After several rounds install/uninstall, I got "Error 1001. The specified service already exists"
    My questions are:
    1. How to cleanup the registry when uninstall a program?
    2. How to deal with the "Error 1001. The specified service already exists"?
    3. Did I do anytbing wrong with the "Class Library" or the "Setup Project"?
    Thanks a lot!
    Helen

    Hi Simon, not a problem!
    I spent some more time on this and here are few more notes:
    it is called Major Upgrade, when you are installing new version of the product upon a previous one and
    MSI supports 2 strategies:
    Strategy 1. Install a new version and uninstall previous one. (Install a new version right upon previously installed version (file merging is performed based on dll version number) and the delete previously
    installed files)
    Strategy 2. Uninstall previous version and install a new one (Delete all previous files and install from scratch new files.)
    From the first look it seems that 1st strategy is weird and buggy. But, remember, MSI is great because it's transactional!!! That means that if once some of the phases (Installation, Uninstallation, Rollback, Comit) fails, your machine
    will be reverted to the previous state and it'll be still functional. 
    Let's consider both strategies:
    Consider you have installed product_v1.msi and you want to install product_v2.msi.
    Strategy 1
    1. MSI engine copies files from Product_v1 directory to TEMP directory
    2. MSI engine merges files based on the assembly version (between v1 and v2)
    3. Once merging is completed successfully it removes files in TEMP (RemoveExistingProducts  action triggers it) and you got product_v2 installed, otherwise if it fails MSI engine revert machine to V1 and copies previous files from TEMP.
    Strategy 2
    1. MSI engine tottaly removes all files from v1.
    2. MSI engine installs v2 files and if something goes wrong you cannot revert back, because RemoveExistingProducts  allready worked out and MSI doesn't have files to revert machine back
    I recommend to everybody to use Strategy 1 and leverage MSI transaction functionality. And you can set this strategies by defining sequence of RemoveExistingProducts action. See more info
    here.  So, I think it's not even a bug in VS as I said in the upper post it is default recommened behaviour.
    AND, you got "Error 1001. The specified service already exists"
    because if we follow Strategy 1 MSI engine tries to install Windows Service on top of the existing service and OF COURSE it fails MSI engine (StopServices, DeleteServices actions are executed before actual
    installation and  they look at ServiceControl table). In order to stop service first and delete them you have to fill ServiceContol table of the MSI (and then StopServices, DeleteServices actions will recognize what to they have to stop
    and delete), like this:
    *clip*clip*clip*
    ' see http://msdn.microsoft.com/en-us/library/windows/desktop/aa371634(v=vs.85).aspx for more info
    ' Update the Service Entry to stop and delete service while uninstalling
    query = "INSERT INTO ServiceControl (ServiceControl, Name, Event, Arguments, Wait, Component_) VALUES ('MAD_Service', 'Service name', '160', '', '1', '"
    + componentName + "')"
    Set view = database.OpenView(query)
    : CheckError
    view.Execute : CheckError
    ' Update the Service Entry to stop and delete service while installing
    query = "INSERT INTO ServiceControl (ServiceControl, Name, Event, Arguments, Wait, Component_) VALUES ('MAD2_Service', 'Service name', '10', '', '1', '"
    + componentName + "')"
    Set view = database.OpenView(query)
    : CheckError
    view.Execute : CheckError
    *clip*clip*clip*
    We can uninstall service first by following Strategy 2, but then we lose transactional support.
    So, Simon did I encourage you to change your code a bit?:)
    And, btw, if you don't want to change the strategy, please don't rely on SequenceID in MSI table, it can be change, you have to get the at the runtime.
    Hope it will help to everybody!
    See also more advanced explanation of how MSI works
    here.
    Truly yours, Marat

  • How to deal with the rejected stock if it is rjected by QC

    Dear All,
    please let me know how to deal with the rejected  stock from Quality point of view.i.e., for incoming materails and Finished if returned from customer
    Regards,
    P.Vijaya

    hi
    if material is rejected for incoming material then you can create Notification for incoming material due to  you can return back material with print for that you have to record defects in result recording. in T-code QM02 if result is recorded with defects. or you can create with Qm01.against vendor
    if material is returned from costumer you can create inspection lot for that for that you have to maintained inspection type 06 in material master. you can result record for that you can create notification for that. or rework for this material as per quality check or can scrap
    if have any problem please come back
    regards
    Pravin

  • How to deal with special character in source file

    Hi experts,
                      i am doing a file to file scenario in which my source file contains many special characters when i am puting this file into moni its going with the special character .My source file is a fixed length file so in content conversion i have specified the file length but due to these special charcters these field lenght is also varing.So please guide me how to deal with these special characters in sender adapter
    regards,
    Saurabh

    you could try using a Java Mapping to change the encoding manually. For that, set the encoding of the OutputFormat of the XML you'll serialize. Try the following code piece for the mapping (inside a try/catch declaration):
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder documentBuilder = factory.newDocumentBuilder();
    Document input = documentBuilder.parse(in);
    OutputFormat format = new OutputFormat(XML, "ISO-8859-1", false);
    XMLSerializer serializer = new XMLSerializer(out, format);
    For more details check this guide:
    https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/uuid/502991a2-45d9-2910-d99f-8aba5d79fb42

  • How to deal with the change in address of plant,

    how to deal with the change in address of plant,companycode,sales org etc.?

    Hi,
    Do you want to change the address of Company code, Plant and Sales org?
    Follow the menu path in SPRO.
    SPRO >> Enterprise structure >> Definition >> Financial accounting >> Define Company code >> Edit company code >> Click on address and change.
    .. Definition >> Sales and Distribution >>  Define ...sales org >> select the sales org and click on address and change.
    ... Definition >> Logistics - general >> Plant >>>> Click on address and change.
    Regards,
    K Bharathi

  • How to deal with 0...n or 1...n mappings?

    Hi all,
    I'm relatively new to BPM. I've already made several processes that are working fine. However, I'm now stuck because, for the life of me, I'm not able to understand how to deal with data mappings of nodes of a cardinality greater than 1...1.
    I'm used to dealing with 0...n inputs of Web Services in Webdynpro Java and CAF Application services, using java code... but I just don't get how to deal with these in a BPM data mapping scenario.
    Let's say you have a Web Service whose input is a node called "Employee", where you can add n Employee objects, like this:
       Employee (0...n)
          FirstName: String
          LastName: String
    How do you:
    1- map a 0...n context node from a Web Dynpro or Web Service output, already containing several employees, into this Employee 0...n WS input node?
    2- map a 0...n context node from a Web Dynpro or Web Service output, containing NO employees, into this Employee 0...n WS input node, without getting an error and the BPM crashing because it says the employee element is not found?
    Hopefully someone can help me with this, because I'm about to go the way of calling the web service n times, one employee at a time, instead of one time with a Employee object with n registries in it.
    Thanks!

    Hi Abhijeet,
    i think i should have mentioned this earlier. My Employee node is inside another node.  So, the actual input structure of the WS is this:
    InputValues (1...1)
       Employees (0..n)
          FirstName: String
          LastName: String
    This scenario works OK in BPM when mapping a 0..n node using deep copy as Jocelyn explained, but I still doesn't work if I want to pass an empty (not null) Employees array.
    If I go to the WS Navigator and run this WS with the following parameters, it runs ok (I get an output message saying no employee was selected, which is how it should work):
    InputValues -  "Is null" checkbox not activated.
       Employees - "Skip" checkbox not activated
          FirstName - "Skip" checkbox activated
          LastName - "Skip" checkbox activated
    However, if instead of activating the checkbox of, say, "FirstName", I enter a "" value, I get an error from the WS saying that's not a vaild first name, which is also how it should work.
    In java code, I would just pass an empty InputValues object to the WS, but I'm not sure how to do this in a BPM without it being considered null, and without having to set on of its String-child values to "".
    Do you know how to achieve this?

  • How to deal with this problem while Flex Integration   SSH

    Error creating bean with name '_messageBroker': Instantiation of bean failed; nested exception is java.lang.NoClassDefFoundError: flex/messaging/AbstractFlexSessionProvider……
    Caused by: java.lang.ClassNotFoundException: flex.messaging.AbstractFlexSessionProvider
    I have  exist project used  SSH ,and now need flex to be use in some new unint.
    I hava follow these step to write my code , please help me to pickup the misstake  i had token.
    (flex4.0  spring 3.6 strust2.2 **)
    1. download the Blazeds file  and spring-flex-core-1.5.2.RELEASE.jar
    (org.springframework.integration-1.0.3.RELEASE.jar also include)
    2. unpack the Blazeds copy the flex folder to WEB-INF 
    3.add the lib/*  to my project lib folder
    4.add some declaration in the web.xml
    5.new a flex-application-config.xml 
    ^^^^ and so on.  I don't know how  to deal with this problem!!!
    Waitting for help!

    The information you provided is totally useless for determining the problem.
    If it helps, I think the message you are getting is related to BlazeDS not being able to find the service class you are calling. You either have a typo somewhere, or you didn't set up a secure channel in your service config (I am assuming you meant SSL and not SSH).

  • How to deal with this problem?

    How to deal with this problem?
    We plan to use Oracle Coherence (In Memory Data Grid) for a large-scale application. In order to keep the database table data in Coherence caches, we will create all the corresplonding Java objects (entities) and construct the persistence system using JPA/EclipseLink+JDBC. In this way, any in-memory object update will be persisted to the corresponding database tables.
    The problem is that some existing application codes are updating these database tables directly now. If the direct-database-table update is not permmited in the persistence environment, we have to discard most of the existing application scripts.
    I want to know, in this situation, should I discard most of the existing scripts?
    Are there any other solutions?

    Allowing writes from both cache & DB is possible with its own set of issues.
    The main issue to consider is conflicts from updates on same record via both cache and DB. If your caches are write-through the conflict decreases - but then cache writes become slower. If your caches are write-behind potentially the older cache update will overwrite the latest DB update. Now you are back to Database 101 -- timestamps, versions, etc...
    If you use a DB trigger to initiate the resync request you might want to distinguish whether the update has come from the cache-store (in which case, you may choose to do nothing), or if the update was from the 'existing apps', etc...
    If you choose to inject the resync logic at the application code level - you have the usual sourcecode issues - can you modify the code, is all the DB code localized, what options do you have to link with Coherence functionality (DLL, external proc, webservice, etc), etc... Naturally though, if you have to make substantial changes to signal a resync....you might consider taking the extra step and change the code to write to the cache.

  • Help!!! How to deal with ClassNotFoundException??

    How to deal with ClassNotFoundException without starting Java Runtime Environment??
    the class file:
    import java.applet.Applet;
    import java.awt.Graphics;
    public class Hello extends Applet {
    public Hello() { }
    public void paint(Graphics g) {
    g.drawString("Hello!", 5, 25);
    the html file:
    <APPLET CODE="Hello" WIDTH=300 HEIGHT=200 >
    </APPLET>
    But it throw a error
    Error loading class: Hello
    java.lang.NoClassDefFoundError
    java.lang.ClassNotFoundException: Hello
    at com/ms/vm/loader/URLClassLoader.loadClass (URLClassLoader.java)
    at com/ms/vm/loader/URLClassLoader.loadClass (URLClassLoader.java)
    at com/ms/applet/AppletPanel.securedClassLoad (AppletPanel.java)
    at com/ms/applet/AppletPanel.processSentEvent (AppletPanel.java)
    at com/ms/applet/AppletPanel.processSentEvent (AppletPanel.java)
    at com/ms/applet/AppletPanel.run (AppletPanel.java)
    at java/lang/Thread.run (Thread.java)
    What 's the rule of com.ms.vm.loader.URLClassLoader finding the class??

    If you compiled the applet with SUN jdk then use -source 1.3 -target 1.1 to make it run in
    msjvm (Microsoft Java Virtual Machine). Note that this is a bad idea because MS is
    phasing out the msjvm.
    If you don't want to ue msjvm (good for you) than use the object tag in your html file to tell
    the browser you need to run this applet with sun jre:
    http://java.sun.com/products/plugin/versions.html

  • How to deal with relation

    Hi
    I am trying to import two beans(TestBean and HelperBean)into my Web Dynpro project to create a model. These beans are dealing with a List(ArrayList). This List is considered as a Relation. I am facing problem in handling this relation.
    I am having both the TestBean and HelperBean in the same package. Below is the code of TestBean. This bean is in turn calling HelperBean ,which is returning a List.
    I am getting an error while creating model -
    <b>[Error]: There are one or more relations unresolved. Importing the model without resolvoing the relations might result in erratic output.</b>
    <u><b>Code For TestBean</b></u>
    public class TestBean implements Serializable{
         private List customerList= null;
         HelperBean helper = new HelperBean();
              public void execute(){
              try{
                                            customerList = (ArrayList)helper.getCustomerList();
                   catch(Exception ex){
                        ex.printStackTrace();
          * @return
         public List getCustomerList() {
              return customerList;
          * @param list
         public void setCustomerList(List list) {
              customerList = list;
    I am new to Web Dynpro and don't know how to deal with relation.Please inform if there is some solution.
    regards,
    Sujit

    Sujit,
    Not every bean becomes model class during import. So your HelperBean is irrelevant here. But you miss other bean, namely Customer bean. You must add it as model class during import, then select problematic 0..n relation and resolve it to model class Customer.
    Valery Silaev
    SaM Solutions
    http://www.sam-solutions.net

  • How to deal with images when detecting/resizing screen?

    Hi there,
    I am trying to learn how to detect screen resolution and
    resize a flash movie to those dimensions. The one thing I'm
    wondering first is, how to deal with images in the movie.
    Do I need a variety of different movie sizes that I serve up
    depending on the resolution, or is there some way of linking to
    higher rez image that can be scaled down to fit the screen?
    Thanks!

    as far as I know this has always been a bit of an issue when
    using
    images inside a scaled movie. If you display a high res image
    inside a
    scaled down movie, flash can't "reoptimize" it so the image
    looks
    jagged. Of course the other way around is even worse..
    Serving images based on the screen res could be possible if
    you detect
    it using javascript but could be a night mare to maintain and
    test it...
    I guess the questions I would ask myselkf are:
    1. what is my audience? What resolution the majority of them
    will have?
    2. Is there anyway I can keep the image size fixed, and scale
    to fit he
    rest of the design?
    3. How much time do I have to implement the customized
    version?
    It really depends on your project..but to answer to your
    quuestion yes
    you can detect.
    http://www.pageresource.com/jscript/jscreen.htm
    and your flash will have to interpret and load images from
    different
    directories based on the var passed

  • How to deal with the rule that do not use "object" class to declear a class

    I run my flex project in sonar. And there is a rule "Do not use Object class ".
    I just want to know how to deal with this problem.
    I mean, when I try to write a base class, I don't know which kind of class will be transfered in by reference, which type I can declear instead of "object"?

    Check out this example:
    The moment I put in the code >> box1.addItem("hello"); << and run the application, the BusNameListener is fired. Hope this makes sense.
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.ActionListener;
    import java.awt.event.ActionEvent;
    public class JFrameExample {
    private JComboBox box1;
    public JFrameExample() {
    box1 = new JComboBox();
    box1 .setMinimumSize(new Dimension(300, 24));
    box1 .setPreferredSize(new Dimension(300, 24));
    box1.addActionListener(new BusNameListener());
    box1.addItem("hello");
    JFrame f = new JFrame("This is a test");
    f.setSize(400, 150);
    Container content = f.getContentPane();
    // content.setBackground(Color.white);
    content.setLayout(new FlowLayout());
    content.add(box1);
    f.setVisible(true);
    class BusNameListener implements ActionListener {
    public void actionPerformed(ActionEvent e) {
    JComboBox cb = (JComboBox) e.getSource();
    String item = (String) cb.getSelectedItem();
    if (item != null) {
    JOptionPane.showInputDialog(null,
    "Specify...", "File Import",
    JOptionPane.OK_CANCEL_OPTION);
    }

Maybe you are looking for