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
mantaworks
May 6, 2005

by Fragmaster
Uhmm where's the backlight edition??!

Adbot
ADBOT LOVES YOU

dwazegek
Feb 11, 2005

WE CAN USE THIS :byodood:
A piece of code that reads items from a buffer, skips a user-definable amount of items, and processes the rest:
code:
public int ItemsToSkip { get; set; }

public void ProcessNextItem()
{
  int skipAmount = ItemsToSkip;
  while(ItemsToSkip > 0)
  {
    GetItem();
    ItemsToSkip--;
  }
  SomeClass item = GetItem();
  Process(item);
  ItemsToSkip = skipAmount;
}
To make things worse, there were two places in the UI where ItemsToSkip could be altered, one was a slider, the other was a pair of buttons that called ItemsToSkip++ or --, and thus behaved pretty much randomly.

The same guy who wrote this also wrote a UserControl that disposed and recreated all its child controls in the OnPaint :downs:

floWenoL
Oct 23, 2002

quote:

...the context-sensitive return value of an array...

To be honest I like explicitly specifying scalar(@a) for array length as the fact that @a reduces to its length in scalar context (and length(@a) is wrong!) is loving gross.

Presto
Nov 22, 2002

Keep calm and Harry on.

Bonus posted:

Ultimate variable naming scheme
Once when I was looking at some files for a MUD I used to work on, I found some code that went something like:
code:
int eger;
int egral;
int yacis; // Yes A Cow Is Smelly
I don't know.

One of the creators of the MUD had a penchant for naming variables things like bing, blue, rabbit, or womble; and his RCS comments half the time are something like "fixed up the thingy a bit". I think he works for Google now. (If you're reading this, Hi David!)

nebby
Dec 21, 2000
resident mog


If we had editors that let you have rich symbology, colors, icons, tables, and flow diagrams instead just a static grid of ascii text of course this whole argument we just had would be moot since naming would take a backseat. Fortress doesn't count because you have to run the whole thing through LaTeX, and it's read only.

nebby fucked around with this message at 22:39 on Mar 31, 2008

such a nice boy
Mar 22, 2002

nebby posted:



Is that a lesbian porn button under the YouTube button? And why is there a Shakespeare button? Is that to solve the "million monkeys at a million typewriters" problem?

hey mom its 420
May 12, 2007

I never found the appeal of those keyboards because I rarely look at my keyboard and when I need to do stuff quickly I rely on vim's command mode or just on keyboard shortcuts in general while in other applications.

Scaevolus
Apr 16, 2007

nebby posted:

If we had editors that let you have rich symbology, colors, icons, tables, and flow diagrams instead just a static grid of ascii text of course this whole argument we just had would be moot since naming would take a backseat. Fortress doesn't count because you have to run the whole thing through LaTeX, and it's read only.
This is sarcasm, right? please?

pseudopresence
Mar 3, 2005

I want to get online...
I need a computer!
This is the best (experimental) graphical implementation of (a subset of) programming I have yet seen. I agree that in principle there are many potential benefits to be had from a more graphical approach to programming, but this has been tried in the past and is at the very least difficult to make more usable than traditional text-based approaches. It is also irrelevant to our choices of variable names in the software we will be writing for the next 5 to 50 years.
http://subtextual.org/subtext2.html

JawnV6
Jul 4, 2004

So hot ...

such a nice boy posted:

Is that a lesbian porn button under the YouTube button? And why is there a Shakespeare button? Is that to solve the "million monkeys at a million typewriters" problem?
:raise: You're saying you don't have a lesbian porn button on your computer?

Scaevolus posted:

This is sarcasm, right? please?
Variable naming is the last great challenge of coding. Software transactional memory took care of concurrency, now the entirety of software engineering is stuck on retval and i.

nebby
Dec 21, 2000
resident mog

Bonus posted:

I never found the appeal of those keyboards because I rarely look at my keyboard and when I need to do stuff quickly I rely on vim's command mode or just on keyboard shortcuts in general while in other applications.
I think the appeal is that this type of thing will greatly reduce the learning curve for having much more modal UI's. Vim is successful because of its modal-ness and it's commitment to efficiency (as you could probably imagine I am a Vim addict) .. it would be pretty sweet if when I entered a different mode my keyboard quickly changed to identify new commands I might not have learned yet.

I think the amount of modal complexity can probably go up quite a bit if the keyboard helped hold the hand of the programmer until they could run on their own. This type of interface would bring about intuitivity without a loss of efficiency, which is great.

What makes this type of thing applicable to higher level domain language based programming is when you can have a UI with a many customizable modes and have it not be a total roadblock to productivity. Right now, you cannot just open up Vim and start using it. With this type of input device (or one similar) you can totally switch between relevant domains and start cranking stuff out relatively easily without up-front memorization. So, if you wanted to start writing code using logic operators, and then switch to a mode that lets you input electrical diagrams, and then switch to a mode optimized for database schema manipulation, you could have the mode reflected on the keyboard and not rely upon memorizing unintuitive commands. Again, I point to CAD/3d modelling apps as inspiration for this approach. Of course, once you spend a few hours in "database schema manipulation mode" you'd have the muscle memory down, just like you do in Vim.

One thing I think would be really interesting would be the introduction of a kanji-like symbology so the density of information in code could go way up since the cardinality of characters would be much, much higher.

Dessert Rose
May 17, 2004

awoken in control of a lucid deep dream...

nebby posted:

One thing I think would be really interesting would be the introduction of a kanji-like symbology so the density of information in code could go way up since the cardinality of characters would be much, much higher.

Do you ever stop masturbating to thoughts of how steeper learning curves could be added to programming?

nebby
Dec 21, 2000
resident mog

Ryouga Inverse posted:

Do you ever stop masturbating to thoughts of how steeper learning curves could be added to programming?
Well, this is a thread dedicated to what happens when the clueless write code, so barriers to entry might be a good thing :)

