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
Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

gibbed posted:

I RE'd a little bit of the testalib.exe and it appeared to just be XORing the content with a generated table based on the key (this is just from a quick look though, I could be wrong). So yeah, crappy obfuscation.

That's how AES-CTR and AES-OFB work, except the table is so fantastically large it's impractical to store.

Adbot
ADBOT LOVES YOU

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

tef posted:

to really beat php you have to have it easy to 'deploy' it to oversold shared hosting :v:

you know that bit where you ftp in and then work out how to chmod a file

code:
> git push heroku master

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

Eliza posted:

My guess is that Python sees you're trying to manipulate a tuple's values, fails as would be expected, but hands the operation to the value anyway, where it succeeds since it's a mutable. Assigning a[0] with a simple a[0] = <value> fails as would be expected.

Nah, it only sees that you're modifying a list. That the list is pointed at by a tuple doesn't even enter consideration.

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

AzraelNewtype posted:

This is almost certainly backwards. Odds are very high that it's doing the append before attempting the assignment to immutable tuple, rather than throwing an exception but deciding to continue on anyway.

List appends aren't in place in python, are they?

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

NotShadowStar posted:

But XML. scales. like. a. boss.

The best part was the simple XSLT used to rename a variable, and Tim Bray crying from laughter in the audience.

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug
. accepts any character, * is a Kleene star closure, your automata theory textbook should cover all this.

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

nielsm posted:

It'd be nice to replace those irregular expressions with regular expressions and parser generators... one can wish.

This is generally what I do. I find https://github.com/bkerley/crapshoot/blob/master/lib/crapshoot/parser/scan.rl#L19-%23L30 to be more readable than a regexp that could parse the same thing.

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

tef posted:

no it is totally serious and not tongue in cheek. I wish it was.

That's as serious as a drunk clown playing with a rubber chicken.

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

Lumpy posted:

I am, and let's just say it's mainly a place for designers.

There's so much bad PHP and JavaScript there it's hilarious.

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

Pardot posted:

Since we're still talking about fizzbuzz, here is the best solution:

code:
  (0..99).map {|i| srand(46308667) if (i%15).zero?; ["FizzBuzz", "Buzz", i+1, "Fizz"][rand(4)]}
Find the seed in your language that causes the random number generator to output the sequence.

Shouldn't rand(4) be the same if you seed it the same every time?

Edit: jiggled by trailing if

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

MOOMIN.EXE posted:

one of the developers at my jorb used to insist on doing seperate commits on every single file he modified

I do that. It makes git bisect more useful than it already is.

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

ColdPie posted:

I think you are confused.

  1. Create feature branch.
  2. Write integration test for feature. Test fails due to missing controller bits. Commit.
  3. Write functional test for a controller action. Test fails due to missing controller bits. Commit.
  4. Write controller action. Tests fail for missing model bits. Commit.
  5. Write unit test for model methods to implement feature. Test fails for missing model bits. Commit.
  6. Write model method. Unit test passes. Functional and integration tests fail due to incompleteness of feature/action. Commit.
  7. Repeat until all tests pass.
  8. When feature is complete, pass branch to someone else for review, or wait two days and review it myself.
  9. If review is bad, add tests, repeat.
  10. If review is okay, merge with production, make sure tests still pass.

Yes, broken code with failing tests gets committed. This is why you run tests before building and deploying.

At the same time, I can go back to the reasoning for any line of code, the test that explains the reasoning, and see the commit comment for why I did it. Comments get stored in the git history which can be blamed to individual lines and disappear automatically when the lines they refer to are changed. In-line comments can't do that.

If something gets broken, I can run git bisect against the particular test that requires that feature until I see where it breaks.

I don't worry about repo bloat because commits are really loving cheap in git.

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

Ensign Expendable posted:

code:
public boolean isTrue(boolean bool)
{
    return !Boolean.toString(bool).length()==5;
}



"ifTrue" and "ifFalse" are methods defined on the True and False classes. Smalltalk owns.

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

