473,698 Members | 2,158 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Best Coding Practice

First, let me say that this question is a rather general programming
question, but the context is PHP, so I figured this group would have
the most relevant insight.

Anyways, this is also more of an opinion based question than one
seeking a definite answer. Recently, while maintaining a rather large
system. I needed to add an array class member to an object. It was
exactly the same as another class member, except that one array stored
regular products, and the other stored free promotional products. As
such, I needed a way to add products to the new, free array. Since all
the logic was the same between the two arrays aside from the price, I
had a few different options to do this. I'm interested in polling
which way some of the group members feel would have been the best.
Naturally these are abbreviated versions of what I envisioned as
possible solutions.
#1.
public function addArrayA($obje ct){
//logic
$a[] = $object;
}

public function addArrayB($obje ct){
//same logic
$b[] = $object;
}
#2. (These next two are arranged as such, because the class using
these functions is included in many script files,
all of which I may not be aware of, so there would have to be some
default value for the array that was always used
before this new array was needed)
public function addArray($objec t, $free = NULL){
//logic
if(!$free){
$a[] = $object;
}else{
$b[] = $object;
}
}

or

#3
public function addArray($objec t, $arr = "a"){
//logic
$$arr[] = $object;
}

I ended up going with option number 1, because I felt that despite the
inefficient, redundant code it would later be more readable to other
programmers that might work on the project. Additionally, I didn't
feel wholly comfortable with default variables being the only
difference between a full price product and a free product. Thoughts?

Aug 24 '07
52 3370

"Jerry Stuckle" <js*******@attg lobal.netwrote in message
news:WN******** *************** *******@comcast .com...
| Steve wrote:
| "Jerry Stuckle" <js*******@attg lobal.netwrote in message
| news:W5******** *************** *******@comcast .com...
| | Steve wrote:
| | "Michael Fesser" <ne*****@gmx.de wrote in message
| | news:cn******** *************** *********@4ax.c om...
| | | .oO(Jerry Stuckle)
| | |
| | | >But if you change the function name, parameter list and/or return
| value,
| | | >you have to change all of the code calling it. This is NOT
| refactoring.
| | |
| | | http://en.wikipedia.org/wiki/Rename_Method
| | |
| | | http://www.refactoring.com/catalog/renameMethod.html
| | >
| | apparently, i'm not up on my lingo.
| | >
| | so what if i change an interface with optional parameters? i then
don't
| need
| | to change *any* calling code, yet i've changed the interface. is
this
| now
| | refactoring? further, most php is not written in OOP but with
| proceedural
| | code. so, the 'interface' would be a browser, in most cases.
| technically, i
| | could change any and all code yet not be mucking with the
'interface'.
| and
| | so that we're all clear...an 'interface' *only* exists as a
| communication
| | point between a caller and an *OBJECT*. functions alone and of
| themselves
| | are NOT interfaces.
| | >
| |
| | OK, I should have clarified - you can't change the interface except to
| | *extend* it. Adding optional parameters would be extending the
interface.
| |
| | In this case, the "interface" wouldn't be the browser - the browser
has
| | nothing to do with PHP. Rather, it would be the common function
calls.
| | Interfaces existed long before OO programming! For instance, fopen()
| | is an interface to the file system.
| >
| well, the op was regarding best programming practices in gereral. either
| way, the user interface is very much a part of any language whether it
is a
| command-line or gui. in general, especially in case of the command-line,
it
| is equally effected by such changes (think of argument changes or
command
| name changes). i understand the difference between what we're talking
about
| and this idea, but the two don't always have a black/white distinction.
the
| main point i was trying to make is that functions are not interfaces,
and if
| they are - such as fopen being an 'interface' to the file system - then
so
| too are the methods a user interacts with in an application - their
(caller)
| way into accessing a set of features ('interfaces'). such an equation
| doesn't help in distinguishing development tasks.
| >
|
| Actually, functions have always been defined as interfaces. Even before
| OO programming came along, it was common to build a library of functions
| to perform a set of actions - similar to the file calls in PHP and C.

all fine lines i suppose. i'm thinking of dll's here. i've always thought of
libraries as precursors to oop encapsulation.. .hence, really object-like.
but i do see your point.

| And yes, the methods a user interacts with an application is an
| interface - widely known as the "user interface".

thus my allusion of 'gui'. ;^) but i digress...