Kidding, the kanji thing is just mental masturbation, so you've got me there. That said, the goal of domain specific programming is meant to reduce the barrier to entry by letting domain experts specify the problem using languages they already are familiar with, and decrease the amount of code overall by employing generative programming techniques so there is less work involved. Use the fluffy English readable ambiguous languages high up enough so they are fun and easy to read for humans, and at the bottom you get the dense high learning curve languages that do the actual work on the wavelengths that wizard programmers can be maximally effective.

Fundamentally, the idea is you can have it both ways, but currently the paradigm locks you into a single language with a one type of notation and a single level of abstraction, so it's going to be a while before we see this take hold (if ever.)

And now, a Coding Horror.

Rails' association proxies:
code:
module ActiveRecord
  module Associations
    class AssociationProxy #:nodoc:
      attr_reader :reflection
      alias_method :proxy_respond_to?, :respond_to?
      alias_method :proxy_extend, :extend
      delegate :to_param, :to => :proxy_target
      instance_methods.each { |m| undef_method m unless m =~ /(^__|^nil\?$|^send$|proxy_)/ }

      def initialize(owner, reflection)
        @owner, @reflection = owner, reflection
        Array(reflection.options[:extend]).each { |ext| proxy_extend(ext) }
        reset
      end

      def respond_to?(symbol, include_priv = false)
        proxy_respond_to?(symbol, include_priv) || (load_target && @target.respond_to?(symbol, include_priv))
      end

      # Explicitly proxy === because the instance method removal above
      # doesn't catch it.
      def ===(other)
        load_target
        other === @target
      end

      # More code
    end
  end
end
Rails' association proxies look like an Array, walk like an Array, and talk like an Array, and even *say* they are Array's. But alas, it is not an Array. At the top there, it's basically undefining all the methods (except a few hand picked ones) and then redefining them below. When I saw this a few months ago I thought I had seen everything when it comes to Ruby magic, but this took the cake in terms of the debugger basically lying to me about what the heck was going on. Now that I know what was happening, it makes sense, but there are those few special moments where you feel like a magical fairy has taken over your computer, because what it is doing is not possibly logical, and tracking this behavior down was definitely one of them.

Surge Strip
Nov 2, 2005
Takin' hits
Our intern programmer makes me laugh some days. For example, he future proofed all his code, just in case the definition for a newline ever changes on Windows:

