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
king_kilr
May 25, 2007

Vanadium posted:

There is at least one C-inspired language that requires that return is used like a function with parentheses and all, as far as I can tell it is mostly because the compiler guy could not be bothered to specialcase return's syntax. :shobon:

PHP?

Adbot
ADBOT LOVES YOU

king_kilr
May 25, 2007

chocojosh posted:

For simplicity? Am I missing something here or does it just seem to be much easier to use a vector<bool> (or bitset) and just count the enumerated bits? I honestly don't see what advantage there is to factoring prime numbers.


Also, if you need 32 different options, then wouldn't you need to multiply the first 32 prime numbers together? That multiplication gives 31610054640417607788145206291543662493274686990 (47 digit number). I think that would require a significant amount of memory space..

I'm really lost as to who is joking right now :(

He's not looking for things that multiple together uniquely, it's addition.(I think)

king_kilr
May 25, 2007

chocojosh posted:

How would you be able to factor primes by addition?

Let's pick the primes 2,3 and 5. If you use addition then 2 + 3 = 5. How would you distinguish 5 from representing 2 + 3 or from just representing 5.

However, using prime numbers you can find a number that is the product of those primes (as every number can be represented as a unique product of primes).
What about 1, 4, 7 any addition of these numbers will be a unique sum(unless you need to add the same value multiple times, in which case primes are the only option).

king_kilr
May 25, 2007

chocojosh posted:

I simply want somebody to show me how they can implement something using prime factorization or whatever in a way that is better than bitmaps. Nobody has been able to so far, or I am not understand them if there is a better way.

I still feel that I'm new to programming and second-guess myself a lot. I know that a lot of people on these forums know more than I do, but I simply don't see why you would use anything except for a bitset. I'm thinking that most of the people are deliberately posting outrageous solutions as a joke, but I'm not sure if maybe they are being just a bit serious at the same time.

I don't see anything wrong with the bitmap solution, the numbers I used I randomly made up because they worked, I'm sure I could extend that technique for at least another 10 numbers :P , my point was that multiplying primes seemed wasteful.

king_kilr
May 25, 2007

Victor posted:

I think this looks best:
code:
if( true == foo.equals(foo2) == true)
(Just don't do the same with false.)

I think there is something to be said for
code:
if ((foo == foo2) == true)

king_kilr
May 25, 2007

EssOEss posted:

== is generally defined as reference equality, not data equality. Overriding it to perform data comparison would be a Coding Horror.

Not to mention the need to give extra arguments to Equals() - case-sensitivity and comparison culture, in case of strings.

Not necessarily, in python for example `is` is used for reference equality.

king_kilr
May 25, 2007
web2py. The English language doesn't contain the appropriate verbiage to describe this, but I'll give it a shot.

1) Web based code editing tool. That is you edit your code in a web browser, and it just runs. The security risks... I can't even describe.
2) It automatically imports stuff, in many languages this may be the norm, but in Python it's the antichrist, this is advertised as a feature.
3) It automatically does migrations for you, as in it detects a change in your models, and it just changes the DB accordingly.
4) It encourages a disk based session store and in memory caching.
5) It has various DOM helper classes, basically so you can write html in python with stuff like HTML(HEAD(TITLE("my title")), BODY(DIV(A))) etc....

Also, the creator, Massimo di Pierro, just about trolls the internet (reddit in particular) advertising it. Plus he thinks the only difference between Python and Java is "exec".

king_kilr
May 25, 2007

TSDK posted:

I came across a good one-liner today:
code:
sbp->p_buffer = p_destination ? p_destination : 0;

I guess technically in C++ with an overloaded bool operator it does something useful :/

king_kilr
May 25, 2007
Well, this morning when trying to use a subversion python binding for pyvcs/django-vcs I managed to segfault the interpretter just by attempting to open a client to a local svn repo :(

king_kilr
May 25, 2007

dancavallaro posted:

]
This was also the case in Python pre-3.0.


What do you mean "it was the case in Python", no one in the Python community writes print with parens in Python 2.x, especially not as a performance hack as the OP suggests.

king_kilr
May 25, 2007

geetee posted:

We were so close to getting past the PHP side tracking and here you (we) go bringing it back up. See ya in 5 pages and 3 more threads.

It's not our fault PHP is a coding horror.

king_kilr
May 25, 2007

Otto Skorzeny posted:

I was assuming that any taint feature in PHP would be a shittier and dumber cargo-cult-copy of its Perl analog (like every PHP feature)

magic_quotes, that is all.

king_kilr
May 25, 2007

Otto Skorzeny posted:

cout << 0[your_good_posts];

Segmentation fault

invalid types ‘int[int]’ for array subscript

king_kilr
May 25, 2007

Lexical Unit posted:

C++:
code:
int sign = (1, 0, -1);
float f = /* ... */;
float f_neg = (f == fabs (f)) ? 1.0 : -1.0;
float some_calc = fabs (f * /* ... */);
some_calc *= f_neg * sign;
Production code. All I've done is change the names and remove the boring parts.

I'm brought comfort by the knowledge that the optimizer is probably sorting that out.

king_kilr
May 25, 2007

Zombywuf posted:

code:
       def get_from_cache(self, key):
        	"""                                                                                                                                                                     
                Abstract - to override                                                                                                                                                  
                """
		return None
So right, and yet so wrong. :psyduck:

Trailing whitespace, mixed spaces and tabs, and 8 space indents are never right :colbert:

king_kilr
May 25, 2007

Presto posted:

An off-by-one error. :v:

's' - 'a' != 1

king_kilr
May 25, 2007
code:
#include <stdio.h>