| | as far as i'm concerned, when i 'refactor', i'm doing whatever needs
to
| be
| | done to existing code to make it better for no other reason (new
| | enhancement, new logical/business requirement, etc.) than to make it
| better
| | (easier to maintain, bring it under standards of practice, make it
| faster,
| | etc.). imo, it's not worth splitting hairs over. i suppose it is a
good
| | thing that when my boss and i talk about 'refactoring' some code, we
| | understand each other...which is the whole point of a word.
| | >
| |
| | Then how do you differ between "refactorin g" and "rewriting" ? There
is
| | a difference!
| >
| besides symantics, what is the superior definition and use of
'refactoring'.
| anytime you 'refactor' code, you 'rewrite' it. i'm fine, as an employer,
| when a developer says, 'i redid/willdo this to do/behave/help with
this...it
| impacted (will impact) this/these things.' THAT is more meaningful than
| EITHER term. moreover, i just don't thing 'redid' and 'willdo' would
have
| sounded very 'extreme' and hence was not included in the book(s). ;^)
| >
|
| Yes and no. Refactoring typically is more limited - for instance,
| recoding a function, set of functions, class, etc., without having to
| change code which calls those functions or class members.

right. when i do use 'refactoring' in conversation, my boss knows i mean
that i'm not adding an enhancement and am usually just bringing shitty
coding practices into our standard...refo rmatting, consolidating code where
it is obvious some yahoo got the first bit working and then pasted it
elsewhere and maybe just changed on thing about it. hell, i did that this
week...some dumbass had 1,000 lines of billing validation for a 'current'
table, pasted that code right below and only changed the 'current' to
'history'. and the 1,000 lines where shit to begin with. i bettered the
query and got it to 200-ish. sorry, had to vent.

| when discussing changes that need to be made in code with a client, i
don't
| use either term. i talk about things he understands like speed,
flexibility,
| longevity, scale, and costs (both long and short-term). when discussing
| changes with my boss, i talk about strategy and architecture. and with
my
| employees, i talk about what i need done specific to all of the
above...and
| if in the course of their changes, they see a pattern, potential
problem, or
| oportunity that should be addressed, we get down to *specifics*...n ot
lingo.
| >
|
| I do the same. I don't even talk about "rewriting" the code. I don't
| even talk about architecture, and the only strategy is that which has to
| be in place to get the job done. Rather, I talk about the benefits he
| will receive from whatever I'm going to do.

which is all they want to hear anyway. that, and that you'll have the new
features in place yesterday.

| but that's just me. everything is a rewrite...or an origination. what
| benefit is it to anyone to split hairs over a term that is itself,
already
| controvertial and unclear?
| >
|
| It's fun? :-) But you're right, it's not really worth splitting hairs
over.

lol.

| don't get me wrong, jerry. i think saunders kaufman has his head
squarely up
| his ass, which explains why he's 'in the dark' on this topic. however,
i've
| done all the 'extreme' stuff including paired programming, bidding,
etc.. as
| i've said, it comes from common practices in other fields all the way
back
| to the early 1900's. ain't nothn' 'extreme' about it as far as
programming
| is concerned. as for the lingo associated with it, may it forever be
limited
| to the context of the book that espoused it. for me, i use specifics
when i
| need someone else to understand what i'm doing or what they need to do.
| 'refactoring' is not specific enough.
| >
|
| I think Sanders is just being honest when he says he's in the dark about
| it. I think most programmers are.

well, it's painfully obvious he doesn't. however, those other 'most'
programmers don't put down anything they know they don't know
about...especia lly with the fervor that he does.

keep 'em truck'n.
Aug 29 '07 #31
Jerry Stuckle wrote:
Yes and no. Refactoring typically is more limited - for instance,
recoding a function, set of functions, class, etc., without having to
change code which calls those functions or class members.
I've been having a LOT of fun with that word ever since that discussion
we had about it.

The other day I was talking to a fellow who wanted to know how I was
doing with this framework. He liked what I've said about it so far, and
may very well pony up a few KiloBucks for me to mash his website into my
framework.

He asked me to tell him about whatever I was currently doing with it and
I said that I had to "refactor" it to make sure that I could later add
other DBMS's to it and the user not have to change their code. (That's
the correct use of "refactor", right?)

Man! The look he gave me!

I saw he was nervous, so I laughed and said, "no what I mean is..." and
then explained what I was doing in better detail.

It turns out that "refactor" is a scary word for him - one that's caused
him serious coin in the past. He said it's like when politicians say
they're leaving office "to spend time with my family"

He's not a technie; he's a businessman. So while he may not understand
the nitty-gritty of programming - he know's when he's being bull-shitted.

I do the same. I don't even talk about "rewriting" the code. I don't
even talk about architecture, and the only strategy is that which has to
be in place to get the job done. Rather, I talk about the benefits he
will receive from whatever I'm going to do.
Amen.

And I also agree there is no "extreme programming". There are "extreme
sports", which can only be done by someone in excellent physical
condition, lots of practice and a willingness to die.
I think of these buzz-word processes as Legacy business logic. A
pattern that may have worked will in the 20th century, when IT was new,
but not so much in the present day.

Now that computers, for most people, are not scary, impossibly complex,
proprietary things - folks are more comfortable hearing the real talk -
instead of the talk about the talk.