code:
CRLF := #13 + #10;
He codes mostly in Delphi, which has quite a few functions for you to use. I guess he just didn't like the Uppercase function they wrote:

code:
function Upercase(str : string) : string;
   var
   len : integer;
   count : integer;
   newstring : string;
   begin
   len := length(str);
   count := 0;
   while (count < len) do
      begin
      newstring[count] := str[count] - 32;
      count := count + 1;
      end;
   result := newstring;
   end;
So many things wrong. He even got an error that Uppercase was already defined, and so he misspelled it.

Kidane
Dec 15, 2004

DANGER TO MANIFOLD

Triple Tech posted:

These things, as Perl programmer, piss me off:
code:
@stack = ();
for ($i = 0; $i < scalar @elements; $i++) {
  $temporary = do_something_to $elements[$i];

  push @stack, $temporary;
}
It's abundantly clear this person doesn't know about scope, the context-sensitive return value of an array, foreach loops, and map. God drat.
code:
print HANDLE "This one also demonstrates something else.";
print HANDLE "This programmer doesn't know how to use select.";
print HANDLE "Nor does he know what a heredoc is.";
print HANDLE "You get paragraphs of text that look like this.";
print HANDLE "For no reason, really.";
Point is, for you non-Perl folk, is that this poo poo could have been written in a more concise, more native-to-Perl fashion.
While I am paid to write Perl, I am by no means an expert. However, I'm of the opinion that there is nothing inherent to Perl which requires overly-concise code. My boss looked at some code I wrote and said "it's very straightforward" which I take as a compliment although I suspect many Perl programmers wouldn't. :) My code tends to look like this:

code:
my $parse_mail = Email::Simple -> new( $email );
my $sender = $parse_mail -> header( "From" );
my $jira_summary = $parse_mail -> header( "Subject" );
my $jira_description = $parse_mail -> body;
I know of the more Perl-like way to write that, I just don't care. Someone here described my Perl as "awkward" which may very well be accurate.

Zombywuf
Mar 29, 2008

Kidane posted:

While I am paid to write Perl, I am by no means an expert. However, I'm of the opinion that there is nothing inherent to Perl which requires overly-concise code.

No, but concise code is often much easier to read, e.g.
code:
@array2 = map \&do_something, @array1;
Does exactly what it says on the tin.

As for the Optimus KB; WANT! Really, after having just looked at it I may need a change of underwear.

tef
May 30, 2004

-> some l-system crap ->

nebby posted:

Fortress doesn't count because you have to run the whole thing through LaTeX, and it's read only.

I believe you are looking for APL.

It needed special keyboard and editors:


Also:

Dijkstra posted:

APL is a mistake, carried through to perfection. It is the language of the future for the programming techniques of the past: it creates a new generation of coding bums.

Triple Tech
Jul 28, 2006

So what, are you quitting to join Homo Explosion?

Kidane posted:

code:
my $parse_mail = Email::Simple -> new( $email );
my $sender = $parse_mail -> header( "From" );
my $jira_summary = $parse_mail -> header( "Subject" );
my $jira_description = $parse_mail -> body;
I know of the more Perl-like way to write that, I just don't care.

Then you're no friend of mine. :colbert: There's a difference between being concise and golfing (which Perl folk love to do) and this isn't golfing. The entire field of computer science has been about a power versus concision payoff. And if you can't see that, then you're hopeless.
code:
my $parse_mail       = new Email::Simple($email);
my $sender           = $parse_mail->header('From');
my $jira_summary     = $parse_mail->header('Subject');
my $jira_description = $parse_mail->body;

MrMoo
Sep 14, 2000

Triple Tech posted:

code:
print HANDLE "This one also demonstrates something else.";
print HANDLE "This programmer doesn't know how to use select.";
print HANDLE "Nor does he know what a heredoc is.";
print HANDLE "You get paragraphs of text that look like this.";
print HANDLE "For no reason, really.";

Same crap in PHP, I just roll my eyes and remember 8-bit BASIC. With PHP you have more options to make it read easier, so its even more retarded.

Similar vein is variable substitution like this, but for large HTML/XML blocks:
code:
echo "hello ".$user.", today is ".$date."\n";
The <<< function is obviously too much voodoo for some developers.

npe
Oct 15, 2004

quote:

Then you're no friend of mine. There's a difference between being concise and golfing (which Perl folk love to do) and this isn't golfing. The entire field of computer science has been about a power versus concision payoff. And if you can't see that, then you're hopeless.

You guys are arguing about inelegant code, which can be annoying if there's a lot of it sure, but I have a hard time calling it really a "code horror", unless you're the type of person that gets in a huff about everyone's bike shed.

For me, true code horror is when you realize that the author clearly doesn't have any idea whatsoever that what they are doing is terribly dangerous and evil (see my COMMIT in stored procedures rant from earlier), or just so outright incompetent that it's obvious the author doesn't really "get" programming in any way, like in the following (apologies for recycling this from the last thread, it's just too drat hilarious to me):

code:
  my $perms = stat($path);
  my $permsbin = unpack("B32",pack("N",$perms->mode & 0777));
  $permsbin =~ s/.*(.)..(.)..(.)../$1$2$3/;

  # check if file is not readable
  if ($permsbin != 111) {
    # error!
    # ...snip...
  }

Kidane
Dec 15, 2004

DANGER TO MANIFOLD

Triple Tech posted:

Then you're no friend of mine. :colbert: There's a difference between being concise and golfing (which Perl folk love to do) and this isn't golfing. The entire field of computer science has been about a power versus concision payoff. And if you can't see that, then you're hopeless.
code:
my $parse_mail       = new Email::Simple($email);
my $sender           = $parse_mail->header('From');
my $jira_summary     = $parse_mail->header('Subject');
my $jira_description = $parse_mail->body;
Hm.

I hate to admit it, but your way is much easier to read, and perltidy agrees with you. Like I said, I'm no expert, and I'm not married to my style of coding.

nebby
Dec 21, 2000
resident mog

tef posted:

I believe you are looking for APL.
Sweet. I didn't know something like this existed that far back in computing, it's got issues because it seems to have many degrees of freedom (not sure about that), but it looks pretty ingenious to me considering the time it was invented. Despite your quote of Dijkstra, it doesn't appear APL is considered a universally discarded idea. I'd argue the existence of Fortress is evidence of it's validity.

Being able to key in code in the language using plain ASCII or unicode key chords is just a matter of modality, which is what I was talking about. You could project APL in plain text mode for enhanced intuitivity and input, and re-project it as unicode when it was time to dig through code you've already understood. As long as this re-projection is quick and painless, it's a great approach. Fortress fails on this account because it sees the reprojection as a separate offline process altogether, though I suppose tools can get better. A bigger problem though is that Fortress doesn't let you mix domain languages (it's domain is higher mathematics, really) but that's an altogether different problem than the one APL and Fortress are trying to solve with symbology.

tef
May 30, 2004

-> some l-system crap ->

nebby posted:

it doesn't appear APL is considered a universally discarded idea.

People liked the point free style and the array operators, but the heiroglyphs haven't been as popular.

nebby posted:

You could project APL in plain text

Infact, K and J are APL variants that use ascii only.

And going back a little to the glyphs, space cadet keyboard anyone ? (If you have ever wondered why the keybindings for emacs are a little mental, now you know)




nebby posted:

A bigger problem though is that Fortress doesn't let you mix domain languages (it's domain is higher mathematics, really) but that's an altogether different problem than the one APL and Fortress are trying to solve with symbology.

I think you're looking for katahdin.

code:
import "fortran.kat";
import "python.kat";

fortran {
  SUBROUTINE RANDOM(SEED, RANDX)
  ...
  END
}
python {
  seed = 128
  randx = 0
  for n in range(5):
    RANDOM(seed, randx)
    print randx
}

nebby
Dec 21, 2000
resident mog

tef posted:

I think you're looking for katahdin.
This is neat, but depressing at the same time. The motivation is great, but the emphasis on parsing being focus of the problem shows how the current paradigm is broken. We need to be editing higher level data structures when programming (ASTs) so that parsing from linear ASCII sequences becomes an additional feature added to a language, not something we need to do anything productive, and we can focus on designing a language that is correctly expressive. This is part of the issue with Fortress, I saw Guy Steele's talk on that at OOPSLA 06 and a huge chunk of his talk was dedicated to how parsing Fortress works, which is depressing in the same way this is.

dustgun
Jun 20, 2004

And then the doorbell would ring and the next santa would come
Back to crummy code.
code:
int Parser::Find()
{
    int found = -1;
    int i;
	for(i = 0 ; i < BUFFER_SIZE ; i++)
	{
		if (STOPWORD == m[i])
		{
                    found = 1;
		    break;
		} 
	}

	if (found != 1)
	{
		 i = -1;
        } 
	return (i);
}// end function
:sigh:

Khorne
May 1, 2002

dustgun posted:

Back to crummy code.
code:
int Parser::Find()
{
    int found = -1;
    int i;
	for(i = 0 ; i < BUFFER_SIZE ; i++)
	{
		if (STOPWORD == m[i])
		{
                    found = 1;
		    break;
		} 
	}

	if (found != 1)
	{
		 i = -1;
        } 
	return (i);
}// end function
:sigh:
People write code that bad? I hope it was a first year student.

Dessert Rose
May 17, 2004

awoken in control of a lucid deep dream...

Khorne posted:

People write code that bad? I hope it was a first year student.

edit oh I see, this is just another "single entry and exit point" abortion

it seriously took me three readings to figure out how that code could possibly work

Victor
Jun 18, 2004
Clearly, return is a function. :psyduck:

dustgun
Jun 20, 2004

And then the doorbell would ring and the next santa would come

Victor posted:

Clearly, return is a function. :psyduck:

I should mention, just for the sake of mentioning, that this was written by a coworker of a friend of mine. I changed the method and variable names, but, it's real live code somewhere.

the talent deficit
Dec 20, 2003

self-deprecation is a very british trait, and problems can arise when the british attempt to do so with a foreign culture





A non-profit I do some work for had a webpage donated to them by a volunteer that looked like it was deployed in 1996. After multiple people walked away rather than try to work with the volunteer I got asked to take a look at it. Where a form appears on the page is instead this:

code:
<!-- CONTENT CONTAINER -->
  <div id='contentContainer' class='interactivePage'>
    <div id='contentBlock'>
      <!--
        All NAME REDACTED Interactive Pages are protected by password, and Secure Socket Layer Encryption.
        All code contained within them is protected by copyright.
        All attempts to bypass this security will be prosecuted to the fullest extent of the law.
      -->
    </div>
  </div>
<!-- CONTENT CONTAINER -->
So then, in the javascript, I find an eyeframe that's loading this (except it goes on for about six pages):

code:
PAR=window.parent;SYS=PAR.SYS;if(SYS){var v_file=g_page.substr(g_page.lastIndexOf('/')+1);
var v_nameArr=v_file.split('.');
var g_parent=SYS.c34317b7e1dbca8c615e3e8881734c00(v_nameArr[0]).parent;
if(g_parent&&typeof exec!='undefined'){g_parent.exec=exec;}}
if(typeof g_messColor!='undefined'){SYS.messColor=g_messColor;SYS.SIDHIS=new Array();
for(var i=0;i<g_sessHist.length;i++){SYS.SIDHIS[i]=g_sessHist[i];}}
2function submitForm(p_arr,p_page){var vPage=(p_page)?p_page:g_page;
var e208e29dbee8c7f3994a32f56e0be770=document.createElement('form');
e208e29dbee8c7f3994a32f56e0be770.method='post';
e208e29dbee8c7f3994a32f56e0be770.action=vPage;
for(var i=0;i<p_arr.length;i++)
{e208e29dbee8c7f3994a32f56e0be770.appendChild(formItem(p_arr[i].id,p_arr[i].value));}
var vBody=document.getElementsByTagName('body')[0];
vBody.appendChild(e208e29dbee8c7f3994a32f56e0be770);
e208e29dbee8c7f3994a32f56e0be770.submit();}
3function formItem(e8920696c8b3f148933d436606327e19,e03bb7688e58920a3532ef6fb0354013)
{var c22dbb8e41fd27f2d5c707a8f4551253=document.createElement('input');
c22dbb8e41fd27f2d5c707a8f4551253.type='text';
c22dbb8e41fd27f2d5c707a8f4551253.id=e8920696c8b3f148933d436606327e19;
c22dbb8e41fd27f2d5c707a8f4551253.name=e8920696c8b3f148933d436606327e19;
c22dbb8e41fd27f2d5c707a8f4551253.value=e03bb7688e58920a3532ef6fb0354013;
return c22dbb8e41fd27f2d5c707a8f4551253;}

