Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Deal with badly written code

Name: Anonymous 2010-03-28 15:38

Since I want to be a good programmer, I developed a precise coding style, and I do my best to write elegant code, however from time to time I find myself messing with poorly written code. This reduces my enthusiasm, and I feel the instinct of fixing it ...but in real life you don't have the time for fixing someone else's code, and you have to put a patch on it.

On the long term this leads to a world-wide growing code base which sucks and keeps sucking... and this drives me mad! How do you handle this problem?

tl;dr: We have a lot of shit to work with. How can you survive?

Name: Anonymous 2010-03-28 15:52

By not worrying about how the code looks until you decide to reinvent the wheel.

Name: Anonymous 2010-03-28 15:53

By fixing it.

Name: Anonymous 2010-03-28 16:00

>>1
By abstracting it. Call into your abstraction, which looks nice on the outside despite housing that garbage that the coop student wrote.

Name: Anonymous 2010-03-28 16:12

>>4
Good point: typically this happens in an academic environment, where they put retard students (or "researchers") who just know Java at doing Real Man's work.

Also I'm not totally happy with putting the garbage under the hood: sooner or later the badly written code shows up (say because of a bug or because of some awful memory leak.

Name: Anonymous 2010-03-28 16:40

OP is a troll, there is no such thing as cookie-cutter "precise coding style". If there was it would be taught in univeristies and everyone would graduate at a Donald Knuth level of understanding algorithms.

OP- just for grins, why dont you show us some "poorly written code" and then show us how you would convert it to your "precise coding style".

Name: Anonymous 2010-03-28 16:45

>>6
Most of academic code is written without indentation and presented in a proportional font. Do you seriously have no problems with that?

Name: Anonymous 2010-03-28 16:55

>>7
Where do you get your info from? Evidence or GTFO.

Name: Anonymous 2010-03-28 17:31

>>8

program decay

* by Hannah Newfield-Plunkett, June 2004
* A program to compute the beta decay energy spectra of various isotopes.
* Properties of the isotopes are input through a data file. A Gaussian smear is
* conducted on the energy spectra. Subroutines written by me are included,
* but the subroutines birks and dedxls are not.

real cs,p(500)
real rmin,rmax,norm,rate
character name*6, title*20, filename*20, hisfile*20
real rkb
common /cbirks/rkb
common /g_smear/res
real malpha
parameter (malpha=3727.379)

* Plots from this program were made using HBOOK commands in PAW. This is
* reflected in the syntax.
integer maxblk
parameter (maxblk = 1024*512)
common /pawc/h(maxblk)
call hlimit(maxblk)

read(*,*) res
read(*,*) bw
read(*,*) rmin
read(*,*) rmax
read(*,*) rkb
read(*,*) filename

nbins=int((rmax-rmin)/bw)
nbins2=int((5.-3.)/bw)
nbins3=int((5.-3.5)/bw)
indx = index(filename,' ')-1
write(hisfile,4) filename(:indx)
4 format(A,'.his')
call hropen(17,'decay',hisfile,'n',1024,istat)
open(unit=7,file=filename,status='old')
k=0
read (7,*) rate
read (7,*) norm
call hbook1(5000,'Total E spectrum',nbins,rmin,rmax,0.)
call hbook1(6000,'Total E spectrum',nbins,rmin,rmax,0.)
call hbook1(7000,'Total E spectrum',nbins2,3.,5.,0.)
call hbook1(8000,'Total E spectrum',nbins3,3.5,5.,0.)
read(7,*) B

10 if(B.ne.0) then
k=k+1
read(7,*) name,z,a
write(title,3) name
3 format('E spectrum ',A6)
read(7,*) cs
call hbook1(k,title,nbins,rmin,rmax,0.)
call hbook1(100*k,title,nbins,rmin,rmax,0.)

* number of modes of decay

read(7,*) n
do i=1,n

* information about each decay mode

read(7,*) Q,Qex,bf1,Eann,Eec,bf2,Qexalpha,bfalpha
if(Eann.eq.1.022) then
zz=-abs(z)
else
zz=abs(z)
endif
Eex=Q-Qexalpha-Qex

* quenching of alphas

vealpha=birks(malpha,2.,Qexalpha)*Qexalpha
offset1=(10.*(Eex+Eann)-int(10.*(Eex+Eann)))/10.
offset2=bw/2.-offset1
if(offset2.lt.0.) offset2=offset2+bw
if(bf1.ne.0.) then
bnorm=betaint(Qex-Eann,zz,a)
endif
do Te=offset2,Q,bw
if(bf1.ne.0.) then

* beta spectrum calculated from energy

bp=beta(Te-Eex-Eann,Qex-Eann,bw,bnorm,zz,a)
else
bp=0.
endif
if(Eec.ge.0..and.Te.ge.Eec-bw/2..and.Te.le.Eec+bw/2.)then

* electron capture branching fraction

x=bf2
else if(bfalpha.ne.0..and.Te.ge.vealpha+Eex-bw/2..and.
+     Te.le.vealpha+Eex+bw/2.) then

* alpha branching fraction

x=bfalpha
else
x=0.
endif
call hfill(k,Te,0.,cs*bf1*bp/norm*rate)
call hfill(5000,Te,0.,cs*bf1*bp/norm*rate)
call hfill(k,Te,0.,cs*x/norm*rate)
call hfill(5000,Te,0.,cs*x/norm*rate)

* performs gaussian smear

call gauss_smear(Te,bw,p,num)
j=1
if(j.eq.1) then
call hfill(6000,Te,0.,p(1)*cs*bf1*bp/norm*rate)
call hfill(7000,Te,0.,p(1)*cs*bf1*bp/norm*rate)
call hfill(8000,Te,0.,p(1)*cs*bf1*bp/norm*rate)
call hfill(100*k,Te,0.,p(1)*cs*bf1*
+ bp/norm*rate)
call hfill(6000,Te,0.,p(1)*cs*x/norm*rate)
call hfill(7000,Te,0.,p(1)*cs*x/norm*rate)
call hfill(8000,Te,0.,p(1)*cs*x/norm*rate)
call hfill(100*k,Te,0.,p(1)*cs*x/norm*rate)
endif
do j=2,num
call hfill(6000,Te+bw*(j-1),0.,p(j)*cs*bf1*
+ bp/norm*rate)
call hfill(7000,Te+bw*(j-1),0.,p(j)*cs*bf1*
+ bp/norm*rate)
call hfill(8000,Te+bw*(j-1),0.,p(j)*cs*bf1*
+ bp/norm*rate)
call hfill(100*k,Te+bw*(j-1),0.,p(j)*
+     cs*bf1*bp/norm*rate)
call hfill(6000,Te-bw*(j-1),0.,p(j)*cs*bf1*
+ bp/norm*rate)
call hfill(7000,Te-bw*(j-1),0.,p(j)*cs*bf1*
+ bp/norm*rate)
call hfill(8000,Te-bw*(j-1),0.,p(j)*cs*bf1*
+ bp/norm*rate)
call hfill(100*k,Te-bw*(j-1),0.,p(j)*
+     cs*bf1*bp/norm*rate)
call hfill(6000,Te+bw*(j-1),0.,p(j)*cs*x/norm*rate)
call hfill(7000,Te+bw*(j-1),0.,p(j)*cs*x/norm*rate)
call hfill(8000,Te+bw*(j-1),0.,p(j)*cs*x/norm*rate)
call hfill(100*k,Te+bw*(j-1),0.,p(j)*
+     cs*x/norm*rate)
call hfill(6000,Te-bw*(j-1),0.,p(j)*cs*x/norm*rate)
call hfill(7000,Te-bw*(j-1),0.,p(j)*cs*x/norm*rate)
call hfill(8000,Te-bw*(j-1),0.,p(j)*cs*x/norm*rate)
call hfill(100*k,Te-bw*(j-1),0.,p(j)*
+     cs*x/norm*rate)
enddo
enddo
enddo
read(7,*) B
goto 10
endif
close(7)
call hrout(0,icycle,' ')
call hrend('decay')
close(17)
end

* ----------------------------------------------------------------
* ----------------------------------------------------------------

* Functions for the above program

function beta(x,Q,bw,bnorm,z,a)

* written by Hannah Newfield-Plunkett, June 2004
* Determines the beta decay energy spectrum of an isotope.
* Inputs: x=kinetic energy of beta
* Q=total energy of decay
* bw=bin width of histogram
* bnorm=normalization of beta function to 1
* z=charge of parent nucleus
* a=mass number of parent nucleus

real*8 me
parameter (me=.510999D0)
if (x.le.0..or.x.ge.Q) then
beta=0.
else

* special correction to beta spectrum of Bi-210 changes value   

if(abs(z).eq.83..and.a.eq.210.) then
beta=sqrt(x**2+2*x*me)*(Q-x)**2*(x+me)/
c     bnorm*bw*fermi(z,a,x)*bi210(x)

* same for K-40 (forbiddenness correction)

else if(abs(z).eq.19..and.a.eq.40.) then
beta=sqrt(x**2+2*x*me)*(Q-x)**2*(x+me)/
c     bnorm*bw*fermi(z,a,x)*rk40(x,Q)

* otherwise, just calculates beta spectrum from Fermi theory

else
beta=sqrt(x**2+2*x*me)*(Q-x)**2*(x+me)/bnorm*bw*fermi(z,a,x)
endif
endif
return
end

*-------------------------------------------------------------------------

function rk40(x,Q)

* by Hannah Newfield-Plunkett
* forbiddenness correction to K40 decay
* Inputs: x=kinetic energy of beta
* Q=total energy of decay

real me
parameter (me=.510999)
pe=sqrt((x+me)**2-me**2)
qnu=Q-x
rk40=qnu**6.+pe**6.+7.*qnu**2.*pe**2.*(qnu**2.+pe**2.)
return
end

*--------------------------------------------------------------------------

function bi210(x)

* by Hannah Newfield-Plunkett
* special correction to Bi-210 decay
* Input: x=kinetic energy of beta

real me
parameter (me=.510999)
parameter(d=0.578)
parameter(b=28.466)
parameter(c=-0.658)

xx=x/me+1.
bi210=1.+d*xx+b/xx+c*xx**2
return
end

*------------------------------------------------------------------------

function betaint(Q,z,a)

* by Hannah Newfield-Plunkett
* integrates the beta function numerically for normalization
* Inputs: Q=total energy of decay
* z=charge of parent nucleus
* a=mass number of parent nucleus

betaint = 0.
do i=1,1000
bw = Q/1000.
x = (i-0.5)*Q/1000.
betaint = betaint + beta(x,q,bw,1.,z,a)
enddo
return
end

*-------------------------------------------------------------------------

real function fermi(z,a,x)

* written by Hannah Newfield-Plunkett
* Fermi correction to all beta spectra
* Inputs: z=charge of parent nucleus
* a=mass number of parent nucleus
* x=kinetic energy of beta

implicit double precision(a-h,o-z)
complex*16 wgamma
external wgamma
real z, a, x
real*8 rnu,g0
real*8 alpha, hbar, me, pi
parameter (alpha=1.D0/137.D0)
parameter (me=.510999D0)
parameter (pi=3.141592654D0)
complex*16 arg,cg
xx=x/me+1.
pe=sqrt(xx**2-1.)
g0=(1.-(alpha*z)**2)
rnu=alpha*z*xx/pe
r=a**(1./3.)
arg=complex(g0,rnu)
cg=wgamma(arg)
abscgsq=dreal(dconjg(cg)*cg)
temp=exp(pi*rnu)*abscgsq
fermi=temp*(pe*r)**(2.*(g0-1.))
return
end

* ---------------------------------------------------------------
* Gaussian smearing subroutine for decay.f and gamma.f

subroutine gauss_smear(Te,bw,p,num)

* written by Hannah Newfield-Plunkett, June 2004
* Determines the percentage of a Gaussian distribution in bins around a
* center bin with data in it.
* Inputs: Te=kinetic energy of beta
* bw=bin width of histogram

* Outputs: p=array containing fraction of distirbution in each bin,
* from mean to three sigma to the right
* num=number of elements in p

common /g_smear/res
real sqrt2
parameter (sqrt2=1.41423)
real p(*)

* standard deviation based on detector resolution

sig=res*sqrt(Te)
num=0
rnorm = 1.+erf(Te/sig/sqrt2)

* calculates amount of Gaussian distribution in each bin for 3 sigma

do i=0,int((3*sig)/bw+0.5)
num=num+1
p(i+1)=(erf(bw*(i+0.5)/sig/sqrt2)-
+ erf(bw*(i-0.5)/sig/sqrt2))/rnorm
enddo
return
end

* ---------------------------------------------------------------
* ---------------------------------------------------------------

Name: Anonymous 2010-03-28 17:35

>>9
Comparing Comp Sci/Engineering code to code produced by engineers/scientitics from other fields is a bit unfair, as most of them just want to get their job done and hack away all kinds of things as long as it works for them.

Name: Anonymous 2010-03-28 17:35

>>9
That wasn't hard to follow.

Name: Anonymous 2010-03-28 17:37

>>10
All of the code in Tanenbaum's books is inconsistently indented in a proportional font.

Name: Anonymous 2010-03-28 18:21

>>5
Speaking of coop students and memory leaks, the worst code I had to deal with was an accounts info server written by an intern who had snaked his ownership of data all through the program, to the point where refactoring alone could not solve the problem--it would require a complete rewrite with fundamentally different design decisions.

I wasn't allowed time to do that, so I pulled an Apache Foundation manoeuvre, and had the server restart itself after ever 10 requests were served. It was an easy fix, but very a sad day.

Name: Anonymous 2010-12-10 14:56

Name: Anonymous 2011-02-03 0:07

Name: Anonymous 2011-02-04 14:17

Name: Anonymous 2011-02-04 17:51

Name: Anonymous 2013-08-31 7:16


 Kimi to Kanojo to Kanojo no Koi was poorly written and had little going for it other than the meta gimmick. Only play it if you're really interested in having someone preach at you about how horrible a person you are for playing eroge

Name: Anonymous 2013-08-31 8:01


KITES, MUTHAFUCKA! DO YOU FLY THEM!?

Name: Anonymous 2013-08-31 8:47


I was offered a position at a Japanese chemical company, starting stateside, and moving to Japan in a few years.

Don't change these.
Name: Email:
Entire Thread Thread List