Aug 29 '07 #32
Steve wrote:
i agree that to me, it's mostly lingo. HOWEVER UNLIKE YOU, i know BOTH
sides - what refactoring is, how it is used, have experienced the entire
'extreme programming' gammut. i have an INFORMED opinion while you not only
have your head up your ass, you seem quite comfortable in leaving it there
and speaking from it.
Man, I wish I could get my twit-filter working.
Aug 29 '07 #33
Steve wrote:
"Jerry Stuckle" <js*******@attg lobal.netwrote in message
| I think Sanders is just being honest when he says he's in the dark about
| it. I think most programmers are.

well, it's painfully obvious he doesn't. however, those other 'most'
programmers don't put down anything they know
Really?!
In my experience, and I speak FOR myself as well, most engineering types
are HIGHLY critical of things they don't understand.

It's a side-effect of keeping yourself informed. If you're a smart
engineer, and you've kept your skills sharp, and then some businessman
comes along and tells you that "waterfall" or "extreme" or "agile" is
THE best way for you to work - you'd be a fool not to be critical.

Especially if, like so many of us here, you're an individual contributor.
Aug 29 '07 #34
On Aug 29, 2:41 pm, Sanders Kaufman <bu...@kaufman. netwrote:
Steve wrote:
"Jerry Stuckle" <jstuck...@attg lobal.netwrote in message
| I think Sanders is just being honest when he says he's in the dark about
| it. I think most programmers are.
well, it's painfully obvious he doesn't. however, those other 'most'
programmers don't put down anything they know

Really?!
In my experience, and I speak FOR myself as well, most engineering types
are HIGHLY critical of things they don't understand.

It's a side-effect of keeping yourself informed. If you're a smart
engineer, and you've kept your skills sharp, and then some businessman
comes along and tells you that "waterfall" or "extreme" or "agile" is
THE best way for you to work - you'd be a fool not to be critical.

Especially if, like so many of us here, you're an individual contributor.
Man, I go away for a couple days and 50+ posts, about 20 different
kinds of insults targeted at an individual engineering capabilities,
and still having fun!

Aug 29 '07 #35
ELINTPimp wrote:
On Aug 29, 2:41 pm, Sanders Kaufman <bu...@kaufman. netwrote:
>Especially if, like so many of us here, you're an individual contributor.

Man, I go away for a couple days and 50+ posts, about 20 different
kinds of insults targeted at an individual engineering capabilities,
and still having fun!
That's sorta my fault. I'm a real mensch on the political newsgroups
and at least one of my trolls followed me here.

Sorry.
Aug 29 '07 #36

"Sanders Kaufman" <bu***@kaufman. netwrote in message
news:uY******** *********@newss vr13.news.prodi gy.net...
| Steve wrote:
|
| i agree that to me, it's mostly lingo. HOWEVER UNLIKE YOU, i know BOTH
| sides - what refactoring is, how it is used, have experienced the entire
| 'extreme programming' gammut. i have an INFORMED opinion while you not
only
| have your head up your ass, you seem quite comfortable in leaving it
there
| and speaking from it.
|
| Man, I wish I could get my twit-filter working.

why? then you'd think none of your posts were making it to the server!
Aug 29 '07 #37

"Sanders Kaufman" <bu***@kaufman. netwrote in message
news:f5******** *******@nlpi068 .nbdc.sbc.com.. .
| Steve wrote:
| "Jerry Stuckle" <js*******@attg lobal.netwrote in message
|
| | I think Sanders is just being honest when he says he's in the dark
about
| | it. I think most programmers are.
| >
| well, it's painfully obvious he doesn't. however, those other 'most'
| programmers don't put down anything they know
|
| Really?!
| In my experience, and I speak FOR myself as well, most engineering types
| are HIGHLY critical of things they don't understand.
|
| It's a side-effect of keeping yourself informed. If you're a smart
| engineer, and you've kept your skills sharp, and then some businessman
| comes along and tells you that "waterfall" or "extreme" or "agile" is
| THE best way for you to work - you'd be a fool not to be critical.
|
| Especially if, like so many of us here, you're an individual contributor.

you'd only be a fool NOT TO LEARN WHAT HE WAS TALKING ABOUT...which is why
you should watch leving the word 'fool'...since you hear 'refactoring',
don't look into it, and then talk outta your ass like you understood it
(which makes you even moreso).
Aug 29 '07 #38

"Sanders Kaufman" <bu***@kaufman. netwrote in message
news:6g******** *******@nlpi068 .nbdc.sbc.com.. .
| ELINTPimp wrote:
| On Aug 29, 2:41 pm, Sanders Kaufman <bu...@kaufman. netwrote:
|
| >Especially if, like so many of us here, you're an individual
contributor.
| >
| Man, I go away for a couple days and 50+ posts, about 20 different
| kinds of insults targeted at an individual engineering capabilities,
| and still having fun!
|
| That's sorta my fault. I'm a real mensch on the political newsgroups
| and at least one of my trolls followed me here.

