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
1337JiveTurkey
Feb 17, 2005

dwazegek posted:

One of my gripes with it is the "retVal" variable (it always seems to be named that way), in the vast majority of the cases, the first "real" value that is assigned to it, is the value that it's going to have at the end of the method. So why not return the value immediately?

Personally, I prefer returning the value immediately, because it makes reading the code easier (or at least, easier for me); if I see a branching statement that immediately returns a value, then I know that the method is done if that branch is hit. If you go with the "single point of return" method, then this is less clear.

RetVal is useful if you're caching outputs somehow like in a map. Since many cache implementations can asynchronously dump some data between testing for its presence and actually getting the data itself, a common idiom is to get the item in question and then test for nullity. If it's there, we got a value. If it's not, we got null and need to switch to Plan B.

Adbot
ADBOT LOVES YOU

1337JiveTurkey
Feb 17, 2005

rotor posted:

jesus christ what the hell

Considering that it's a 128 bit number, I'm guessing he tried obfuscating things by just going through and doing a find-replace with the MD5 of all of the variable names, possibly flipping the occasional bit to make everything a valid identifier.

1337JiveTurkey
Feb 17, 2005

This'll probably horrify some posters, but I like:
code:
blah =	!isset(bravo)?	here(something) :
	isset(charlie)?	here(charlie) :
			nothere();
Conditions in one column, values in another and it's easy to quickly scan for what goes with what with the general else condition going at the end.

1337JiveTurkey
Feb 17, 2005

Jeffrey posted:

I like this, except maybe I'd line up the question marks and possibly the colons, especially if there were more cases.

Extra formatting can make it more of a pain to change things later although the question mark would make a decent column delimiter.

theg sprank posted:

Were you at any point in your life a LISPer?

To be quite honest, I could never figure out what's proper indentation in Lisp for the life of me even if the other stuff makes sense.

1337JiveTurkey
Feb 17, 2005

MORE CURLY FRIES posted:

Sorry if I'm being a bit groggy here, but what's wrong with a switch in a for statement?

Just write them sequentially instead since all that code does is call case 0 and then case 1, but in an obfuscated manner.

1337JiveTurkey
Feb 17, 2005

shopvac4christ posted:

You know, it's so difficult to use an integer as an index on an array, we should just throw an eval around it instead.

code:
if(eval("document.frmFoo.optBar[" + idx + "].checked") == true) baz += 3;

If that wasn't autogenerated, there is no God.

1337JiveTurkey
Feb 17, 2005

Ryouga Inverse posted:

the real wtf is that it actually saves to the file (without asking) and then asks if you want to save the file, but really it's asking "do you not want to delete the file?"

I do something similar when I'm supposed to write out an error log with an execution trace only if some error occurs. At the end, if it succeeded with no errors, I delete it. It's perfect because if it fails to delete for some reason or another, then I needed the log file because that's an error. :v:

1337JiveTurkey
Feb 17, 2005

A copy of that regex takes about 2MB of RAM and 2 ms to compile into an internal FSM representation on my computer. :psyduck:

1337JiveTurkey
Feb 17, 2005

Dijkstracula posted:

I admit I can't even imagine why an implementation of TSP (or, even any of its variants - bitonic TSP, euclidean TSP, etc) would take anywhere near 3000 lines :gonk:

ADD CURRENTEDGEWEIGHT TO TOTALEDGEWEIGHT GIVING TOTALEDGEWEIGHT,

1337JiveTurkey
Feb 17, 2005

http://java.sun.com/javase/6/docs/api/javax/xml/transform/TransformerFactory.html

Apparently just having an XSLT transformer isn't enough. It needs to be instantiated using a factory for extra flexibility. At first I thought it was for the ability to read input and write output as streams, SAX events, STAX events, and DOM trees with the same API. Now I've learned that it's also great for use cases such as the developer having one XSLT implementation which accepts blank namespaces and the server having another XSLT implementation which suffers a fatal error whenever it encounters a blank namespace. :suicide:

1337JiveTurkey
Feb 17, 2005

Zombywuf posted:

Seriously?

Java has so much to answer for.

Cue coding standard that require prefixing similar functions in order for Eclipse to group them correctly.

That's an Eclipse quirk. IntelliJ is perfectly happy to list the class structure in the sidebar in alphabetical order while leaving the code well enough alone. In any case if it's impossible to find anything in a class without putting every member in alphabetical order, the class is probably too drat big to begin with.

1337JiveTurkey
Feb 17, 2005

Otto Skorzeny posted:

By the way, does Java make any guarantees as to the layout of the class based on the order of declaration of members?

There's no guarantees or need to do so. The class file format begins with some identifiers and then a constants pool. Everything else within the file refers to the constants pool including the class name itself. When the class is loaded the constants pool is interned, creating exactly one canonical copy of each constant in the permgen space which everything refers to. Since method, class and field references are also in the constants pool, interning dynamically links the program.

1337JiveTurkey
Feb 17, 2005

I learned an interesting/disturbing use for XSLT when I needed to add some unit tests to some XML data exporter recently. It turns out the exporter doesn't have unit tests in the traditional sense but instead has one unit test. This test is naturally thousands of lines long and spread over several files and includes a set of unit tests for testing itself. This is only prudent for a multithreaded framework which appears* to run different programmatically constructed exports selected using cost/export time based heuristics. These exports are then tested using a combination of XSLT stylesheets which use patterns that cause the transformation to fail when their associated XPath expression matches. Now all I have to do is figure out how those stylesheets get associated with the proper permutations of options and then add my own somewhere in there.

*I'd be more sure if there was a single drat useful comment in the whole thing. :suicide:

1337JiveTurkey
Feb 17, 2005

mr_jim posted:

Time works the same way.

So my stack is actually a cube?

1337JiveTurkey
Feb 17, 2005

yaoi prophet posted:

What exactly does '3rd-level damage' mean?

Sounds to me like it had effects which showed up several modules away from the original cause of the problem. Like a classpath error in one module being traced back to a Kodo error which was caused by yet another module failing to deploy because of what ultimately amounts to the clustering configuration referring to a host that doesn't resolve.

1337JiveTurkey
Feb 17, 2005

I'm stuck at work diagnosing some build error that only happens on my system in a perl script somewhere under seven layers of antcall with some gratuitous javascript tossed in the middle.

edit: I forgot about the little bit which runs some taglet parser over an autogenerated buildfile.

1337JiveTurkey fucked around with this message at 03:44 on Dec 10, 2009

1337JiveTurkey
Feb 17, 2005

Zombywuf posted:

Dunno, what if you want to implement a sort command?

I think you've clarified why Java is the horror.

If you want a CLI command then use the -client rather than -server command line option and complaining that the runtime environment uses more RAM and takes longer to start. If you want a language that lets you write fast code while making gratuitous system calls, it's down aisle 7 between the pixie dust and unicorn farts and beneath the functional compilers that actually generate parallel code.

1337JiveTurkey
Feb 17, 2005

I was teaching some middle schoolers how to use Game Maker's visual programming interface and it turns out that a comment block immediately after an if or an else statement acts in exactly the manner that ColdPie's describing. It sucks when something like that comes up during a live demonstration of how and why you should always comment your code.

1337JiveTurkey
Feb 17, 2005

Toady posted:

On a somewhat related note, why are many new coders full of distrust and want to roll things on their own? No matter how much you tell them it's a bad idea, they will not listen to you. They'll even be polite about it, but you'll never convince them otherwise.

We teach new coders how to write programs that open a file, read a character stream from them, parse it and then write it to another file. We don't teach them how to do the same task with an ESB and data binding API. When I graduated from college, I didn't really trust the libraries and frameworks I now consider indispensable because I didn't understand them but I did understand the Unix model and I did understand how to parse character streams. It took experience before I could really appreciate the level of abstraction that they operated at, and I gained some of that experience by reinventing the wheel on occasion.

1337JiveTurkey
Feb 17, 2005

Sprawl posted:

Both of those ways are dumb because then you have to change too much should you need to make a change. You should just make an custom generic and be passing that.

That sort of ties into the whole thing about beginning programmers and tools in that it's debating the architecture of an essentially solved problem. Just use an ESB and a data binding API, create a Reservation class and get down to the important parts.

1337JiveTurkey
Feb 17, 2005

Broken Knees Club posted:

Is MUMPS an elaborate practical joke?

Most modern dynamically typed scripting languages share the use of an associative array as their primary/only data structure. In that sense, the language is somewhat ahead of the curve and it got there because medical records keeping really needs that sort of functionality. People come down with new problems that require new types of tests and treatments. The relational model doesn't fit very well to it, whereas associative arrays are just what the doctor ordered. :v:

Everything somehow being a row in a database is another way of describing single level storage, which is quite popular outside of OS derivatives of CP/M and UNIX. In Multics, the primary method for accessing files was effectively mmap and there wasn't a need for some dedicated API for writing to disks since a file was just another segment in your process memory space. The UNIX model of files being streams of bytes took off due to the lack of hardware support for that in minicomputers, microcomputers and personal computers. These days everything has virtual memory support, though and the only excuse for multi level storage is that it's what everyone's used to.

1337JiveTurkey
Feb 17, 2005

Shumagorath posted:

I'm not sure what virtual memory has to do with that, but hasn't Microsoft been trying to bring this back for WinFS for a decade now and they just keep getting held up?

WinFS is more than just single level storage in that it's got searching plus pretty much a full OO database with sharing and permissions and every bell and whistle that could possibly exist. SLS on its own simply treats disk storage as plain old memory and RAM as cache. Multics used both segmented and paged memory, and treated every file as a segment that could be mapped into a process space. File reading and writing was performed simply by reading and writing into that segment and the OS would handle it by mapping the pages to memory for reading and writing dirty pages to disk.

Since modern operating systems already do have mechanisms like mmap, I guess that you could say that we do have SLS of a sort as an option although the flat memory space makes it difficult to map the whole file.

1337JiveTurkey
Feb 17, 2005

Amusing anecdotes about systems programming on the VAX 11/780 are truly the fons et origo of all best programming practices.

1337JiveTurkey
Feb 17, 2005

BattleMaster posted:

The only good partner in university is no one at all.

I once had a professor who told me that I had to do one project individually since group projects amounted to having three people watch me do all the work. :smuggo:

1337JiveTurkey
Feb 17, 2005

Somewhat more questionable is that Excel rounds up, VBA for Excel rounds to even and some contractors we hired didn't quite get that distinction.

1337JiveTurkey
Feb 17, 2005

Section 1.4.4.6: Wherein we learn why referential integrity is actually bad

quote:

There are so many problems with foreign key constraints that we don't know where to start:

  • Foreign key constraints make life very complicated, because the foreign key definitions must be stored in a database and implementing them would destroy the whole ``nice approach'' of using files that can be moved, copied, and removed.
  • The speed impact is terrible for INSERT and UPDATE statements, and in this case almost all FOREIGN KEY constraint checks are useless because you usually insert records in the right tables in the right order, anyway.
  • There is also a need to hold locks on many more tables when updating one table, because the side effects can cascade through the entire database. It's MUCH faster to delete records from one table first and subsequently delete them from the other tables.
  • You can no longer restore a table by doing a full delete from the table and then restoring all records (from a new source or from a backup).
  • If you use foreign key constraints you can't dump and restore tables unless you do so in a very specific order.
  • It's very easy to do ``allowed'' circular definitions that make the tables impossible to re-create each table with a single create statement, even if the definition works and is usable.
  • It's very easy to overlook FOREIGN KEY ... ON DELETE rules when one codes an application. It's not unusual that one loses a lot of important information just because a wrong or misused ON DELETE rule.
The only nice aspect of FOREIGN KEY is that it gives ODBC and some other client programs the ability to see how a table is connected and to use this to show connection diagrams and to help in building applications.