I met the creator of that on Saturday during "Crash & Compile" at defcon; they won because one of the teams was a PDP-11 gimmick team that picked their language from a d12, and another team used the other gimmick team's d20 from last year.

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

TasteMyHouse posted:

This is looking at commit messages, not comments. Still, php devs probably don't use those either.

ecommerce-mvc-cms-framework.fixed the colors.backup2.real.zip

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

meinstein posted:

code:
textValue = row.Elements<DocumentFormat.OpenXml.Wordprocessing.TableCell>().First().Elements<DocumentFormat.OpenXml.Wordprocessing.Paragraph>().First().Elements<DocumentFormat.OpenXml.Wordprocessing.Run>().First().Elements<DocumentFormat.OpenXml.Wordprocessing.Text>().First().Text;
WHY DEAR GOD WHY

Couldn't you use an xpath?
code:
textValue = row.down('descendant-or-self::tablecell/descendant::paragraph/descendant::run/descendant::text').first.text

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

thelightguy posted:

Amazingly, there are still hotline servers up, and they're serving up exactly what they were serving back in 2001.... Mac warez and low-res porn jpegs. It's like a blast from the past.

"DO NOT DOWNLOAD ANY .SIT OR .HQX IF U WORK FOR THE GOVERNMENT LAW ENFORCEMENT"

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

JediGandalf posted:

So in this very thread I posted some rather horrific Javascript for a mortgage calculator we use and then attempted to "clean" it up with some jQuery. Well here is my solution:
code:
<input type="radio" id="rdoPercentage" checked name="downType" value="pct" />% of sale price 
<input type="radio" id="rdoFixedAmount" name="downType" value="fixed" />fixed amount 

$('#btnCalculate').click(function () { 
if (validForm) { 
var downType=$('#rdoPercentage').val() == "pct" ? "pct": "fixed"; 
 
var mortgage = MortgageCalculator.Calculate( 
$('#txtSalePrice').val(), 
$('#txtDownPayment').val(), 
$('#txtLoanTerm').val(), 
$('#txtInterestRate').val(), 
downType 
);
I'll you all laugh at this at my expense.

Except for the forums mangling your indentation, that looks pretty much par for the course for jQuery.

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

Jabor posted:

code:
var downType=$('#rdoPercentage').val() == "pct" ? "pct": "fixed";
Wouldn't this always be "pct", or am I just not getting jquery?

Oh duh; this is why I prefer to use the DOM:

code:
> f = document.forms['track']
// => <form name="track" id="track" action="/live/form.rvt">…</form>
> f['ident']
// => <input name="ident" id="ident" type="text" value="DAL64" title="e.g. N123AB">
> f['ident'].value
// => "DAL64"

Cocoa Crispies fucked around with this message at 05:40 on Sep 3, 2011

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

pokeyman posted:

Speaking of, and here's an opportunity to ask, I've seen code that aligns all preprocessor directives to the left no matter what. So you get stuff like

code:
            hurtyFlurtySchnipp();
#if DEBUG
            log("sup");
#endif
            etCetera();
I've always assumed it's just lovely style, but it occurs to me that maybe there's some technical reason for it, like gcc's old preprocessor used to ignore any hashes not in column 1 or something. Am I just excusing lovely style?

It's probably because preprocessor tokens are "special," since they're more about the implementation of the software than the design of it.

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

Biowarfare posted:

Why not just use hasChanged && (module1.reload(), module2.reload(), module3.reload(), module4.reload());

(assuming this is js)

Because being cute with short-circuiting is way worse than using an if statement.

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

NotShadowStar posted:

Introducing goto would also require some very complex rules on the limits of jumping because otherwise somebody is going to do something very hosed up that'll put the stack in a hosed up state that would bring down most interpreted languages.

I've used longjmp in a project for a defense contractor.

Sleep well.

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

Plorkyeran posted:

code:
Extents3d extenst = blockRef->GeometricExtents;
for (int i = 0; i < 4; i++)
{
	switch(i)
	{
	case 0:
		p.SetValue(extenst.MinPoint.X, extenst.MinPoint.Y, 0.);
	break;

	case 1:
		p.SetValue(extenst.MaxPoint.X, extenst.MinPoint.Y, 0.);
	break;

	case 2:
		p.SetValue(extenst.MaxPoint.X, extenst.MaxPoint.Y, 0.);
	break;

	case 3:
		p.SetValue(extenst.MinPoint.X, extenst.MaxPoint.Y, 0.); 
	break;
	}
	pointArray->SetValue(p, i);
}
17 lines to avoid duplicating a trivial line of code three times.

Take a drink every time you see a for-switch in this thread.

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

kalleth posted:

code:
 def profile_update
    @user = current_user
    @user.transaction do
      @user.update_attributes(params[:userdata])
      #Destroy and recreate all capabilities to handle the user having deleted some.
      #This is why weu se a transaction
      attrs = %w(capabilities experiences educations skills)
      attrs.each do |attr|
        #for each of the above, destroy them
        @user.send(attr).each{|e| e.destroy}
        const = attr.singularize.constantize
        params[attr.to_sym].each do |el|
          next if el.nil? || el.blank?
          #now create them
          obj = const.create!(params[attr])
          @user.send(attr) << obj
        end
        @user.save!
      end
    end
  end
cool story? I wrote this. Then promptly deleted it again. now I'm staring at a black screen :(

At least move it to the model so you can unit test it.

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

kalleth posted:

$3 per hour gets you software developers, guys, remember that

I have one experience with the cheap kind of developer, and I will never fear offshoring again.

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

HardDisk posted:

Why's this so awful?

How are you supposed to keep track of all that indentation? It's also a 300 line function, which is 200 lines longer than fits on my screen.

Something that big could probably be turned into 30 (or fewer) ten-line functions.

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

Monkeyseesaw posted:

There is a vast gap between the minimal semantic markup it takes to describe for example a news article with navigation menu and the actual markup you need so you can write the set of CSS rules that makes it look half-way decent. That's the very definition of a failed styling language and it should have been immediately obvious to anyone paying attention.

I loving hate CSS so much.

Learn to use CSS and HTML better; you'll find that it's not actually as complicated as you believe it is, and your stress level at work will go down. For what it's worth, I don't see huge div stacks on The New York Times, Wired, or Ars Technica beyond what's needed to semantically organize the content.

Monkeyseesaw posted:

All signs point to us entering a whole new generation of browser wars. I can't loving wait. I mean we *just* got IE on the same page as everybody and now everything's fragmenting again.

Everything's fragmenting on frills like WebGL; layout and other important things are stabilizing. JavaScript VMs are getting faster, and JavaScript compatibility libraries are frighteningly commonplace.

I'd say for 99% of sites, the features at the intersection of modern Firefox, Chrome, and IE9 are all you need.

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

shodanjr_gr posted:

This reminds me of this practice that a cooworker who worked for a defence contractor mentioned.

Unit tests.

For every. Single. Line. Of. Code. Individually.

He might have been exageratting, but still.

http://ruby.sadi.st/Heckle.html

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

nielsm posted:

"C++ doesn't need garbage collection, because it doesn't produce garbage."

C++ doesn't have garbage collection, because it would collect itself!!!

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

Bhaal posted:

I wish it were the case, and I'm sure he's spent plenty of time on those sorts of things, but his background primarily speaks of php, c# and java

Those are prime languages where you want to use break/continue all the time instead of just mapping and reducing the poo poo out of all your things too.

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug
Tom Preston-Warner of GitHub presented at RubyConf last saturday, and one of his points was "code as if it's going to be open-source." So if you're writing something, make it modular, clean, and don't leave your dingus experiments in.

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

Hammerite posted:

I just looked up "ActiveRecord" on wiki and it sounds like a terrible idea. How on earth would you perform complicated select queries that involve joins? Why would you ever not write your own SQL? Apart from the building queries using string concatenation + unescaped input, I don't see the basis for your objection.

Rails was built for web applications like Basecamp. Most queries in these are pretty simple: select a single entry from one table, and join in the kind of record you'll be iterating over: @author = Author.includes(:posts).find(params[:author_id]) produces SELECT * from author INNER JOIN posts WHERE post.author_id == author.id WHERE author.id == 1;

Optimizing the language for the common case (simple queries) is the sane thing to do, especially if you still leave in an interface or two for more complex uses.

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug
DISCLAIMER: I WORK FOR A NOSQL COMPANY IN THE ADVOCACY DEPARTMENT AND ALL MY EXPERIENCE IS WITH WEB APPS

I recommend people start with Postgres because it's a known quantity and most sites never get big enough to where "scalability" matters. If your poo poo is too slow because it's popular you've already loving won. If you want something that has a fancier model than "some columns," MongoDB is good to start with because it's easy to use on Heroku.

If you know you're going to start big (i.e. you're developing software for a business that's already big), you might want to look into the more scalable NoSQL databases like Cassandra (if you can model your data to fit) or Riak (which actually has secondary indices and full-text search now).

Stored procedures are big now, but we call them "HTTP APIs that are Rails/Sinatra/whatever apps with no UI that only exist to serve internal clients." Twitter is one of these now.

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

Aleksei Vasiliev posted:

make a pull request that just requests the file be deleted

Those are the best: "+ 426 additions, - 24,623 deletions" https://github.com/tomdale/everyjs.com/pull/26

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

plushpuffin posted:

I have to work on an application for which this isn't true, and it's a nightmare. Calling A.B.C.D.E.F is pretty commonplace, and each call always involves a SQL query and a home-made cache implementation (which never, ever removes anything from its cache).

[…]

Performing any operation on more than one base object at once takes minutes or hours thanks to this object model, and since the cache never throws anything out, ever, memory usage just keeps growing indefinitely until the application is closed.

Whoa you mean a code horror is in fact a code horror, you don't say?

(ps ActiveRecord supremacy:)
code:
Client.includes("orders").where(:first_name => 'Ryan', :orders => {:status => 'received'}).count

# => SELECT count(DISTINCT clients.id) AS count_all FROM clients
#  LEFT OUTER JOIN orders ON orders.client_id = client.id WHERE
#  (clients.first_name = 'Ryan' AND orders.status = 'received')
And if you've already materialized the query into an Array before you call count, it just uses Array.count.

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

Sedro posted:

code:
public static bool IsEmpty<T>(this IEnumerable<T> source)
{
    if (source == null)
        throw new ArgumentNullException("source");
    if (source is ICollection<T>)
        return ((ICollection<T>)source).Count == 0;
    if (source is ICollection)
        return ((ICollection)source).Count == 0;
    return !source.Any();
}

Why is there a check for if the source is ICollection<T> when you just try treating it as an ICollection next?

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

Sedro posted:

Because ICollection<T> doesn't implement ICollection :doh:

ICollection<T> can't even be cast to a ICollection?

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

tef posted:

i guess you're saying you want type erasure? :v:

I want duck typing :shobon:

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

Munkeymon posted:

Is it weird that I find the notion of an entry point for a browser scripting language kind of distasteful? It's not that you need it to represent the start/exit stack frame.

It seems kind of nice to me, actually. Presuming I can put a main in an included file, I can put it at the top of the file, instead of jamming it in at the bottom or using some weird DOM event hooks to trigger it to start.

Adbot
ADBOT LOVES YOU

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

Munkeymon posted:

There may be things you want to have done before the DOM is ready and things you will want to do after, so driving that with the regular event system just makes sense. I would agree that it's nice to have main(){} as a shorthand for the code to hook the DOM Ready event (if that's what it actually means - I haven't found that in the docs yet), but jQuery pretty well solved event management problems already.

Now what about something you want run after the file is parsed but before the DOM loads? How does jQuery help you put that at the top of the file where you can find it quickly instead of at the bottom?

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