or perhaps the truth lies in simply stating you are a real mensch and that
wherever you go, people realise this and react to it. unless you're of the
'i'm ok, everyone else is not' type of mentality. jury still out.
Aug 29 '07 #39
| The other day I was talking to a fellow who wanted to know how I was
| doing with this framework. He liked what I've said about it so far, and
| may very well pony up a few KiloBucks for me to mash his website into my
| framework.
|
| He asked me to tell him about whatever I was currently doing with it and
| I said that I had to "refactor" it to make sure that I could later add
| other DBMS's to it and the user not have to change their code. (That's
| the correct use of "refactor", right?)
|
| Man! The look he gave me!

and you were a dumbass to use private lingo to a public audience! 'refactor'
in programming is of no use to someone outside of programming. it could also
be lingo in another context. the fact that you don't know what appropriate
language to speak to whom and when is frightening!

| He's not a technie; he's a businessman. So while he may not understand
| the nitty-gritty of programming - he know's when he's being bull-shitted.

apparently not. he's considering your framework, right. ;^)

| I think of these buzz-word processes as Legacy business logic. A
| pattern that may have worked will in the 20th century, when IT was new,
| but not so much in the present day.

only, with the discussion at hand, refactoring and the greater context it
was birthed in are very sound programming methods to employ to ensure
quality. if you knew what you were talking about, you'd know the practice is
more than just words you don't understand. sad, it involves processes yet
known to you!

| Now that computers, for most people, are not scary, impossibly complex,
| proprietary things - folks are more comfortable hearing the real talk -
| instead of the talk about the talk.

so why the hell would you think lingo is profitably entangled with standard
english...such that you don't know to filter based on audience? that's just
dumb. i already think that about you, why are you giving me more cause?!
Aug 29 '07 #40

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
9252
by: DrUg13 | last post by:
In java, this seems so easy. You need a new object Object test = new Object() gives me exactly what I want. could someone please help me understand the different ways to do the same thing in C++. I find my self sometimes, trying Object app = Object(); Object *app = Object(); Object app = new Object();
2
3933
by: Dave | last post by:
Does anyone know much about this tool? Also, if anyone can point me to a TSQL coding standard, please let me know. -- Dave
136
9379
by: Matt Kruse | last post by:
http://www.JavascriptToolbox.com/bestpractices/ I started writing this up as a guide for some people who were looking for general tips on how to do things the 'right way' with Javascript. Their code was littered with document.all and eval, for example, and I wanted to create a practical list of best practices that they could easily put to use. The above URL is version 1.0 (draft) that resulted. IMO, it is not a replacement for the FAQ,...
5
3998
by: Ant | last post by:
hi, I'm now using C#. Seeing as though you can declare & initialize or pass a value to a variable on the same line as the declaration, is it still best practice to group all the variables together at the top of the method, or is it now acceptable for them to be declared at the point where they are initially needed, seeing as though you can 'go to the definition', with the right click of a mouse? Pedantic I know, but I'm curious. thanks...
10
2988
by: Ren | last post by:
Hi All, I'm still rather new at vb.net and would like to know the proper way to access private varibables in a class. Do I access the variable directly or do I use the public property? public class MyClass private _variableName as integer public property VariableName as integer
13
3107
by: Alan Silver | last post by:
Hello, MSDN (amongst other places) is full of helpful advice on ways to do data access, but they all seem geared to wards enterprise applications. Maybe I'm in a minority, but I don't have those sorts of clients. Mine are all small businesses whose sites will never reach those sorts of scales. I deal with businesses whose sites get maybe a few hundred visitors per day (some not even that much) and get no more than ten orders per day....
4
8359
by: Number 11950 - GPEMC! Replace number with 11950 | last post by:
Just looking for the best way to set an image to fill a <divcontainer as a background without upsetting HTML/CSS validation... Thanks in Advance... -- Timothy Casey GPEMC! >11950 is the number@fieldcraft.biz 2email Terms & conditions apply. See www.fieldcraft.biz/GPEMC Discover valid interoperable web menus, IE security, TSR Control, & the most advanced speed reading application @ www.fieldcraft.biz
16
2805
by: Rex | last post by:
Hi All - I have a question that I think MIGHT be of interest to a number of us developers. I am somewhat new to VIsual Studio 2005 but not new to VB. I am looking for ideas about quick and efficient navigating within Visual Studio 2005. Let's say your project (or solution) has dozens of forms and hundreds or even thousands of routines. Two Questions: 1) BUILT-IN to Visual Studio 2005. What ideas do you have to quickly
0
8683
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9031
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8901
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8871
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7739
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6528
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5862
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4371
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3052
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.