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
Soricidus
Oct 21, 2010
freedom-hating statist shill

Zemyla posted:

fputs(fp, buf)
That really wouldn't be an improvement.

Adbot
ADBOT LOVES YOU

FlapYoJacks
Feb 12, 2009

ExcessBLarg! posted:

Only if you don't check the return value of snprintf for truncation or error. Actually I should qualify that a bit since there's not universal agreement on best practice.

Some code only checks snprintf for truncation, assuming that with certain use cases it's impossible to error. Other code checks for both truncation and error, but the only error case being "snprintf(...) == -1)". To me, if you're going to check the result of snprintf at all, it makes the most sense to ensure it's in the range [0, size), since, even if a negative return value other than -1 is implausible/"impossible", it's just easy to check for it too.

Even if I "know" the usage of snprintf can't result on truncation or error on the platform, I'd still do a result check as an assert "just in case".

If you really know the usage of snprintf can't result in truncation or error, or more likely just don't care (i.e., preparing a string for log output) and specifically don't want to check the result, then casting the return value to "(void)" at least states that it's a conscious decision to not check the return value instead of an oversight. Although in this case, you definitely care if the string is truncated when passing it to popen.

Thanks! That's really good info and I will start using it that way for sure. I generally don't test for truncation because whenever I use popen it's from a known size of buffer such as the output of ps. I generally stay away from user input programs, but good coding habits are universal. :v:

ExcessBLarg! posted:

fread shouldn't return short (except error or EOF) so you don't need to call it in a loop. Except, apparently there are cases where fread has returned short as result of libc bugs. Furthermore, fread doesn't need to scan for linebreaks like fgets does.

Also thanks for the help! The last time I used fgets was for some string handling functions where I needed to know the line count, so I was using the fgets loop to increment a index when \n was reached. :v: But again, good habits is something I would rather have than lovely habits that work but not for the right reasons.

Zamujasa
Oct 27, 2010



Bread Liar
code:
a = { "a", "b", "c", nil, "e" }

print (#a) -- 5

a[6] = "butt"

print (#a) -- 3
:psypop:


Ran into this when trying to demonstrate that # is foiled by gaps in keys (since "nil" isn't kept as a table entry).

I guess it's deserved for playing around with nils in tables, but still.

Edison was a dick
Apr 3, 2010

direct current :roboluv: only

Zamujasa posted:

code:
a = { "a", "b", "c", nil, "e" }

print (#a) -- 5

a[6] = "butt"

print (#a) -- 3
:psypop:


Ran into this when trying to demonstrate that # is foiled by gaps in keys (since "nil" isn't kept as a table entry).

I guess it's deserved for playing around with nils in tables, but still.

Yeah, that looks like a bug.

It looks like it's setting the internal length attribute on table construction time, since it can easily know the capacity of the fixed list, but then after you set a new key, it has to recalculate and is foiled by the nil.

canis minor
May 4, 2011

code:
function aaa() {
    return {
        test: 1
    }
}; typeof aaa();
> object

code:
function aaa() {
    return
    {
        test: 1
    }
}; typeof aaa();
> undefined

:ohdear:

Vanadium
Jan 8, 2005

Finally someone takes a principled stand against wasting vertical space with that brace style. :colbert:

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

eithedog posted:

code:
function aaa() {
    return {
        test: 1
    }
}; typeof aaa();

> object

code:
function aaa() {
    return
    {
        test: 1
    }
}; typeof aaa();

> undefined

:ohdear:

Aw yeah, ASI horrors. That gift keeps on giving.

ToxicFrog
Apr 26, 2008


Edison was a dick posted:

Yeah, that looks like a bug.

It looks like it's setting the internal length attribute on table construction time, since it can easily know the capacity of the fixed list, but then after you set a new key, it has to recalculate and is foiled by the nil.

If by "a bug" you mean "behaviour that is explicitly documented as undefined in the language specification", then yes:

quote:

Unless a __len metamethod is given, the length of a table t is only defined if the table is a sequence, that is, the set of its positive numeric keys is equal to {1..n} for some integer n. In that case, n is its length. Note that a table like

{10, 20, nil, 40}
is not a sequence, because it has the key 4 but does not have the key 3.

leper khan
Dec 28, 2010
Honest to god thinks Half Life 2 is a bad game. But at least he likes Monster Hunter.
Working on a client application against a server being developed by the guys paying us to write the client. I'm 6 hours into waiting on a deployment that they didn't notify or schedule with us.

Naturally, they have failed to deploy all of their environments at the same time.

Is this the megathread for software deployment procedure horrors? How do you even deal with this, house an SLA in the contract?

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
I once billed a client for 10 hours of "waiting for the server to work" and had it paid without complaint.

When possible, just find other stuff to work. Server downtime is a great time to write more unit tests for poo poo, make your build system less of a barely working pile of garbage, etc.

Zombywuf
Mar 29, 2008

All of the horrors http://www.tedunangst.com/flak/post/worst-common-denominator-programming

quote:

The common way to approach software portability is to establish a baseline and then program to that least common denominator. The portability layers in OpenSSL, however, go way beyond least. This is a fully realized experiment in worst common denominator programming.

Polio Vax Scene
Apr 5, 2009



eithedog posted:

> object

> undefined

:ohdear:

Languages that automatically insert semicolons, the true horror.

Zopotantor
Feb 24, 2013

...und ist er drin dann lassen wir ihn niemals wieder raus...

Plorkyeran posted:

When possible, just find other stuff to work.

I wasted the entire day yesterday because ClearCase decided to stop working on my machine. It got gradually worse, to the point that I could not even open a new terminal window or log in remotely.
Only good thing is that I got a workstation upgrade out of it.

We're planning to transition to Git Real Soon Now. I can't decide whether to wish for it or be terrified about it. I'm sure I'll have plenty of horrors for this thread when it happens.

revmoo
May 25, 2006

#basta
Git is amazing as long as you don't have coworkers that read HackerNews 24/7 and get distracted by every shiny new thing and come up with ridiculously outlandish branching and merging processes. Then you end up with things that belong in this thread.

Soricidus
Oct 21, 2010
freedom-hating statist shill

Manslaughter posted:

Languages that automatically insert semicolons, the true horror.
There's more than one? :ohdear:

Zopotantor posted:

I wasted the entire day yesterday because ClearCase
You can stop there. My condolences.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

Soricidus posted:

There's more than one? :ohdear:

I've never looked at it but I'ma guess ActionScript will insert semicolons without you asking.

Deus Rex
Mar 5, 2005

Golang has (significantly less-retarded) ASI as well.

DeciusMagnus
Mar 16, 2004

Seven times five
They were livin' creatures
Watch 'em come to life
Right before your eyes

When we transitioned to Mercurial from ClearCase, some of the groups estimated it would take months to get it to replace everything. Our project adopted it withing a week and the others with a couple of weeks. Haven't looked back since. Can't recommend getting away from ClearCase enough.

Powerful Two-Hander
Mar 10, 2004

Mods please change my name to "Tooter Skeleton" TIA.


We used to use clearcase and had a dedicated support team except their response to every problem was pretty much "idk it's hosed I guess". Some teams are still on it which should be making somebody nervous. At least we're on svn though so it's a step up.

Edit: I found 1.6gb of possibly confidential pdf files checked into svn last week the dev responsible said "yeah sounds like something I'd do" :v:

Scaevolus
Apr 16, 2007

Deus Rex posted:

Golang has (significantly less-retarded) ASI as well.
Plus it's the only style anyone writes Go in, so you don't have maverick JS developers writing semicolon-free code arguing with the mainstream.

Effective Go posted:

The rule is this. If the last token before a newline is an identifier (which includes words like int and float64), a basic literal such as a number or string constant, or one of the tokens

break continue fallthrough return ++ -- ) }

the lexer always inserts a semicolon after the token. This could be summarized as, “if the newline comes after a token that could end a statement, insert a semicolon”.

Athas
Aug 6, 2007

fuck that joker

Soricidus posted:

There's more than one? :ohdear:

Haskell also inserts semicolons (and curly braces) by itself. That's because the Haskell syntax is nominally indentation-based (like Python), but it's internally reduced to a braces-and-semicolon syntax, which is what the grammar proper is defined in terms of. For example:


code:
fartButts = do butts <- gets allButts
               forM butts $ \butt -> do aim butt
                                        fart butt
               return smell
is converted to

code:
fartbutts = do {
              butts <- gets allButts;
              forM butts $ \butt -> do {
                                      aim butt;
                                      fart butt;
                                    };
              return smell;
              }
Or something like that - most Haskell programmers never use the
explicit notation, except if they have to generate Haskell code for some reason

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

I interviewed with a big games company back in ~2005 and at the time they used SourceSafe for everything (on the team I was going to work with, at least, which was building an MMO). This was especially great for the server guys who were developing for Linux, and had to do Samba copy-over bullshit every time they updated or wanted to commit. One guy said they *routinely* lost changes and had to chase bugs because of it for weeks at a time, but when I asked the lead about it after he interviewed me, his answer was basically ":shrug: I have some batch files".

That's not why I didn't take the job, and it's probably not why the game was cancelled (leaving the company's MMORPG/MMOFPS/MMORTS trinity incomplete!), but I'm sure it contributed to both.

ToxicFrog
Apr 26, 2008


Similarly, Lua permits semicolons as statement separators, but it's not really "ASI" -- the grammar is unambiguous with or without them, and inserting a semicolon anywhere that wasn't already parsed as being between statements is a syntax error. They are permitted primarily to let you semicolon-separate one-liners for readability.

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe

Athas posted:

Or something like that - most Haskell programmers never use the explicit notation, except if they have to generate Haskell code for some reason

Some people use the explicit notation exclusively. Back when I was writing Haskell regularly, I did use the implicit notation, and my experience was that the algorithm generally worked quite well, but:
  • There were some weird cases that didn't quite work the way I expected, and I would consistently run into them, maybe once a week or so.
  • Actually tracking down why it happened so that I could get the implicit notation back on track could turn into a major interruption, because the rules are very complex and the errors are very opaque.
  • It is not possible to fix the problem locally by just adding a semicolon or something; you have to convert the entire block to the explicit notation.
So I can completely understand why some people just give up and used the explicit notation.

Go's design is admirably simple, but it does force some style decisions that I'm not thrilled about, like always putting binary operators on the end of the line instead of the beginning of the next.

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe

Subjunctive posted:

I interviewed with a big games company back in ~2005 and at the time they used SourceSafe for everything (on the team I was going to work with, at least, which was building an MMO). This was especially great for the server guys who were developing for Linux, and had to do Samba copy-over bullshit every time they updated or wanted to commit. One guy said they *routinely* lost changes and had to chase bugs because of it for weeks at a time, but when I asked the lead about it after he interviewed me, his answer was basically ":shrug: I have some batch files".

That's not why I didn't take the job, and it's probably not why the game was cancelled (leaving the company's MMORPG/MMOFPS/MMORTS trinity incomplete!), but I'm sure it contributed to both.

