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
Vanadium
Jan 8, 2005

Expecting a C compiler to turn an invalid memory reference into a well-defined program is a bit much, though. I can see that it's a big deal for the kernel folks but this seems like fairly reasonable behavior for the average user.

Adbot
ADBOT LOVES YOU

Zhentar
Sep 28, 2003

Brilliant Master Genius

pseudorandom name posted:

There's a qualitative difference between narrowly following the spec and providing a useful tool, and a knee-jerk response of "But the spec allows us to do this!" doesn't ingratiate you with your users.

Their providing a useful tool depends upon them doing the things that the spec allows them to do. The spec doesn't include undefined behavior because the committee was too lazy to write up how to handle that case, it's there because defining the behavior would force the compiler to emit additional code to enforce preconditions and handle the edge cases on at least some architectures, or would prevent significant optimizations. That is the exact opposite of what their users want.

CHRISTS FOR SALE
Jan 14, 2005

"fuck you and die"

ymgve posted:

To derail a little bit, what are some examples of really good code?

Ruby on Rails is pretty easy to read, and very well documented.

Zamujasa
Oct 27, 2010



Bread Liar
I need to find a way to keep the boss away from the database...

We have a lot of columns in this particular table that are all following the nameslikethis format. No underscores, words run together. It's a little off compared to the rest, but at least I know that this table is consistently different.

And then my boss goes in over the weekend and adds some new pet fields, like last_checked_time. Well, okay. That's dumb, breaks what little consistency there was, but at least it's not--
code:
last_checked_time         varchar(45)
last_checked_ip_address   datetime
:ughh:

And of course this is in the live database, too. Happy Monday! :suicide:


(Not pictured above: the fact that we already have similar fields for storing the last check time.)

Golbez
Oct 9, 2002

1 2 3!
If you want to take a shot at me get in line, line
1 2 3!
Baby, I've had all my shots and I'm fine
Also fun is the varchar(45): An IPv4 address will never be longer than 15 chars, and IPv6 will never be longer than 39. So he just picked a number out of his rear end and was lucky it was long enough to handle an IP (had it been in the correct column, that is).

Zamujasa
Oct 27, 2010



Bread Liar
varchar(45) is also the bizarre default of MySQL Workbench (along with every-field-is-null-by-default).

There are more than a few fields we have that are varchar(500), though. And I just found out that apparently that field isn't for an IP address like the (real) name suggested, it's for the "server time". Because apparently we need to store that, too, in addition to the 4 other timestamps that we're tracking.



I should also mention that I spent this whole weekend trying to figure out how to make this project work, came up with a workable solution, and now everything is suddenly different and he decided over the weekend that we weren't doing it the way we said we were doing it. This is a project we have to have done by the end of the week. :sigh:

tef
May 30, 2004

-> some l-system crap ->
Find a new job, it will be quicker than teaching your boss how to do his.

taqueso
Mar 8, 2004


:911:
:wookie: :thermidor: :wookie:
:dehumanize:

:pirate::hf::tinfoil:

Zamujasa posted:

varchar(45) is also the bizarre default of MySQL Workbench (along with every-field-is-null-by-default).
Apparently an IP can be 45 characters: http://stackoverflow.com/questions/1076714/max-length-for-client-ip-address

Deepak on SO posted:

There's a caveat. For IPv4 mapped IPv6 addresses, the string can be longer than 39 characters. Let me show with an example:

IPv6 (39 bytes) :

ABCD:ABCD:ABCD:ABCD:ABCD:ABCD:ABCD:ABCD
IPv4-mapped IPv6 (45 bytes) :

ABCD:ABCD:ABCD:ABCD:ABCD:ABCD:192.168.158.190
The last 32-bits (that correspond to IPv4 address) can need more than 10 characters.

The correct maximum IPv6 string length, therefore, is 45.

This was actually a quiz question in an IPv6 training I attended. (We all answered 39!)

M31
Jun 12, 2012

Which is a good argument for not storing IP addresses in varchar fields at all.

ijustam
Jun 20, 2005

Zamujasa posted:

I need to find a way to keep the boss away from the database...

We have a lot of columns in this particular table that are all following the nameslikethis format. No underscores, words run together. It's a little off compared to the rest, but at least I know that this table is consistently different.