int main() {
    printf("%d\n", 's' -  'a');
}
Hey screw you guys, it's legal C code.

king_kilr
May 25, 2007

yaoi prophet posted:

look at your keyboard

oh...

I don't want to talk about it, mine's still sort of funny thought... right? :suicide:

king_kilr
May 25, 2007

dimebag dinkman posted:

That's kind of scraping the bottom of the Coding Horror barrel. Unless I am missing something, it doesn't seriously impact performance, code readability, logical correctness, or anything like that - it's just a bit redundant. Also, are you sure this is the final form this function will take? I can imagine sometimes I might write a function like that if I know that pretty soon there's going to be more going on in it.

Yeah, no it's terrible. It decreases readability.

king_kilr
May 25, 2007
Hey guys, we're on reddit: http://www.reddit.com/r/programming/comments/a4f97/coding_horrors_code_that_makes_you_laugh_or_cry/

king_kilr
May 25, 2007

poopgiggle posted:

I have authored regular expressions which were about 4" wide on the screen.

http://github.com/brosner/everyblock_code/blob/master/ebdata/ebdata/nlp/addresses.py

I hope this makes you feel tiny.

king_kilr
May 25, 2007

Janin posted:

While we're at it:

As I recall this doesn't actually perfectly parse emails, RFC822 allows infintely nested comments, this just allows REALLY nested comments. regex aren't powerful enough to parse 822.

king_kilr
May 25, 2007
Guys you should be using ruby so you can just monkeypatch a to_radians and to_degrees functions onto int.

king_kilr
May 25, 2007

Broken Knees Club posted:

I see your clever ruse.

No clever ruse intended :confused:. I seem to recall rubies integer class isn't actually named that though, is that the alleged ruse?

king_kilr
May 25, 2007

dis astranagant posted:

No one sane uses an integer for radians.

Doh. I'm going to go somewhere and pay penance for my insanity.

king_kilr
May 25, 2007

CanSpice posted:

Not really a coding horror but it's about codinghorror.com:
Spot the horror!

That he wasn't doing backups? (No, backups on *the same server* aren't backups).

king_kilr
May 25, 2007

CanSpice posted:

Not really a coding horror but it's about codinghorror.com:
Spot the horror!

http://74.125.95.132/search?q=cache...lient=firefox-a

king_kilr
May 25, 2007
Anyone here ever parsed psycinfo or scopus records (some medical bibliography format). I'm dealing with a code base for parsing them out, and it's a fracking clusterfuck. It's actually open source :(

king_kilr
May 25, 2007
Does $ret implicitly get set to "" when something is concatinated to it (and it doesn't already exist).

king_kilr
May 25, 2007

gibbed posted:

Yes, but you'll also get a warning (unless you're dumb and have warnings set to something other than E_ALL).

... that's the real coding horror.

king_kilr
May 25, 2007
WTF does he create the parameter, how is __import__("poo poo").create() any worse than that disaster.

king_kilr
May 25, 2007
The real coding horror is not knowing the difference between strong/weak typing and static/dynamic typing.

king_kilr
May 25, 2007

Monkeyseesaw posted:

Lambdas are awesome, I can't imagine why anyone would think otherwise. The alternative is the old 2.0 anonymous delegate syntax which was ugly as hell and hard to read. Unless you've been in bracket land your entire programming career, lambdas read very naturally.

var I can understand because it can make code harder to read at a glance. Yeah weakly-typed languages aren't inherently harder to read than strongly-typed languages but when you run into what looks like weak typing in the middle of strongly-typed code it forces you to put on the breaks.

Having said that its usage in limited areas (like foreach loops on some complicated enumeration or linq expression results) it does make the code more compact without sacrificing too much clarity.

dynamic scares me. Everyone who *thinks* var introduces weak-typing is gonna fuckin' love dynamic.

Congrats, you don't know the difference between strong/weak typeing and static/dynamic. Have a cookie.

king_kilr
May 25, 2007
Ah java, was my_str == "foobar" really that hard.

king_kilr
May 25, 2007

6174 posted:

You have no idea what a break really is, do you?

And you apparently don't understand the purpose of a syntax more expressive than asm.

king_kilr
May 25, 2007

Bhaal posted:

Well no, it can't be less than the current balance. It doesn't make sense for the balance to be a larger amount BEFORE you deposit the money, so you have to check for it.
Exactly. The programmer accounted for edge case of negatives by throwing that abs() in there.

This is a phenomenal troll. Now please go away.

king_kilr
May 25, 2007

Dijkstracula posted:

I'm trying to debate whether this guy is the douchiest of all Ruby developers, or the one Ruby dev I'd actually want to have a beer with.

Zed doesn't drink, but he's quite fun to have a beer.

king_kilr
May 25, 2007

Otto Skorzeny posted:

Does PHP's core or standard library have any other data structures besides its array/hash mashups?

Depends how you define "standard library" do you mean the unholy mess of everything they just threw in the global namespace, or the *actual* SPL. I think the SPL has some more datastructures, they probably suck though.

king_kilr
May 25, 2007
Not a coding horror the way everything else in this thread is, but a friend of mine hates writing functions. I have no idea why, or what caused him to think this way, but he does. He often asks me things like, "Can I do this without writing an extra function?", and I don't get it. Luckily he's still a student, maybe they can beat it out of him.

Adbot
ADBOT LOVES YOU

king_kilr
May 25, 2007

shrughes posted:

That's pretty funny. Is it because he thinks that function calls are expensive?

Nah, nothing like that (my amusing rationale was API bloating :P), I think he doesn't quite "think like a programmer" yet.

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