MySQL will soon store FOREIGN KEY definitions so that a client can ask for and receive an answer about how the original connection was made. The current `.frm' file format does not have any place for it. At a later stage we will implement the foreign key constraints for application that can't easily be coded to avoid them.

1337JiveTurkey
Feb 17, 2005

dark_panda posted:

Definitely a joke. The entire blog is hilariously bad so yeah, definitely a joke. I just wish there were more comments in the comments sections from people taking the bait.

The one thing that makes me think it's real is that "Reinvent the Wheel with Ground-up Teleporters" is practically a design pattern.

1337JiveTurkey
Feb 17, 2005

dark_panda posted:

Nah, it's just too good to be real. I mean, it hits all the right notes so well:

I'm sort of used to seeing Verner cyphers using a plain old PRNG, home-cooked reference counting in Java to 'help' the GC, code generation driven by a >300kB .xsl file and a CVS repository with nightly branches and tags for major code branches. There is literally no code so utterly perverse in its design or implementation that I couldn't believe it's real but you're right that the density of the idiocy pretty much had to be by design. At least I hope so, since I'd hate to think that there's production code out there written by someone who thinks that using 20 MB to store an interned string is a great way to save memory.

1337JiveTurkey
Feb 17, 2005

Plorkyeran posted:

Does that make PHP Stalin?

No, .NET is Stalin and Mono is the People's Republic of Tannu Tuva. PHP is probably Imperial Japan or something.

1337JiveTurkey
Feb 17, 2005

Sewer Adventure posted:

Yeah but still they should ditch the decimal point and treat the numbers as cents

It still isn't going to work if you do anything which involves multiplying by non-integral numbers such as interest rates. Even then the interest rates still won't work unless you can express them as the sum of several powers of two. The least that can be said is that they're not something like GTINs. Handling those unambiguously when reading in an Excel file is not fun.

1337JiveTurkey
Feb 17, 2005

Hammerite posted:

"Content-oriented"? I've not heard that before. What's an example of something that isn't content-oriented?

Any site where viewing content created by the site owner or someone else is a means to an end rather than an end in and of itself. You can go to Amazon just to read reviews and look at book covers, but most people go there to buy stuff.

1337JiveTurkey
Feb 17, 2005

It's more of an irk than anything else, but the Scala compiler treats all tabs as eight spaces and I've got IDEA set up with 4 space tabs so all of the error messages end up pointing to the wrong spot on the line.

1337JiveTurkey
Feb 17, 2005

pokeyman posted:

Dot is "any one character", star is "zero or more times". So the empty string is indeed matched by .*.

Beyond that any string is matched by .* because it eagerly evaluates. Even if you took out the ^ in the middle, ^(.*)(ox)$ can never match anything.

1337JiveTurkey
Feb 17, 2005

You have to explicitly tell the standard Java regex to backtrack with (.*?) because it can significantly affect performance.

1337JiveTurkey
Feb 17, 2005

Hammerite posted:

http://stackoverflow.com/questions/6163683/cycles-in-family-tree-software


Masterful troll, or all kinds of horror at once?

The problem is really just a data error and can easily be solved by simply killing everyone involved and removing their memories from the annals of history.

1337JiveTurkey
Feb 17, 2005

Doc Hawkins posted:

We can learn from their optimism.
Or this could just be implementing part two of my advice.

1337JiveTurkey
Feb 17, 2005

pokeyman posted:

1. It's ugly.
Then don't look at the page source. Or if you really need to, use some XML schema that describes your data in a structured manner and then transform it. It's similar to how CSS is used to separate stylistic elements from the underlying document structure. Instead it's separating the data's logical structure from the document's structure so you don't have spans, divs, tables and the like cluttering up the biographical information of a film director.

quote:

2. That's the whole job of a bloody search engine!
Removing semantically meaningful data is something that should only be done with a reason. If a website were to use PNGs instead of text, it'd be impossible for a search engine to index it in any meaningful way. Removing metadata which is in a standardized format makes it harder for search engines and other tools to use the remaining data effectively.

1337JiveTurkey
Feb 17, 2005

Aleksei Vasiliev posted:

writing code without looking at it is some seriously zen poo poo

This is generated HTML 99 times out of 100 so apart from reviewing developed code for correctness people won't be looking at it anyhow.

1337JiveTurkey
Feb 17, 2005

pokeyman posted:

This admirable goal has nothing to do with the posted example, which in fact adds one div and one span that were not present in the original.
HTML doesn't do structured data very well and it shows. XML with client-side XSLT does much better in that regard since then you can just have an XML document.
code:
<movie>
  <name locale="us">Avatar</name>
  <genre>Science Fiction</genre>
  <director ref="../directors/jamescameron.xml"/>
  <trailer ref="../movies/avatartrailer.mpeg"/>
</movie>
It's not perfect but it's useable as the source for a styled website as well as a ReST API.

quote:

We're talking about a new specification that adds data. As of a month ago, precisely zero websites were using it. What data is being taken away here?

Just as data should be removed only with reason, so should data be added only with reason. There is such a thing as too much.
If nobody makes it available then nobody will ever be able to use it. Google's adopted similar microdata formats in the past. That's why you see stuff popping up on their search results that's for sale from various online retailers.

Adbot
ADBOT LOVES YOU

1337JiveTurkey
Feb 17, 2005

pokeyman posted:

HTML does documents very well, and I'm not sure it was ever seriously offered as a language to describe structured data, so why should it do that very well? As you point out, there are better tools for that job. Yet another attempt to bolt some attributes on to HTML and call it a data description language seems wrongheaded. And ugly.

<structured data store> + <store to html transformation> will generally be better than HTML for any values of the two variables, if your problem is storing and presenting structured data.

Really in that respect I couldn't agree with you more. HTML really does suck at structuring data in any meaningful manner. If there's any reason people use HTML with microformats at all, it's institutional inertia. My issue is that the second half of <structured data store> + <store to html transformation> should be pushed back as far as possible and the structured data should be available as long as possible. Microformats at least keep some structured data available longer and therefore more useful to tools other than plain old web browsers.

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