And then my boss goes in over the weekend and adds some new pet fields, like last_checked_time. Well, okay. That's dumb, breaks what little consistency there was, but at least it's not--
code:
last_checked_time         varchar(45)
last_checked_ip_address   datetime
:ughh:

And of course this is in the live database, too. Happy Monday! :suicide:


(Not pictured above: the fact that we already have similar fields for storing the last check time.)

Wait... the way I'm reading this is that the checked_in_time is a varchar and the IP address is a datetime. How.. ??? :psyduck:

Zamujasa
Oct 27, 2010



Bread Liar

ijustam posted:

Wait... the way I'm reading this is that the checked_in_time is a varchar and the IP address is a datetime. How.. ??? :psyduck:

That's how it originally appeared to me, when I was replacing the column names. I thought it was just a simple screwup of applying the wrong type to the wrong column (since they would make sense the other way). When I asked about it, the boss mentioned how it was actually supposed to both be timestamps, but for some reason instead of storing it as datetime we're storing the raw string.

Because we aren't already storing the raw string in about 5 other places, I guess. :sigh:


I'd consider another job but right now I've worked hard for my lowly $15/hour wage. At least I have benefits, even if they do come out of my paycheck at the end of the week.


RE: IP address talk, we only deal with IPv4. We're probably so rooted in IPv4, in fact, that any attempt to change it would probably cause our poo poo to violently implode.

Golbez
Oct 9, 2002

1 2 3!
If you want to take a shot at me get in line, line
1 2 3!
Baby, I've had all my shots and I'm fine

So by pure chance he got it exactly right.

Strong Sauce
Jul 2, 2003

You know I am not really your father.





Golbez posted:

So by pure chance he got it exactly right.

No MySQL workbench defaults to 45 for varchars, and by pure coincidence an IPv6 can also contain 45 characters. His boss just pressed buttons.

pseudorandom name
May 6, 2007

Yes, so by pure chance, he got it exactly right.

lamentable dustman
Apr 13, 2007

ðŸÂ†ðŸÂ†ðŸÂ†

pseudorandom name posted:

Yes, so by pure chance, he got it exactly right.

That's why he's the boss

Bhaal
Jul 13, 2001
I ain't going down alone
Dr. Infant, MD
I honestly could sit here all day and post coworker code. There is no "coder horrors" thread so I just keep making regular installments of this guy's antics since the CTO feels too burdened to fire him and he can minimally perform with an average of only about 1-2 significant production level problems a week out of him.

Here we're rendering up a view where a simple, nestable data structure needs to be fed into JSON for a js widget to pick it up and do things in the browser. I'll ignore the fact that he doesn't ever pull out the data structure properly and it's very easy to break his numerical index parallel array/query method of building out the data. Here's where he rolls his own JSON, just one small select piece of it (NOTE: It is a 1-dimensional loop that is he is going through in this spot):

php:
<?
        if($element < $elementplus)
        {
            echo '{ attributes: { id : "'.$array[$a]['id'].'" }, data: "'.$array[$a]['name'].'", children : [';
            $open++;
        }
?>
And another choice piece in the same loop block:

php:
<?
        $diff = $element -$elementplus ;
        for($b=0;$b<$diff;$b++)
        {
            echo ']},';
            $open--;
        }
?>
I don't know about you guys but when I find myself writing something like the above block that's usually when I stop myself and ask "what the gently caress am I trying to do and why does it have to be this fiddly?".

This is the same guy who wrote his own (so, so broken) csv parser, resulting in about 200-300 extra lines of code where it's still parsing the csv in spots where it should just be doing data-layer activities, instead of using fgetcsv or one of many csv parsing libraries out there and having the CSV data pulled out error-free and organized in about 3 lines of code.

He's now working on an expedited pet project for the CEO directly because the head boss wants it in flash (don't ask, I don't know either) and he's the only dev who's done stuff in flash. In other words when he bungles it up horribly 1) it'll have very high visibility to top level management, and 2) nobody will be able to un-gently caress the thing he writes.

Bhaal fucked around with this message at 22:21 on Jun 18, 2012

KaneTW
Dec 2, 2011

It's like he's writing such code just to troll you. How can someone code like that?

This reminds me why I went studying physics and not CS, at least physicists have an excuse for writing terrible code.

SavageMessiah
Jan 28, 2009

Emotionally drained and spookified

Toilet Rascal
How about coding standards horrors? I'm "improving" some code I wrote for our parent company by switching over to their "standards".

I can't call functions in if conditions. I can't use booleans implicitly in if conditions (true == blah ahoy!). I have to use single point of return. Hungarian notation.

code:
if(isWrong()) {
    cerr << "A problem" << endl;
    return;
}
code:
bool bIsWrong = isWrong();
if(true == bIsWrong)
{
    cerr << "A problem" << endl;
}
else
{
//the rest
}
Boy howdy, that sure is muuuuch better. Also, indentation with tabs instead of spaces but also mandating tab widths.

That Turkey Story
Mar 30, 2003

SavageMessiah posted:

How about coding standards horrors? I'm "improving" some code I wrote for our parent company by switching over to their "standards".

I can't call functions in if conditions. I can't use booleans implicitly in if conditions (true == blah ahoy!). I have to use single point of return. Hungarian notation.

<snip>


... this is it, folks, this is how we write good code!

Jabor
Jul 16, 2010

#1 Loser at SpaceChem
code:
goto *(isWrong() ? &&err : &&continue);
err:
    cerr << "A problem" << endl;
    goto end;
continue:
    
end:
    return;
:q:

Zombywuf
Mar 29, 2008

SavageMessiah posted:

I can't call functions in if conditions. I can't use booleans implicitly in if conditions (true == blah ahoy!). I have to use single point of return. Hungarian notation.

Hahaha, I think I know why the first condition exists. This is not to say its a good reason, I suspect it has been handed down cargo cult fashion.
code:
on error resume next
if thisFunctionRaisesAnError() then
   andThisIsExecutedAsItsOnTheNextLine()
end if
You see, with this restriction VB 6's insane error handling can't cause weird errors in your C++ code.

Also hungarian notation is bog standard for VB, I suspect the single point of return is pining after VBs named return values.

Your coding standards are literally for VB 6.

Zombywuf fucked around with this message at 00:27 on Jun 19, 2012

MrMoo
Sep 14, 2000


tcha,

Rename one of your interfaces to qwertyuiopasdfghjklzxcvbnm then access the server via another IPv6 host on the LAN.

fe80:ABCD:ABCD:ABCD:ABCD:ABCD:ABCD:ABCD%qwertyuiopasdfghjklzxcvbnm

An IPv6 address can be 39+1+IF_NAMESIZE, with IF_NAMESIZE being 16 or 256 on most platforms.

ToxicFrog
Apr 26, 2008


Zombywuf posted:

Hahaha, I think I know why the first condition exists. This is not to say its a good reason, I suspect it has been handed down cargo cult fashion.

[...]

Your coding standards are literally for VB 6.

To be fair, it's possible that the SPOR restriction has been handed down cargo cult fashion from the structured/unstructured programming wars of the 60s and 70s instead. :v:

Zamujasa
Oct 27, 2010



Bread Liar

SavageMessiah posted:

Hungarian notation.

Hungarian notation is just... :psyduck: Most places that require its use don't even understand what it was supposed to be and just use the brain-dead way from someone's misinterpretation.

Any IDE worth its salt will tell you if you hosed up your typing, you don't need a letter for that.

Internet Janitor
May 17, 2008

"That isn't the appropriate trash receptacle."

MrMoo posted:

An IPv6 address can be 39+1+IF_NAMESIZE, with IF_NAMESIZE being 16 or 256 on most platforms.

And people wonder why IPv6 adoption is abysmal.

PrBacterio
Jul 19, 2000

Jabor posted:

code:
goto *(isWrong() ? &&err : &&continue);
err:
    cerr << "A problem" << endl;
    goto end;
continue:
    
end:
    return;
:q:
Wait... You can take the address of a label? :stare: And then use it in an expression as a goto target? :catstare: And ... you can use a keyword as a label name? :stonk:

pseudorandom name
May 6, 2007

It's a gcc extension that makes writing the main loop of an interpreter slightly more efficient.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

Zombywuf posted:

Hahaha, I think I know why the first condition exists. This is not to say its a good reason, I suspect it has been handed down cargo cult fashion.

I think finding weird coding conventions like this and speculating on their source or reasoning would make for fascinating reading.

Wheany
Mar 17, 2006

Spinyahahahahahahahahahahahaha!

Doctor Rope
I'm pretty sure you don't have to understand my moon language to get the horror:

http://www.omatieto.fi/kartta/postinumero.js
(used on http://www.omatieto.fi/kartta/postinumero.html)

JavaScript code:
function Postcode_procent(){
var myTextField = document.getElementById('postcode');

if(myTextField.value == "48200")return document.getElementById('procent').value = ("22"), document.getElementById('area').value = ("Hovinsaari");
if(myTextField.value == "20240")return document.getElementById('procent').value = ("21"), document.getElementById('area').value = ("Pansio-Perno");
if(myTextField.value == "13250")return document.getElementById('procent').value = ("21"), document.getElementById('area').value = ("Katuma");
if(myTextField.value == "99830")return document.getElementById('procent').value = ("21"), document.getElementById('area').value = ("Saariselkä");
// 2042 rows snipped
else
alert("Tällä postinumerolla ei löydy maksuhäiriöriskiprosenttia. Anna uusi postinumero.")
}

Axel Rhodes Scholar
May 12, 2001

Courage Reactor

MrMoo posted:

tcha,

Rename one of your interfaces to qwertyuiopasdfghjklzxcvbnm then access the server via another IPv6 host on the LAN.

fe80:ABCD:ABCD:ABCD:ABCD:ABCD:ABCD:ABCD%qwertyuiopasdfghjklzxcvbnm

An IPv6 address can be 39+1+IF_NAMESIZE, with IF_NAMESIZE being 16 or 256 on most platforms.

Hate to be all pedantic nerd here but that's not really right - it's how ifconfig or ipconfig or whatever stringify link local addresses, but underneath it scope id is just a 4 byte integer, and also one so ill-defined that it's pretty pointless to bother storing it in a database or relying on it to identify a particular host (I'm not even sure if it's guaranteed that scope ids for an interface persist between reboots, and obviously even converting it to an interface name and storing that is pretty fragile as well). If you really had to store the scope id as a string, you can do just as well with at most 11 characters for the scope id + whatever separator you want ('%', I suppose).

I mean maybe you know what software stack he's using and that it stringifies link-local IPv6 addresses like that, but if it just inet_ntops an IPv6 address then INET6_ADDRSTRLEN will be fine.

Of course IPs should be stored as 16 byte blobs (with v4 in ipv6 mapped format) anyway.

Groke
Jul 27, 2007
New Adventures In Mom Strength

Kim Jong III posted:

And this is what they wanted me to maintain. :fuckoff:

Ahaha.

For a living, I maintain (after a fashion) a pretty large suite of in-house developed legacy database applications written in an obscure and rare language. The bulk of the system is 25 years old and the main developer was a guy who wasn't exactly a spring chicken back then (he is now either in his eighties or dead; long-since retired in either case) and obviously learned the programming trade and formed his habits at some point even further back in the history of technology. In days when storage space was so expensive that you wrote source code without comments and used as short variable names as possible, because every byte of source code had to be stored somewhere and the compilers were limited as to how much text they could handle in any case. So in the older bits of the system, nothing is explained anywhere and none of the variables have descriptive names and a lot of them resemble each other. You can imagine the horrors. Despite all this it's a pretty sweet job (it's mostly pretty easy work but everyone thinks it's really difficult).

tef
May 30, 2004

-> some l-system crap ->

Groke posted:

Ahaha.

For a living, I maintain (after a fashion) a pretty large suite of in-house developed legacy database applications written in an obscure and rare language.

Is it MUMPS? :ohdear:

Groke
Jul 27, 2007
New Adventures In Mom Strength

tef posted:

Is it MUMPS? :ohdear:

Nope, it's this thing: http://en.wikipedia.org/wiki/NATURAL which is used at approximately three sites in my country and I've worked at two of them.

In this language it is quite possible to write source code which is spacious and well-commented and easy for a human reader to follow. But, like, you don't HAVE to.

Golbez
Oct 9, 2002

1 2 3!
If you want to take a shot at me get in line, line
1 2 3!
Baby, I've had all my shots and I'm fine

Zamujasa posted:

Hungarian notation is just... :psyduck: Most places that require its use don't even understand what it was supposed to be and just use the brain-dead way from someone's misinterpretation.

Any IDE worth its salt will tell you if you hosed up your typing, you don't need a letter for that.

We use it here simply due to momentum. Then again, it's PHP, so it ultimately matters nothing, but done right, and with typecasting, it helps ... ... something, I guess? I dunno. But, 100% of the existing codebase is done that way, so why stop now?

MrMoo
Sep 14, 2000

dazjw posted:

Hate to be all pedantic nerd here but that's not really right - it's how ifconfig or ipconfig or whatever stringify link local addresses, but underneath it scope id is just a 4 byte integer, and also one so ill-defined that it's pretty pointless to bother storing it in a database or relying on it to identify a particular host (I'm not even sure if it's guaranteed that scope ids for an interface persist between reboots, and obviously even converting it to an interface name and storing that is pretty fragile as well). If you really had to store the scope id as a string, you can do just as well with at most 11 characters for the scope id + whatever separator you want ('%', I suppose).

Nominally you would only work with global scope IPv6 addresses, anything link-local scope should only be for testing.

The %interface syntax would be generated by getnameinfo from the underlying scope id of the struct sockaddr_in6.

Persistent interface id's are a problem resolved with the latest generation of hardware but certainly an issue with everything older. Facebook et al told the vendors to implement fixed NIC naming to prevent reordering on boot, most OS releases support it now:

http://en.community.dell.com/techcenter/b/techcenter/archive/2011/01/24/consistent-network-device-naming-coming-to-fedora-15.aspx

Johnny Cache Hit
Oct 17, 2011

Groke posted:

Nope, it's this thing: http://en.wikipedia.org/wiki/NATURAL which is used at approximately three sites in my country and I've worked at two of them.

In this language it is quite possible to write source code which is spacious and well-commented and easy for a human reader to follow. But, like, you don't HAVE to.

I've always wondered about jobs with stuff like MUMPS or NATURAL or these languages that are responsible for huge amounts of data but for only like four or five companies in the world.

How do you find this kind of job? What's the outlook like - are companies trying desperately to move away, or is the code base so significant that they'd rather deal with training people?

ozymandOS
Jun 9, 2004

Kim Jong III posted:

I've always wondered about jobs with stuff like MUMPS or NATURAL or these languages that are responsible for huge amounts of data but for only like four or five companies in the world.

How do you find this kind of job? What's the outlook like - are companies trying desperately to move away, or is the code base so significant that they'd rather deal with training people?

The place I'm at just trains people. We have too many customers with too much data (not too mention too much legacy code) to ever really be able to convert to anything else.

evilentity
Jun 25, 2010

Wheany posted:

I'm pretty sure you don't have to understand my moon language to get the horror:

http://www.omatieto.fi/kartta/postinumero.js
(used on http://www.omatieto.fi/kartta/postinumero.html)

JavaScript code:
function Postcode_procent(){
var myTextField = document.getElementById('postcode');

if(myTextField.value == "48200")return document.getElementById('procent').value = ("22"), document.getElementById('area').value = ("Hovinsaari");
if(myTextField.value == "20240")return document.getElementById('procent').value = ("21"), document.getElementById('area').value = ("Pansio-Perno");
if(myTextField.value == "13250")return document.getElementById('procent').value = ("21"), document.getElementById('area').value = ("Katuma");
if(myTextField.value == "99830")return document.getElementById('procent').value = ("21"), document.getElementById('area').value = ("Saariselkä");
// 2042 rows snipped
else
alert("Tällä postinumerolla ei löydy maksuhäiriöriskiprosenttia. Anna uusi postinumero.")
}

How the gently caress people conclude that 2000+ lines of same code with 3 variable things is a good idea? :psyboom:
If only we had these base things... or arrays/dicts at least.

Zhentar
Sep 28, 2003

Brilliant Master Genius

Kim Jong III posted:

How do you find this kind of job? What's the outlook like - are companies trying desperately to move away, or is the code base so significant that they'd rather deal with training people?

Millions upon millions of lines of code, decades of data accumulated. Migrating would cost us man-millennia, on top of enormous expense & effort on the part of our customers, and would probably take at least 5-10 years before nearing the stability of our current codebase. And for what? So we can save a month of training for new hires? So we can get more sympathy in coding horror posts because now our snippets of slow, lovely code are written in SQL?

A large scale migration could easily kill a software company. It's not something you do unless not migrating is certain death.

Adbot
ADBOT LOVES YOU

pigdog
Apr 23, 2004

by Smythe

evilentity posted:

How the gently caress people conclude that 2000+ lines of same code with 3 variable things is a good idea? :psyboom:
If only we had these base things... or arrays/dicts at least.

Not that it couldn't be expressed better, but that code is very probably generated.

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