why would anybody build an MMO

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

Suspicious Dish posted:

why would anybody build an MMO

Because they had made money off EQ, and thought lightning would strike them twice, I assume.

Edit: unless you mean "why would someone take a job doing that" in which case I'm not sure, but I do take a sympathetic position on mental illness in general.

Subjunctive fucked around with this message at 00:20 on Apr 24, 2014

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed

ToxicFrog posted:

Similarly, Lua permits semicolons as statement separators, but it's not really "ASI" -- the grammar is unambiguous with or without them, and inserting a semicolon anywhere that wasn't already parsed as being between statements is a syntax error. They are permitted primarily to let you semicolon-separate one-liners for readability.

Lua does have a single case where you need a semicolon:
Lua code:
a = b + c
(print or io.write)('done')
This is parsed as a = b + c(print or io.write)('done') since newlines have no semantic meaning.

I've never actually encountered this problem in real code.

Strong Sauce
Jul 2, 2003

You know I am not really your father.





Plorkyeran posted:

Lua does have a single case where you need a semicolon:
Lua code:
a = b + c
(print or io.write)('done')
This is parsed as a = b + c(print or io.write)('done') since newlines have no semantic meaning.

I've never actually encountered this problem in real code.

Yet people still whine about semicolons.

ToxicFrog
Apr 26, 2008


