• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Bad Code/Design Practices

 
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I hate the code I am reviewing. Why? because it is bad. For example, using XXXClient to represent a server. Let's list what you hate to see and make us and others easier to follow.
Here is my list:
1). Do not use client to represent server.
2). Do not use interface to include constants.
3). Do not repeat code segment in the block.
4). Do not use too many switches in the block.
...
 
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Loajar, interesting set of pet peeves. As you may notice from another post, I am going through Martin Fowler's Refactoring book. It talks about a couple of these as 'bad smells' in code that needs to be reworked. He lists quite a few of these type of scenarios--in particular, he also talks about code duplication, too many switches/case statements, etc.
One question I want to ask you though is why not use interfaces for constants? I actually like doing that and find it quite convenient, and so it would be great to hear why you find it iritating or a 'smell' of a bad coding practice.
Thanks,
OP
 
mister krabs
Posts: 13974
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I agree with octavyn. Could you also explain exactly what you mean by #1?
 
Author
Posts: 6055
8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How To Write Unmaintainable Code at http://mindprod.com/unmain.html
This is a great list of bad programming practices. I give copies to all my new programmers. Unfortunately, in the alst year or so, the list has grown huge and suffered from "feature creep." Still it's a good resource.
--Mark
hershey@vaultus.com
------------------
 
Mark Herschberg
Author
Posts: 6055
8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by octavyn pittman:
One question I want to ask you though is why not use interfaces for constants? I actually like doing that and find it quite convenient, and so it would be great to hear why you find it iritating or a 'smell' of a bad coding practice.


Ths is a fairly common complaint I hear from people. Often you'll find C/C++ programmers who gripe about no global variables. Then they discover that the interface can effectively provide them with global variables, just have everyone implement the foo.bar.Constant interface, which has no methods, just variables (coulnd't be easier to use!).
What happens is the interface gets abused and overused. It becomes easiest just to throw a variable into the interface rather than have to pass it around, or worry about field access. The end result? Monolithic, proceedural like code. Instead of data hiding, everyone starts to learn everything about everyone else, and the code turns into spagetti. OO purists will argue that global variables should not be supported in a language.
There may be other reaons, too, but this is what I often hear cited.

--Mark
hershey@vaultus.com
 
High Plains Drifter
Posts: 7289
Netbeans IDE VI Editor
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Class names in all lower case. Drives me nuts.
------------------
Michael Ernest, co-author of: The Complete Java 2 Certification Study Guide
 
Ranch Hand
Posts: 1157
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Laojar,


1). Do not use client to represent server.


I am not sure what you meant by this.I had designed a ChatServer and ChatClient application using RMI.I had put some methods in the client,which the server calls to post the message to it.So for the server, the client acts like a server.Is this a bad programming practice?
This is how I came up with the design.

  • Asked myself what the server should do?It should provide/expose methods to post message from the client, so that the client can call these methods.Here server acts like a server !!
  • Asked myself what the client should do?It should provide/expose methods for the server, so that the server may call this method to post the message to the respective client Thread.In this case, the client acts like a server !!!

  • Is my logic very bad??
    Thanks in advance.
    Regards,
    Sandeep Desai
    vgdesai@bom3.vsnl.net.in

    1. Sun Certified Programmer for Java 2 Platform Scored 93 per cent
    2. Oracle JDeveloper Rel. 3.0 - Develop Database Applications with Java Scored 56 out of 59
    3. IBM Enterprise Connectivity with J2EE Scored 72 per cent
    4. Enterprise Development on the Oracle Internet Platform Scored 44 out of 56

    5. [This message has been edited by Desai Sandeep (edited May 05, 2001).]
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic