Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Zhentar
Sep 28, 2003

Brilliant Master Genius
Searching for "if 1" in my code base here finds enough results that I'm not sure if it's in the tens of thousands or hundreds of thousands. :911:

Adbot
ADBOT LOVES YOU

Zhentar
Sep 28, 2003

Brilliant Master Genius
I've been reluctant to post in here, since most of the things I see would take too much explaining to be funny. But this one takes the cake, and I have to share it:
code:
. s cnt=0
. s cnt=cnt+1,valAry3(cnt)=val3
. s valAry3(0)=cnt
. s valAry4(1)="1"
. s valAry4(0)=1
. k resultvalAry3
. f i=1:1:valAry4(0) q:result1=0  d
. . s result1=0 f j=1:1:valAry3(0) q:result1=1  d
. . . i valAry3(j)=valAry4(i) d
. . . . s result1=1,resultvalAry3(j)=valAry3(j)
. . . . s:pOut(1)="" pOut(1)=pOut(1)_valAry3(j)
. s partResult(2)=partResult(2)!(result1)
. s partResult(1)=partResult(1)!partResult(2)
. s partResult(2)=""
. s partResult("T2")=partResult(1)
. s partResult(1)=partResult(1)&(result2)
. s partResult("T2")=partResult(1)
. s RESULT=RESULT!partResult(1)
. s partResult(1)=""
Note that the leading dots mean this is inside a for loop.

This code is almost equivalent:
code:
. i val3="1" s result1=1 s:pOut(1)="" pOut(1)=val3
s RESULT=RESULT!(result1&result2)
The "almost" is because my version doesn't have a bug in it.

Zhentar
Sep 28, 2003

Brilliant Master Genius

RegonaldPointdexter posted:

What language is that?

MUMPS

Zhentar
Sep 28, 2003

Brilliant Master Genius

PnP Bios posted:

Why are you still using dead software?

Microsoft posted:

Non-Supported Phase
* Support will no longer be offered for Visual Basic 6.0 after nine years of general product availability.
* Visual Basic 6.0 will no longer be supported starting March 2008.

:sigh:

Zhentar
Sep 28, 2003

Brilliant Master Genius
While investigating an issue today, I noticed a form that should be pure UI takes 4 RPCs to the database server to open. I indulged my curiosity and began investigating.

1. Checks if we can get a lock on a certain record. Does not keep lock. The lock will not be needed at any point in the work flow.

2. Checks if the work flow's context is still valid. It's avoidable, but legitimate.

3. Checks if we are allowed to create new records of a certain type. The work flow does not involve creating any records of any type.

4. Tries to load the name of a record. No record is specified. Doesn't matter because no names are supposed to be displayed anywhere.


#3 seemed especially curious, so I dug deeper. As it turns out, the form is multi-purpose, and there is one situation where new records are created. This situation represents somewhere between 0.01% and 0.001% of the instances where the form is used. The situation is also easy to test for in an if statement, as it is already identified in a boolean variable.

Then I took a look at the server code in the RPC. 7 lines of code, with a logic hole big enough to drive a truck through. It doesn't address the majority of cases at all. Given a certain (unusual) configuration, it will get several cases wrong. Of the few cases it does handle correctly, one was an accident.

With that, I pulled up the documentation for the development. The summary (which is used for release notes) states that these changes were removed.

Zhentar
Sep 28, 2003

Brilliant Master Genius

UberJumper posted:

I think the old coop student (who will become a wind-chime soon) didn't use a decompiler. I looked a bit into java Decompilers, but from my understanding is that in java it will return the original functions names, etc. It also keeps comments :confused:

Even if this is the case, an obfuscation program could still have been used to strip any useful names or comments.

Zhentar
Sep 28, 2003

Brilliant Master Genius

Wheany posted:

Well, it doesn't really show from those lines, but there is no need for the flag to even exist in device.c.

That's still not much of a horror; it just looks like useless cruft that's accumulated over many revisions.


To contribute, I just came across some code I wrote 6 months ago....

code:
  s curData=$$get(recId,700,date)
  s %=$p(curData,c10,1),$p(%,c9,1)=itm,itm=itm-$p(%,c9,2)+$p(%,c9,3),$p(curData,c10,1)=%
  s %=$p(curData,c10,2),$p(%,c9,1)=amt,amt=$$addAmount($$subtractAmount(amt,$p(%,c9,2)),$p(%,c9,3)),$p(curData,c10,2)=%
  s %=$p(curData,c10,3),$p(%,c9,1)=grp,grp=grp-$p(%,c9,2)+$p(%,c9,3),$p(curData,c10,3)=%
  s %=$$put(recId,700,date,curData)
  f  s tab=$o(itm(tab)) q:tab=""  d
  . s curData=$$get(recId,700,date,tab)
  . s %=$p(curData,c10,1),$p(%,c9,1)=itm(tab),itm(tab)=itm(tab)-$p(%,c9,2)+$p(%,c9,3),$p(curData,c10,1)=%
  . s %=$p(curData,c10,2),$p(%,c9,1)=amt(tab),amt(tab)=$$addAmount($$subtractAmount(amt(tab),$p(%,c9,2)),$p(%,c9,3)),$p(curData,c10,2)=%
  . s %=$p(curData,c10,3),$p(%,c9,1)=grp(tab),grp(tab)=grp(tab)-$p(%,c9,2)+$p(%,c9,3),$p(curData,c10,3)=%
  . s %=$$put(recId,700,date,tab,curData)
  q

Zhentar
Sep 28, 2003

Brilliant Master Genius

Gazpacho posted:

I understand that everyone has their own sense of code aesthetics, I just wouldn't use it as the basis for calling something a coding horror when my solution is not really much better in production.

The horror is not the original programmer's failure to use negation, so much as the comment suggesting that the original programmer is unaware that negation is even possible.

Zhentar
Sep 28, 2003

Brilliant Master Genius

Goat Bastard posted:

code

Alternatively, if duplicated function calls murdered your father and raped your mother:

code:
if(condition == FIRST_STATE || condition == SECOND_STATE) {
	doFirstStateStuff();
} 
if (condition == SECOND_STATE) {
	doSecondStateStuff();
}

Zhentar
Sep 28, 2003

Brilliant Master Genius

BattleMaster posted:

Hint: Not everyone programs for desktop/server/laptop computers. A lot of embedded devices have compilers that aren't so hot at optimization. For example, MPLAB C18 for PIC microcontrollers never generates jump tables out of if/else chains. It instead turns it into a big chain of comparisons. Small Device C Compiler doesn't either, though its jump-table generation for switch/case is pretty bad as it is.

A year later the inefficiency from forcing things into difficult to maintain code is going to dwarf the overhead of extra conditional branches.

Zhentar
Sep 28, 2003

Brilliant Master Genius

sex offendin Link posted:

Autoindenting is one thing, but moving code around vertically would throw me off all the time.

I don't know where most of my code is vertically. It's convenient having two related functions next to each other, but otherwise I'm just Ctrl+F/jumping to what I'm looking for.

What really sucks is when....

Otto Skorzeny posted:

Perhaps you should all try the Forth way of organizing code


"what is stackholm syndrome?" - leo brodie, 1984, 1994, 2004

You're working in MUMPS and you have a 32k routine size limit and you have to spread your code across 17 different routines.

Zhentar
Sep 28, 2003

Brilliant Master Genius

Avenging Dentist posted:

just loving quit, it's not worth it.

I like it. (My job, not MUMPS)

Otto Skorzeny posted:

"what is stackholm syndrome?" - Zhentar, 2009

Zhentar
Sep 28, 2003

Brilliant Master Genius

HatfulOfHollow posted:

That still doesn't forgive this...

code:
Dim Decimaal As String

Nor the fact that he named it RoundOff because Round is already taken by a standard VB function.

Zhentar
Sep 28, 2003

Brilliant Master Genius

Insurrectum posted:

Goddamn. Looks like I made the right choice.

MUMPS is totally awesome and will train you into a programming legend!

code:
torment(poster) ;
	L+ ^CoC(poster)
	i  d  i 1
	. s ^CoC(poster)="I Love MUMPS!"
	. w !,poster," has been tormented."
	. L- ^CoC(poster)
	e  d  
	. w !,poster," was not available for torment."
	q
code:
d torment("Avenging Dentist")
P.S. "A Case of the MUMPS" has a fairly small intersection with reality, so don't take too much of it to heart.

Zhentar
Sep 28, 2003

Brilliant Master Genius

golgo13sf posted:

He's actually a very good database guy, just lazy sometimes.

Who isn't? That's what you have code review for.

Zhentar
Sep 28, 2003

Brilliant Master Genius

I love this comment:

Coding Horror commenter posted:

My backup strategy? I post my important data in base64-encoded little chunks in the comments on the blogs of people who actually take the necessary steps to backup their data.

U3VpdGNhc2UgY29tYmluYXRpb246IDEgMiAzIDQgNQ==
RS1tYWlsIHBhc3N3b3JkOiBwYXNzd29yZDE=

Zhentar
Sep 28, 2003

Brilliant Master Genius

Lumpy posted:

I want to see the thought process on the variable name....

"I'll call it 's'! No, wait, that could be confusing. 'ss'! Oh man, that's like all nazi and poo poo. 'sss' it is!"

I'd bet it was originally written within a function that had both s and ss already in use. Then the developer realized that it was long and functions shouldn't be long so they should split things up with cut+paste into a new function.

Zhentar
Sep 28, 2003