Plorkyeran posted:

Lua does have a single case where you need a semicolon:
Lua code:
a = b + c
(print or io.write)('done')
This is parsed as a = b + c(print or io.write)('done') since newlines have no semantic meaning.

I've never actually encountered this problem in real code.

:stare:

That was a parse error in 5.1 precisely because of that ambiguity. I had no idea they'd dropped that restriction.

shrughes
Oct 11, 2008

(call/cc call/cc)

rjmccall posted:

Some people use the explicit notation exclusively. Back when I was writing Haskell regularly, I did use the implicit notation, and my experience was that the algorithm generally worked quite well, but:

I began using the explicit notation because that made it super-easy for Emacs to indent the code by hitting tab exactly once.

Presto
Nov 22, 2002

Keep calm and Harry on.

revmoo posted:

Git is amazing as long as you don't have coworkers that read HackerNews 24/7 and get distracted by every shiny new thing and come up with ridiculously outlandish branching and merging processes. Then you end up with things that belong in this thread.
Git is amazing in sort of the same way having ebola is amazing.

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.

Sagacity
May 2, 2003
Hopefully my epitaph will be funnier than my custom title.
Hey, as long as it's implemented in NodeJS (2011), Clojure (2012), Scala (2013) or Go (2014) I don't think anyone in HN will disagree.

Sulla Faex
May 14, 2010

No man ever did me so much good, or enemy so much harm, but I repaid him with ENDLESS SHITPOSTING
I only code in languages that haven't been invented yet.

Westie
May 30, 2013



Baboon Simulator

Sulla-Marius 88 posted:

I only code in languages that haven't been invented yet.

And so do your colleagues, from what you've been telling us.

:downs:

Sulla Faex
May 14, 2010

No man ever did me so much good, or enemy so much harm, but I repaid him with ENDLESS SHITPOSTING

Westie posted:

And so do your colleagues, from what you've been telling us.

:downs:

:D

The latest bit of fun has been trying to explain (for the 2nd or 3rd time) how to protect against SQL injection.

Not even what it is, just "take as a given that data from the user is dangerous, here's this function you need to use that someone has already coded for you".

I don't have the energy to get stuck into "also you have to assume that data already in your database is dangerous too". I'm just.. so help me god I'm just not paid enough for that.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

Strong Sauce posted:

Yet people still whine about semicolons.

Nobody in this thread is claiming that intentionally writing Lua like that is somehow virtuous or worthwhile. I will happily join you (?) in condemning that misfeature of Lua's grammar/parser.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

Sulla-Marius 88 posted:

:D

The latest bit of fun has been trying to explain (for the 2nd or 3rd time) how to protect against SQL injection.

Not even what it is, just "take as a given that data from the user is dangerous, here's this function you need to use that someone has already coded for you".

I don't have the energy to get stuck into "also you have to assume that data already in your database is dangerous too". I'm just.. so help me god I'm just not paid enough for that.

I know that any place that doesn't understand SQL injection won't have code reviews, but this is exactly why you do code reviews.

Fuck them
Jan 21, 2011

and their bullshit
:yotj:
I remember running from a place that asked if I did Dynamic SQL and biz logic in sprocs

:stonk:

Adbot
ADBOT LOVES YOU

revmoo
May 25, 2006

#basta
Just remembered an old coding horror, complements of a colleague. He got a ticket to add the current time, with seconds, to a page in an app. So he wrote js/php to query the server every second and get the current time. Nobody ever noticed until I happened to be looking at the code for the page in question months later.

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