the talent deficit fucked around with this message at 01:32 on Apr 2, 2008

rotor
Jun 11, 2001

classic case of pineapple derangement syndrome

the talent deficit posted:

code:
var e208e29dbee8c7f3994a32f56e0be770=document.createElement('form');

jesus christ what the hell

jarito
Aug 26, 2003

Biscuit Hider

rotor posted:

jesus christ what the hell

Probably some kind of automated obfuscation app? That's loving horrible. Who would write software to DONATE that was entirely unmaintainable? What a douche.

defmacro
Sep 27, 2005
cacio e ping pong

Victor posted:

Clearly, return is a function. :psyduck:

For what it's worth, I have a hunch this was how it was originally written back when C was very young as evidenced by it appearing in UNIX Version 6. I could be wrong, but I knew I'd seen return treated as a function somewhere reputable before.

MrMoo
Sep 14, 2000

Victor posted:

Clearly, return is a function. :psyduck:

The SSL library by Reuters has oodles of wonders like this. Basically the API is 20 years old and needs to support every lovely poo poo poo poo compiler and linker out there. To an extreme. It's one function per file as old linkers don't smart link properly.

Victor
Jun 18, 2004

dustgun posted:

I should mention, just for the sake of mentioning, that this was written by a coworker of a friend of mine. I changed the method and variable names, but, it's real live code somewhere.
Are you a member of the NRA yet?

nebby
Dec 21, 2000
resident mog

the talent deficit posted:

So then, in the javascript, I find an eyeframe that's loading this (except it goes on for about six pages):
I mean, clearly this is generated code .. not really a Coding Horror depending on how it was generated. (That's not to say it isn't a bastardization of how to build a website appropriately.) For example, OpenLaszlo will generate javascript like this when targetting DHTML (but will use much shorter, sane names like __lz0 to __lz9)

Victor
Jun 18, 2004
I dunno man, insert some underscores into the obfuscated version and it starts looking like Hungarian...

nebby
Dec 21, 2000
resident mog
Ha ha. It's obviously even more advanced than Hungarian, it's the elusive md5(rand()) notation.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

Surge Strip posted:

code:
function Upercase(str : string) : string;
   var
   len : integer;
   count : integer;
   newstring : string;
   begin
   len := length(str);
   count := 0;
   while (count < len) do
      begin
      newstring[count] := str[count] - 32;
      count := count + 1;
      end;
   result := newstring;
   end;

Woah, OK, this example here takes the cake. Let me see if I can list the problems here:

1. A function that does the intended effect already existed.
2. The function name is purposely misspelled.
3. I've never written Delphi before, so correct me if I'm wrong, but newstring is going to be the old string's ASCII characters shifted down 32. So this fantastic reimplementation doesn't even do anything right. (Your newline is now ASCII -22! Or maybe even 234! :woop: )
4. This is a trivial function for someone a month into their first ever programming class with no prior experience. Yet someone got paid to write this.

This simply cannot be topped. This is maximum :psyduck:.

(Did I miss anything?)

Adbot
ADBOT LOVES YOU

nebby
Dec 21, 2000
resident mog

pokeyman posted:

(Did I miss anything?)
He used a While loop instead of a For loop to iterate over a String.

His input variable is named "str" and his aggregating one is named "newstring", if I try to put myself in his position, he probably said to himself, "ok, I'll name the input variable string and the output variable newstring. That makes sense. Oh, god drat it, I can't name a variable string because its one of those special colored in words. I guess I'll just call it str." Surely he did this after having the same mental exercise happen that resulted in Uppercase -> Upercase.

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