Brilliant Master Genius
You know you've been using MUMPS too long when... you need to sort a list alphabetically and you aren't sure what to do or how to do that. (It's also a sign you need to stop using other archaic languages when the correct answer does not involve calling a standard library function or property of the list object)

:smith:

Zhentar
Sep 28, 2003

Brilliant Master Genius

Yakattak posted:

It's more like encryption rather than a programming language.

The wikipedia article intentionally uses especially dense, confusing examples. No one (at least around these parts) still writes code that lovely and unreadable these days.

Jonnty posted:

This is the problem with languages like this, it's not like people (often) start writing new projects in them. It's always maintaining old stuff, which is often hard enough with normal languages.

We are still actively developing software using MUMPS and have no plans to ever stop doing so.

Zhentar
Sep 28, 2003

Brilliant Master Genius

rt4 posted:

Are you worried about hurting your career by staying at a place where the core technology you use has little relevance outside your current workplace?

Not too much, no. Partly because we're moving away from VB6 on the client side (thank loving god) to C#. And partly because I actually enjoy doing legacy code maintenance, and I'm picking up plenty of applicable experience in that area.

Zhentar
Sep 28, 2003

Brilliant Master Genius

Zombywuf posted:

Butthurt much?

I'm no fan of java, but I cannot possibly take anyone who thinks this is an acceptable presentation of data seriously.





Edit: (1/(Speed/Fastest Speed)) :psyduck:

Zhentar fucked around with this message at 23:32 on Jan 28, 2010

Zhentar
Sep 28, 2003

Brilliant Master Genius

Dijkstracula posted:

Well, you know, maybe the VB6 interpreter will just go ahead and unroll that "loop", inline what PD(1),PD(2) and PD(3) evaluate to, and strip out all the dead code blocks...right, guys? :ohdear:

VB6 can compile to C object code which is then compiled to binary by VC6, so it will get optimized as well as the VC6 compiler can manage.

Zhentar
Sep 28, 2003

Brilliant Master Genius

Milotic posted:

We have blades at work which restart if a sensor fails - even temporarily. I can see why it makes sense from an ops perspective, but as a developer whose code is running on there, it terrifies the poo poo out of me that it might do it a certain critical juncture.

But there's always the possibility that your code could be unexpectedly terminated... if it's making you more aware of that fact, that's a good thing.


tef posted:

it's easier to crash on an error and restart than recover in some cases.

for example:
http://en.wikipedia.org/wiki/Crash-only_software

There are some failure-resistant CPU architectures that will run everything in duplicate. Run the same thing side by side; if at the end you get two different answers, flush everything and try again.

Zhentar
Sep 28, 2003

Brilliant Master Genius
^^^^ Woo re-implementing standard library functions with unusual names! Brilliant!


LockeNess Monster posted:

What is wrong with complicated conditions and/or math in for loop? It can make sense and be elegant in certain ways.

"Elegant" is not the word I'd choose for needing to search through 6 lines of code to find the semicolons needed to even begin understanding what the loop is doing.

Zhentar
Sep 28, 2003

Brilliant Master Genius

mr_jim posted:

K&R supremacy.

1TBS is accurately named.

Zhentar
Sep 28, 2003

Brilliant Master Genius

Hammerite posted:

I think BODMAS (or whatever you learnt it as) is sufficiently basic to be assumed. Obviously some base level of knowledge could be assumed in all instances.

I find it easier to just always use parenthesis rather than try to keep track of whether or not whatever I'm using today actually correctly follows order of operations.

Zhentar
Sep 28, 2003

Brilliant Master Genius
My money would be on a poor understanding of the syntax involved, or not understanding beforehand what values need to be passed. Either way, it means extra work switching back and forth between from the header trying to correctly define the function.

Zhentar
Sep 28, 2003

Brilliant Master Genius
:smith:

Zhentar
Sep 28, 2003

Brilliant Master Genius

Plorkyeran posted:

There's a difference between invalid input and input that has to be escaped. "gently caress you" in a phone number field should probably be rejected by the UI, but "O'Connor" in a name field certainly shouldn't be rejected. It might need to be escaped prior to being sent to the database, but that should be handled by the code that actually calls the database, not some higher level module.

There's also the small matter of free text comment fields, where there essentially is no invalid input; someone can enter "Comment' DROP TABLE TRANSACTIONS" if they want to, and there shouldn't be anything wrong with that.

Edit:

Avenging Dentist posted:

with no indication in any of the documentation that that's how it actually worked.
To be fair, there probably wasn't any documentation to indicate it.

Zhentar fucked around with this message at 02:35 on Apr 21, 2010

Zhentar
Sep 28, 2003

Brilliant Master Genius

Insurrectum posted:

Does Epic have a thing for physics grads? They tried to recruit me last year as I was graduating. Thankfully, grad school went through.

Physics is one of several majors (math too, and maybe music) that they target to hire into technical services to support customers. The position involves a lot of troubleshooting and debugging, plus potentially developing fixes or custom programming. They're looking for people with logic/reasoning skills that can be taught to program adequately well, while saving the serious programmers for R&D.

Zhentar
Sep 28, 2003

Brilliant Master Genius

Avenging Dentist posted:

the CEO is a fruit loop.

The CEO is also a workaholic, and has built a company culture that expects everyone else to be too (my boss got a call once from someone who heard me mention I only average 42 hours a week).

I like my job well enough, and they pay very well, but I don't think most CoCers could handle the VB6+MUMPS thing.



Not to defend MUMPS, but that article is terribly inaccurate. It also misses a lot of good reasons to hate MUMPS.

Zhentar
Sep 28, 2003

Brilliant Master Genius
It's pretty easy to write obfuscated MUMPS, but with some decent coding standards (and not trying to be clever) it's easy to understand. The abbreviated commands can be confusing if you aren't familiar with it, but it's actually quite nice.

Zhentar
Sep 28, 2003

Brilliant Master Genius

rt4 posted:

Nicer than what? Not trying to be snarky; I just don't get it.

The abbreviated syntax is nicer than the not-abrreviated syntax.

Plorkyeran posted:

Can you post an example of some MUMPS code that you would consider easy to understand? I've never seen any that did anything not completely trivial that wasn't hideous.

I don't have anything handy that would be understandable without a whole lot of context. I'll check out the programming competition thread and put together a solution for something quick, unless you have any specific ideas.

Zhentar
Sep 28, 2003

Brilliant Master Genius

rt4 posted:

Write fizzbuzz

code:
FizzBuzz() n num
	f num=1:1:100 d  
	. w !,num," "
	. w:num#3=0 "Fizz"
	. w:num#5=0 "Buzz"
	q

Zhentar
Sep 28, 2003

Brilliant Master Genius
^^^ Yeah, it does. And I've got more for you too!

I decided to do Project Euler problem #10

http://projecteuler.net/index.php?section=problems&id=10 posted:

The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.

Find the sum of all the primes below two million.

code:
EulerProblem10(limit) n num,check,sum
	;
	f num=2:1:limit s ^CoC(num)=""
	;
	s num=""
	f  s num=$o(^CoC(num)) q:num=""  d  
	. s check=num*num-1
	. f  s check=$o(^CoC(check)) q:check=""  d  
	. . k:check#num=0 ^CoC(check)
	;
	f  s num=$o(^CoC(num)) q:num=""  s sum=sum+num
	q sum

Zhentar
Sep 28, 2003

Brilliant Master Genius

pseudorandom name posted:

Does that print Fizz/Buzz/FizzBuzz instead of or in addition to the number?

...

That isn't FizzBuzz.

Oops. Should've read the description more carefully.

Zhentar
Sep 28, 2003

Brilliant Master Genius

Shumagorath posted:

Am I alone in liking that for loop structure (start:increment:end)? Maybe it's because I got my start in OOT and Pascal.

I'm cool with the for loop structure.

It's the foreach structure that gets a bit awkward, although it makes up for it by being very flexible.

code:
	f  s num=$o(^CoC(num)) q:num=""  d  

Zhentar
Sep 28, 2003

Brilliant Master Genius

Avenging Dentist posted:

QUIT:num="" says "break out of this loop, but only when num is the empty string.

Just to clarify, the empty string is not a legal subscript. When $ORDER returns "", that means you've reached the end of the array.

Internet Janitor posted:

<job security>

Not really. This stuff can be easily trained in under a week.

Zhentar
Sep 28, 2003

Brilliant Master Genius

Avenging Dentist posted:

Which is why the training period is (was?) three months for developers. And that's excluding application training and project-level training. All told, it was about 7 months before I committed a single thing.

Was. They've cut it down to about 2 1/2 months. But of that, only one week was MUMPs specific; the rest was VB, framework, and application training (so I don't know why you would think that was excluded...). By my 6 month mark, I'd completed a project to be delivered to a customer shortly, so I'm guessing your team was weird.

BP posted:

As of a recent version, Caché is now compiled to byte code and comments no longer cause a performance hit. By recent, I mean in the last year or two.

Caché has compiled to byte code for a long time. Comments at the end of lines were stripped, however lines that were pure comments were compiled as noops, to preserve line numbering for jumps to offsets. Recent improvements have allowed lines that are pure comments to be removed entirely.

Adbot
ADBOT LOVES YOU

Zhentar
Sep 28, 2003

Brilliant Master Genius

Avenging Dentist posted:

so in the absence of actual performance data, they relied on superstition to tune their code. Incidentally, this is still the case at Epic, or was when I was there; people who went through training at different times received vastly divergent advice about performance (and it wasn't due to compiler/interpreter changes).

There are still plenty of people who attempt tune their code without gathering performance data, misunderstand recommendations, and disseminate incorrect information. Although this thread is proof that the problem is hardly unique to Epic or MUMPS.

There has been some substantial effort recently to improve the quality of performance training and documentation, which has helped.

Avenging Dentist posted:

Also global variables were infinitesimally faster than local variables

Local variables are much faster than globals for a relatively small number of subscripts. However, globals scale much better.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply