Live data from Hacker News

One of the Best Bits of Programming Advice I ever Got

objology.blogspot.com

21–30 of 94 posts

Re: One of the Best Bits of Programming Advice I ever Got

#21
post #5

Even better: don't use objects at all. Use a functional programming language.

Object oriented programming is the sweet spot solution to many problems. For example, if you have a UI with several text fields, it's natural to think of them as objects that have methods like setText(), setEnabled() and such. These methods often have side effects and that's their whole point. Of course functional programming also has use cases for which it is the sweet spot solution, e.g. writing compilers.

These methods often have side effects and that's their whole point.

You don't need state and mutations, GUIs can also be programmed nicely using functional reactive programming (FRP). A nice description of FRP:

http://stackoverflow.com/questions/1028250/what-is-functiona...

Some examples of FRP in GUIs:

http://www.haskell.org/haskellwiki/Reactive-banana/Examples

Re: One of the Best Bits of Programming Advice I ever Got

#22
post #19

I disagree with this advice and the reason I disagree with it because it completely disregards the human tendency to name objects (not OOP objects, but real-life objects) based on their functionality. Guess what a photocopier does? Or a scanner? An eraser? An elevator? I don't think these are particularly bad names; quite the contrary, their meaning is very clear. Why would it be any different for OOP objects? If the…

He does say, at the end of the piece, that nouns that happen to end in -er are an exception.

Aren't all words which end in -er, and used as class names, nouns ?

Re: One of the Best Bits of Programming Advice I ever Got

#24
post #3

Google has posted warning signs to look out for in code (1). One of them is very similar: Suspicious names: context, environment, principal, container, or manager (all of the things google mentions, are things I've seen much, much more in Java codebase than anywhere else) (1) http://googletesting.blogspot.com/2008/11/guide-to-writing-t...

166 violations, of the 4025 classes/interfaces in java 7:

That's 4% of Sun's own JDK, not counting user defined classes. In my 15 years of Java pgmming, I've seen enterprise programmers almost always start out their OO design with a class named "xyzmanager"...probably reflecting their subliminal desire to become a manager someday :)

------ AbstractDocument.AttributeContext AbstractRegionPainter.PaintContext AbstractRegionPainter.PaintContext.CacheMode AccessControlContext AccessibleContext AppletContext BAD_CONTEXT BeanContext BeanContextChild BeanContextChildComponentProxy BeanContextChildSupport BeanContextContainerProxy BeanContextEvent BeanContextMembershipEvent BeanContextMembershipListener BeanContextProxy BeanContextServiceAvailableEvent BeanContextServiceProvider BeanContextServiceProviderBeanInfo BeanContextServiceRevokedEvent BeanContextServiceRevokedListener BeanContextServices BeanContextServicesListener BeanContextServicesSupport BeanContextServicesSupport.BCSSServiceProvider BeanContextSupport BeanContextSupport.BCSIterator CompositeContext Context Context ContextList ContextNotEmptyException ContextualRenderedImageFactory DirContext DOMCryptoContext DOMSignContext DOMValidateContext DragSourceContext DropTargetContext EndpointContext EventContext EventDirContext FontRenderContext GSSContext HttpContext InitialContext InitialContextFactory InitialContextFactoryBuilder InitialDirContext InitialLdapContext InputContext InputMethodContext JAXBContext LdapContext LogicalMessageContext LoginContext MathContext MessageContext MessageContext.Scope NamespaceContext NamingContext NamingContextExt NamingContextExtHelper NamingContextExtHolder NamingContextExtOperations NamingContextExtPOA NamingContextHelper NamingContextHolder NamingContextOperations NamingContextPOA NoContext NoContextHelper NoInitialContextException NotContextException PaintContext RenderContext ScriptContext ServiceContext ServiceContextHelper ServiceContextHolder ServiceContextListHelper ServiceContextListHolder SimpleScriptContext SOAPMessageContext SSLContext SSLContextSpi SSLSessionContext StyleContext SynthContext WebServiceContext XMLCryptoContext XMLSignContext XMLValidateContext _NamingContextExtStub _NamingContextImplBase _NamingContextStub ActivationGroupDesc.CommandEnvironment Environment GraphicsEnvironment GroupPrincipal JMXPrincipal KerberosPrincipal Principal Principal PrincipalHolder ProcessingEnvironment RoundEnvironment UserPrincipal UserPrincipalLookupService UserPrincipalNotFoundException X500Principal AdapterManagerIdHelper BeanContextContainerProxy CertPathTrustManagerParameters Container ContainerAdapter ContainerEvent ContainerListener ContainerOrderFocusTraversalPolicy CookieManager DefaultDesktopManager DefaultFocusManager DefaultKeyboardFocusManager DesktopManager DirectoryManager DomainManager DomainManagerOperations DriverManager ErrorManager FocusManager ForwardingJavaFileManager GSSManager JavaFileManager JavaFileManager.Location JComboBox.KeySelectionManager KeyboardFocusManager KeyManager KeyManagerFactory KeyManagerFactorySpi LayoutManager LayoutManager2 LogManager ManageReferralControl ManagerFactoryParameters MemoryManagerMXBean MenuContainer MenuSelectionManager NamingManager POAManager POAManagerOperations PropertyEditorManager RepaintManager RMISecurityManager RootPaneContainer ScriptEngineManager SecurityManager ServantManager ServantManagerOperations StandardJavaFileManager ToolTipManager TrustManager TrustManagerFactory TrustManagerFactorySpi UIManager UIManager.LookAndFeelInfo UndoManager ---------

Re: One of the Best Bits of Programming Advice I ever Got

#25

Amazing how small linguistic changes can cause large semantic shifts. Comparable to the post's rule: in English, a few rules I've picked up are - avoid words ending in "ly" (suffix weakens concepts; suggestion from Stephen King) - never start a sentence with "I" and otherwise minimize its use - "but" negates everything that came before - avoid "to be" Any other such suggestions, in natural or artificial languages?

- read Strunk & White.

Re: One of the Best Bits of Programming Advice I ever Got

#29

Amazing how small linguistic changes can cause large semantic shifts. Comparable to the post's rule: in English, a few rules I've picked up are - avoid words ending in "ly" (suffix weakens concepts; suggestion from Stephen King) - never start a sentence with "I" and otherwise minimize its use - "but" negates everything that came before - avoid "to be" Any other such suggestions, in natural or artificial languages?

Good code isn't written, it's re-written.

Omit needless code. Omit needless code. Omit needless code.

Re: One of the Best Bits of Programming Advice I ever Got

#30
post #14

I disagree with this advice and the reason I disagree with it because it completely disregards the human tendency to name objects (not OOP objects, but real-life objects) based on their functionality. Guess what a photocopier does? Or a scanner? An eraser? An elevator? I don't think these are particularly bad names; quite the contrary, their meaning is very clear. Why would it be any different for OOP objects? If the…

I was going to write basically the same thing. I used to combine data and action in the same classes but recently have begun refactoring them out into separate data and "-er" classes. Maybe somewhere an OOP purist is frowning, but I really prefer this naming convention. My FlowchartShape class included methods for formatting and positioning. I now have a FlowchartShapeFormatter class and a FlowchartShapePositioner cl…

Agreed. The reason I end up with some '-er' classes is to separate out immutable definitions and the classes that work on the definitions. In your example, by making the FlowchartShape a simple definition class, you can then write that to a file or send it over the network as a snapshot of the state of the -er classes.

If the article's advice was taken, you'd end up renaming WebServer to be WebPage, but then would have nothing to name a WebPage. (Maybe WebPageSnapshot?)

Post reply on HN