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
Coffee Mugshot
Jun 26, 2010

by Lowtax

manero posted:

Hey, does anyone know why everything on the page stopped worki

code:
  jQuery("a").click(function(event) {
   event.preventDefault();
   ...

This is dedicated trolling.

Adbot
ADBOT LOVES YOU

Coffee Mugshot
Jun 26, 2010

by Lowtax
EDIT: Nevermind, I see the differences now. I'm the coding horror.

Coffee Mugshot
Jun 26, 2010

by Lowtax

OriginalPseudonym posted:

Is that like "I don't know PHP so I'll make PHP in Javascript"?

No, it's like "I don't know javascript, so I'll make javascript in PHP": http://code.google.com/p/phpquery/

Coffee Mugshot
Jun 26, 2010

by Lowtax

:stare:

The part you quoted is the worst part but jesus christ, everything in that markup is awful. I guess it was a couple years ago, so maybe they've learned their lesson?

Coffee Mugshot
Jun 26, 2010

by Lowtax

tef posted:

code:
$sqlQuery = $_GET["sql_query"]
and the query is constructed in javascript and sent with ajax

Is this how you say "Come at me, bro" in PHP?

Coffee Mugshot
Jun 26, 2010

by Lowtax

Chopper posted:

But it's GOOGLE, they do no evil... right? :unsmith:

I have a feeling Google has a lot easier ways to "steal" your online messages.

Coffee Mugshot
Jun 26, 2010

by Lowtax
I don't get it. That's how all my professors' code looks at the university I'm at right now. Turns out the people who teach you how to code don't know how to code themselves.

Coffee Mugshot
Jun 26, 2010

by Lowtax

Thermopyle posted:

I'm really embarrassed to say that I use git and didn't really know this. This is due to me first learning the minimum I needed to know about git during a time crunch and then lazily not ever reading about it more.

Since it came up, I might be good to mention git add -p, which allows for staging hunks. So even if it's the same file, you could commit the different changes to different branches.

Coffee Mugshot
Jun 26, 2010

by Lowtax

Ephphatha posted:

Perl code:
$divideby = 1;
$count = 1;
foreach (my $entry in $options) {
    $html .= "<td>a checkbox and label using values from $entry</td>";
    if ($count / $divideby == 4) {
        $html .= "</tr>\n<tr>";
        $divideby++;
    }
    $count++;
}

Sorry, this is from last page, but this stands out to me as a serious coding horror in PHP. I really don't understand this, but it really seems like PHP devs are extremely adverse to using templating engines and instead there ends up being disgusting html string building and printing. I used to do it, too, but I even see some bigger projects straight up echo out html. Is there something inherently flawed about templating engines that I'm not aware of?

Coffee Mugshot
Jun 26, 2010

by Lowtax

nielsm posted:

Odd, seeing that PHP itself is a templating engine, that has massively grown out of its original purpose.

(By the way that code you quoted is not PHP, it's Perl.)

Oops. That's what I get for knowing PHP and not Perl. I just thought the code tags always said "Perl code." I must be misremembering something.

Coffee Mugshot
Jun 26, 2010

by Lowtax
I'd usually agree with you both, but maybe I have a bias after using Flask/Jinja and Symphony/Twig for a lot of projects lately. Even for simple html pages, I've always found something like:

Python code:
render_template('home.html', options, divideby)
HTML code:
<table>
  {% for entry in options %}
    <td>a checkbox and label using values from {{ entry }}</td>
    {% if loopcount / divideby == 4 %}
      </tr>\n<tr>
      {% set divideby = divideby + 1 %}
    {% endif %}
  {% endfor %}
</table>
easier to read than:

Perl code:
$divideby = 1;
$count = 1;
foreach (my $entry in $options) {
    $html .= "<td>a checkbox and label using values from $entry</td>";
    if ($count / $divideby == 4) {
        $html .= "</tr>\n<tr>";
        $divideby++;
    }
    $count++;
}
It seems like a good way to further separate logic from presentation. I also feel that the $html variable is really distracting because you end up having to read a lot of code to find out what it actually is/does at the point it gets echo'd. With a template, I just tell that I'm going to write some html in a loop and there's nothing else there. There's no temptation to store everything inside of $html.

I'm not saying this is the one true way. I just think devs should be less averse to using it for code clarity. But then again, I've only been using them for the past few months, so maybe I'm the horror.

Coffee Mugshot
Jun 26, 2010

by Lowtax

Freakus posted:

Html in code is bad, but code in templates is bad. There's more code than html in all rewrites I've seen - really, what's the point either way?

I'd argue that for debugging purposes, you know exactly where to look. If some HTML renders weird or there's some weird typo, you know that it's something wrong with the presentation logic in the template so you can easily go to that exact point and follow any explicitly mentioned macros from there. When it's in the controller or view logic where you build the HTML, then you need to first find where you build that HTML at, since it could be spread across a lot of other logic before it gets echo'd.

There's not much of a difference, but it seems like a good idea to separate controller/view logic from actual presentation logic. And code in templates is a little bit better than interrupting HTML with weird breaks into <?php ?>. Most people don't use the construction syntax and then you get things like:

PHP code:
<?php if (condition) { ?>
Large amount of HTML output with inlined <?php //code ?>
<?php } ?>
which is extremely hard to debug or extend. Or maybe I'm just bitching about the last time I had to write some custom view logic in Wordpress.

Coffee Mugshot
Jun 26, 2010

by Lowtax

DAT NIGGA HOW posted:

You're telling me its impossible to create a completely cryptographically secure communication application in the browser? Thats an interesting claim.

What is it about browser based applications that makes them impossible to achieve security?

Are you copy-pasting from Hacker News right now or are you serious? Have you ever used a computer before?

Coffee Mugshot
Jun 26, 2010

by Lowtax

Deus Rex posted:

fix that opening brace and it is perfect

Yeah, why put a space between the `else` and the `{` and not between the `if` and the `{`? I imagine that's a typo.

Unless you were talking about putting the opening brace on the next line. In which case, gently caress you.

Coffee Mugshot
Jun 26, 2010

by Lowtax

pokeyman posted:

Just probate everyone who continues a tabs v. spaces (or similar) argument beyond the third consecutive reply.

As long as you make sure the probation message is within 80 characters.

Coffee Mugshot
Jun 26, 2010

by Lowtax

Scaramouche posted:

I'm not going to post code because it would just be a nested series of statements, but I've inherited a farrago of snakes

Modz pls rename me farrago of snakes

Coffee Mugshot
Jun 26, 2010

by Lowtax

Isilkor posted:

Is there a reason they can't just replace (what I assume is) their own implementation of HMAC with a small wrapper around OpenSSL, since they're already recommending that and it's part of the standard library?

Why bother with continuously updating the wrapper when it shouldn't be there in the first place? I imagine they want to just totally yank this out of the next version.

Coffee Mugshot
Jun 26, 2010

by Lowtax

Does not compile? Looks like someone needs a testsuite and presumbit hooks. Seriously, I'd rather someone get mad at my tests and linter that keeps being a dick to them about whitespace and lack of backwards compatibility than rollback and blame for every dumb push.

Coffee Mugshot
Jun 26, 2010

by Lowtax

Extortionist posted:

I wish I could dump large bits of my company's codebase on here, because I could demonstrate quite clearly the ways in which dumb people use whitespace.

It doesn't really have anything to do with tabs vs spaces, though--at least where I work, it seems to be more "this script won't run, so I'll just add more braces at the end until it will" kind of stuff.

Should've use Go and gofmt, scrubs :smug:

Coffee Mugshot
Jun 26, 2010

by Lowtax
Wow, someone doesn't write tests. 20 restarts is a whole lot of money lost. Are you the only user or something?

Coffee Mugshot
Jun 26, 2010

by Lowtax
I really don't understand why anyone would find git harder to use than any other VCS or DVCS. Like, what are you guys doing? Cloning, merging, forking, pulling, cherry-picking, and blaming are dead simple. And all git UIs suck save for Github/Bitbucket because a simple alias is nicer than a totally different UX workflow. Even github talks about a bunch of features it has available but find difficult to expose through the UI.

Coffee Mugshot
Jun 26, 2010

by Lowtax
I dunno, I remember going to the ACM Socal programming competition like 3 times and Harvey Mudd beating us up.

Coffee Mugshot
Jun 26, 2010

by Lowtax
Uh, hate to break this to you, but that's not even a lot of imports in python. Also, I hope you never have to write something that uses tons of included dependencies like C/C++.

Coffee Mugshot
Jun 26, 2010

by Lowtax

BigRedDot posted:

Not quite the same thing, but how about a while-else?

code:
n = 5
while n != 0:
    print n
    n -= 1
else:
    print "welp"

http://docs.python.org/2/tutorial/controlflow.html#break-and-continue-statements-and-else-clauses-on-loops.

The only problem I have with for-else in python is that some templating engines use for-else to check if the loop condition isn't true on the very first iteration. Like what Twig does: http://twig.sensiolabs.org/doc/tags/for.html#the-else-clause. So when I switch from writing Twig templates to Jinja templates, I always have weird display errors.

Coffee Mugshot
Jun 26, 2010

by Lowtax

Ithaqua posted:

Of course, the actual horror there is unit testing private methods. :v:

Unless you're teaching a programming class, and want some automated testing. I don't understand the need for the extra #undef private, am I missing something?

Coffee Mugshot
Jun 26, 2010

by Lowtax
If people hate Javascript, why not write code in Coffeescript and pretend it's python? Unless you're actually upset that the answer to "4 < '4'" is not what you expect.

Coffee Mugshot
Jun 26, 2010

by Lowtax
College courses that teach programming all vary wildly in structure in content with the only constant being that their structure and content almost assuredly sucks. Please do not ruin my world view with stories of your Stanford, MIT, and CMU CS courses, those obviously do not count.

For a related coding horror, I present some mime-type checking code I wrote for a school project where we had to make an application with the minimal functionality of Google Docs:

code:
function is_media_format($fileType, $fileName) {
  return (strstr($fileType, "video/") != false || 
          strstr($fileType, "audio/") != false || 
          strpos($fileName, ".webm") != false || 
          strpos($fileName, ".wmv") != false ||
          strpos($fileName, ".mkv") != false ||
          strpos($fileName, ".mp3"));
}
Honestly, I don't know how you're really supposed to do this anyways, but I know this isn't the right solution.

Speaking of compiler horrors in uni, we had to write an Android->JS transcompiler, so I chose to generate Coffeescript and compile that into JS using the `coffee` tool. To support overloaded functions in Coffeescript (since we used an ANTLR Java grammar and didn't know anything about Android), I mapped all function names of a class to a set of definitions of different argument lengths and parameter lists and in the generated Coffeescript I defined each class function by switching on argument length and then doing type checking on each argument for each length case.

Basically, the following code in Java:
code:
public class MultipleConstructor
{
        MultipleConstructor()
        {
        }
        MultipleConstructor(int a , int b, int c, int d)
        {
        }
}
would turn into this "equivalent" Coffeescript code:

code:
class MultipleConstructor
    MultipleConstructor:() ->
        switch arguments.length
            when 0
                ;
            when 1
                if a is Int and b is Int and c is Int and d is Int
                    ;

TL;DR: I'm a bad programmer and I apologize.

Coffee Mugshot
Jun 26, 2010

by Lowtax

I'm referring to actually populating that set to catch the correct video formats. It seemed like a "video/" filetype would be a catchall for videos. I just added the four other on, but I never tested whether any vulnerabilities could happen and I found out a couple of years later (with the site running on my linode still for some reason) that it was vulnerable to this old PHP hack since I couldn't think of better ways to find out if a file was really a video/audio file or not.

Coffee Mugshot
Jun 26, 2010

by Lowtax
With that last example, I almost feel like we're talking past each other. Just because your compiler figures it out fine on your particular architecture, it doesn't mean the behavior is defined by the language specification. I'm sure gcc4.6+ won't blow up on the snippet posted, but that's probably because the forward-propagate RTL pass is turned on by default at every optimization level. But it's even strange to assume two different C/C++ compilers would return the same results for that snippet, although they might.

Coffee Mugshot
Jun 26, 2010

by Lowtax

Don Mega posted:

One of my old coworkers loved to put for loops on one line.

code:
for (var i = 0; i < j; i++){ if ( i > 10) fartbong(); else if (i == 5) { yep(); still_one_line(); } else console.log('dog');}
Some were even longer than this.

Looks like they are compensating for something.

Coffee Mugshot
Jun 26, 2010

by Lowtax
Coding horrors thread: throwing shoes at 15 year olds

Coffee Mugshot
Jun 26, 2010

by Lowtax
Yeah, that's right, I compile with -Wall and -pedantic
Then I get mad and type `python` 'cause I ain't got time for semantics

Coffee Mugshot
Jun 26, 2010

by Lowtax

apseudonym posted:

Lack of code review considered harmful.

Honestly, I doubt that given a code review for this, which was probably one of many files, you would have caught the error on a first pass. Especially since the code is so logically simple. It's like when someone writes the the word "the" twice and your eyes kind of just combine them.

Coffee Mugshot
Jun 26, 2010

by Lowtax
PHP: The Good Parts

Coffee Mugshot
Jun 26, 2010

by Lowtax

revmoo posted:

coworkers that read HackerNews 24/7

This is the real horror, no need to blame a perfectly fine DVCS.

Coffee Mugshot
Jun 26, 2010

by Lowtax
http://cpprocks.com/what-if-c-looked-more-like-python-or-coffeescript/

As a person who likes to write C/C++, Python, and Coffeescript, I am deeply offended.

Coffee Mugshot
Jun 26, 2010

by Lowtax
I just wish people used the auto keyword responsibly.

Coffee Mugshot
Jun 26, 2010

by Lowtax

The Insect Court posted:

The "argument" for NodeJS was that there were a shitload of JavaScript "developers" and NodeJS let them spread to doing server-side stuff without using a sensible language.

Ah, yes, the sensible languages to write server-side code in: Python, Ruby, PHP, and Java.

Coffee Mugshot
Jun 26, 2010

by Lowtax

WHERE MY HAT IS AT posted:

Why yes, that is a 19,000 line source file.

Is that supposed to be uncommon or something?

Adbot
ADBOT LOVES YOU

Coffee Mugshot
Jun 26, 2010

by Lowtax
I don't understand how if Javascript/Node/NPM are bad, you suggest Python/Django/Pip and Ruby/Rails/RVM|Gems are somehow a better alternative. All of these toolchains seem to have mostly the same problems, except the JS toolchain excels in lack of maturity and doesn't have enough C bindings to be included on your lovely OS by default.

Well, I do understand, it's probably because you get paid to write in it and it fits your world view for some reason.

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