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
Remulak
Jun 8, 2001
I can't count to four.
Yams Fan

Kazinsal posted:

Enums for complicated finite state machines tend to get real messy real quick.

Adbot
ADBOT LOVES YOU

Soricidus
Oct 21, 2010
freedom-hating statist shill

Surprise T Rex posted:

Are Java enums sort of like Union types? From a C# perspective they’re confusing since in C# it’s just a strongly typed list of name-to-Integer mappings.

They’re sugar for collections of singletons with special compiler support to let you use them in switch statements, and special support classes like EnumSet and EnumMap that take advantage of the compiler-generated ordinal() method to use them as efficiently as integers in other common situations.

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe
motherfucker,

Only registered members can see post attachments!

Volmarias
Dec 31, 2002

EMAIL... THE INTERNET... SEARCH ENGINES...

Hammerite posted:

motherfucker,



Not an email address.

Yes I know

RPATDO_LAMD
Mar 22, 2013

🐘🪠🍆

Hammerite posted:

motherfucker,



your login name is not necessarily the same as your publicly visible steam account name
and if like me you only used steam on one pc and had it set to auto sign in you might have not actually seen that login name for years

e: wait this is the coding horrors thread not the steam thread

2Fast2Nutricious
Oct 4, 2020

Hammerite posted:

motherfucker,



Phone numbers can only be digits, spaces, parentheses, and a plus sign. Hope this helps. :) [WONTFIX]

Carbon dioxide
Oct 9, 2012

https://www.youtube.com/watch?v=t863QfAOmlY

JawnV6
Jul 4, 2004

So hot ...

Beef posted:

I went into a video call expecting a tabs vs spaces discussion when I raised the issue of the baffling seemingly random C code style on a project I'm working on. Sometimes there would be a space between the function name and arglist, sometimes where wouldn't. There are occasional superfluous space after an open brace, which my emacs setups paints in angry red, that I would have to sweep up using whitespace-cleanup before commits.


It turned out every extra space has it's purpose and it is beautiful.

`foo ()` vs `foo()` allows grep to distinguish between definitions and call sites.

The superfluous space is a marker for a codegen tool that inserts markers for code coverage testing using gcov.

I used to maintain perl written by EE's. EE's generally have funny ideas about software, will get things working once then move on to other problems. This was perl that smashed ASCII together into SQL queries, so just the best possible environment for clever solutions to persist for years.

A couple of the genius inventions that I had to deal with included
code:
$AND = "AND"
$OR  = "OR "
Thinking it was superfluous, I removed the extra space from $OR. Turns out it was load bearing, as it bashed strings together to make a SQL query it would get to the end and chop; chop; chop; to remove the "extra" operator, without the " " it would whack a ")" and imbalance things.

The other incredible move was redefining $\, the newline character, from '\n' to '' so it could slurp a whole file and do one s/// operation instead of "looping" over "lines" like some uncourageous jerk.

Kazinsal
Dec 13, 2011

JawnV6 posted:

The other incredible move was redefining $\, the newline character, from '\n' to '' so it could slurp a whole file and do one s/// operation instead of "looping" over "lines" like some uncourageous jerk.

Okay, that's worth some electroshock therapy on whoever did that.

more falafel please
Feb 26, 2005

forums poster

the horrors of perl can be summed up by

JawnV6 posted:

redefining $\, the newline character,

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

Look, bash programmers overwrite $IFS all the time so what’s the big deal???

Bruegels Fuckbooks
Sep 14, 2004

Now, listen - I know the two of you are very different from each other in a lot of ways, but you have to understand that as far as Grandpa's concerned, you're both pieces of shit! Yeah. I can prove it mathematically.

JawnV6 posted:

I used to maintain perl written by EE's. EE's generally have funny ideas about software, will get things working once then move on to other problems. This was perl that smashed ASCII together into SQL queries, so just the best possible environment for clever solutions to persist for years.

A couple of the genius inventions that I had to deal with included
code:
$AND = "AND"
$OR  = "OR "
Thinking it was superfluous, I removed the extra space from $OR. Turns out it was load bearing, as it bashed strings together to make a SQL query it would get to the end and chop; chop; chop; to remove the "extra" operator, without the " " it would whack a ")" and imbalance things.

The other incredible move was redefining $\, the newline character, from '\n' to '' so it could slurp a whole file and do one s/// operation instead of "looping" over "lines" like some uncourageous jerk.

when maintaining feral perl you need to act as if it has a long term nuclear waste message around it, e.g.

quote:

This place is a message... and part of a system of messages... pay attention to it!
Sending this message was important to us. We considered ourselves to be a powerful culture.
This place is not a place of honor... no highly esteemed deed is commemorated here... nothing valued is here.
What is here was dangerous and repulsive to us. This message is a warning about danger.

Son of Thunderbeast
Sep 21, 2002

turning theoretically everything into a single-line expression was :kiss:

lifg
Dec 4, 2000
<this tag left blank>
Muldoon

JawnV6 posted:

The other incredible move was redefining $\, the newline character, from '\n' to '' so it could slurp a whole file and do one s/// operation instead of "looping" over "lines" like some uncourageous jerk.

I do that all the time, it’s a great trick, but only in one-liners for some quick data wrangling that I’ve hopeful never committed.

But if you’re working in the Boston area: my bad.

JawnV6
Jul 4, 2004

So hot ...
Hahahahaha "committed" lmao, sure right okay.

let me direct you back to the intro:

JawnV6 posted:

I used to maintain perl written by EE's

"commit" wasn't in the vocabulary back there, this landed in my email as a .zip file

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

Dijkstracula posted:

Look, bash programmers overwrite $IFS all the time so what’s the big deal???

Not me :smug:

because apple ripped bash out of macos a version or two ago :(

more falafel please
Feb 26, 2005

forums poster

I was a teenage perl kid, and now my null checks are if (ptr == nullptr) because it makes my meaning explicit and adds some amount of typesafety

honestly I can't imagine working in a dynamically typed language for a living. I barely trust my code after it's compiled, letting the compiler yell at me about my many shortcomings is the right move

LOOK I AM A TURTLE
May 22, 2003

"I'm actually a tortoise."
Grimey Drawer

more falafel please posted:

I was a teenage perl kid, and now my null checks are if (ptr == nullptr) because it makes my meaning explicit and adds some amount of typesafety

Cause I'm just a teenage perl kid baby

lifg
Dec 4, 2000
<this tag left blank>
Muldoon
At my last Perl job the company had developed some functions to do runtime type checking.

Zopotantor
Feb 24, 2013

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

Bruegels Fuckbooks posted:

when maintaining feral perl you need to act as if it has a long term nuclear waste message around it, e.g.

I personally prefer the inscription on the Gates of Hell from the Inferno.

quote:

Per me si va ne la città dolente,
per me si va ne l'etterno dolore,
per me si va tra la perduta gente.

Lasciate ogne speranza, voi ch'intrate.

Polio Vax Scene
Apr 5, 2009



The new I-9 form has a new checkbox and its options are "Off" for unchecked and "Yes" for checked.

Foxfire_
Nov 8, 2010

It's like they didn't even consider that the checkbox might be FileNotFound at all

Macichne Leainig
Jul 26, 2012

by VG
Everyone's favorite, the n+1 possible states checkbox

rarbatrol
Apr 17, 2011

Hurt//maim//kill.

Foxfire_ posted:

It's like they didn't even consider that the checkbox might be FileNotFound at all

You know, it's funny... at work I ended up refactoring our internal permission check result into (roughly) yes, no, and "you are not allowed to know this exists". 404 Not Found. That's me.

Carbon dioxide
Oct 9, 2012

Macichne Leainig posted:

Everyone's favorite, the n+1 possible states checkbox

The "checkboxes" in the Microsoft Office Installer... or at least that's what they were when I last installed Office, 3000 years ago.

For each item you can toggle between install, do not install, and install on first use. And if you fold out the the more detailed stuff, a fourth option can be chosen, that means "partially selected".

Jabor
Jul 16, 2010

#1 Loser at SpaceChem
i was recently dealing with a ui that had essentially four possible states, but represented them with a two-state toggle control and no other way to disambiguate which state you were in

lifg
Dec 4, 2000
<this tag left blank>
Muldoon
So many booleans evolve into an enum. Like when a nice and simple ReadOnly/Writable boolean becomes a ReadOnly/Writable/WriteOnce.

leper khan
Dec 28, 2010
Honest to god thinks Half Life 2 is a bad game. But at least he likes Monster Hunter.

lifg posted:

So many booleans evolve into an enum. Like when a nice and simple ReadOnly/Writable boolean becomes a ReadOnly/Writable/WriteOnce.

Good thing they're both already the same type.

Macichne Leainig
Jul 26, 2012

by VG

leper khan posted:

Good thing they're both already the same type.

Except in this one hardcoded instance that’s not going to be touched for 6 months, well after you’ve forgotten about the work.

raminasi
Jan 25, 2005

a last drink with no ice

Foxfire_ posted:

It's like they didn't even consider that the checkbox might be FileNotFound at all

rarbatrol posted:

You know, it's funny... at work I ended up refactoring our internal permission check result into (roughly) yes, no, and "you are not allowed to know this exists". 404 Not Found. That's me.

I am currently working on a project to add a third return state to an existing workflow that previously only returned "true" or "false." The new state is "we don't know because the remote service didn't respond or responded unintelligibly." True/False/FileNotFound is the only cited reference in the design doc.

Polio Vax Scene
Apr 5, 2009



Eagerly awaiting the day where all computer logic switches from binary to analog and checkboxes have any value between "unchecked" and "checked" represented by how transparent the checkmark is

ynohtna
Feb 16, 2007

backwoods compatible
Illegal Hen
Touch fuzzy logic, get dizzy data.

darthbob88
Oct 13, 2011

YOSPOS
https://github.com/TodePond/C

quote:

Arrays
Some languages start arrays at 0, which can be unintuitive for beginners. Some languages start arrays at 1, which isn't representative of how the code actually works. C does the best of both worlds: Arrays start at -1.
code:

const const scores = [3, 2, 5]!
print(scores[-1])! //3
print(scores[0])!  //2
print(scores[1])!  //5

quote:

Indents
When it comes to indentation, C strikes a happy medium that can be enjoyed by everyone: All indents must be 3 spaces long.
code:

function main() => {
   print("C is the future")!
}
-3 spaces is also allowed.

   function main() => {
print("C is the future")!
   }

quote:

String Interpolation
Please remember to use your regional currency when interpolating strings.
code:

const const name = "world"!
print("Hello ${name}!")!
print("Hello &#163;{name}!")!
print("Hello &#165;{name}!")!
And make sure to follow your local typographical norms.
code:

print("Hello {name}&#8364;!")!
The symbol for the Cape Verdean escudo is placed in the decimal separator position, as in 2$50. Developers from the Republic of Cape Verde can benefit from this syntax:
code:

addEventListener("keydown", e => print(`You've pressed: {e$code}`))!

QuarkJets
Sep 8, 2008

I liked this

quote:

Mutable data is an anti-pattern. Use the const const const keyword to make a constant constant constant. Its value will become constant and immutable, and will never change. Please be careful with this keyword, as it is very powerful, and will affect all users globally forever.

const const const pi = 3.14!

Also this

quote:

Both variables and constants can be named with any Unicode character or string.

This includes numbers, and other language constructs.

const const 5 = 4!
print(2 + 2 === 5)! //true

QuarkJets
Sep 8, 2008

The project has a LICENSE.md with this at the top

LICENSE.md posted:

Congratulations! You found the hidden examples page!

NihilCredo
Jun 6, 2011

iram omni possibili modo preme:
plus una illa te diffamabit, quam multæ virtutes commendabunt

This is goddamn brilliant.


quote:

To declare a function, you can use any letters from the word function (as long as they're in order):

code:

function add (a, b) => a + b!
func multiply (a, b) => a * b!
fun subtract (a, b) => a - b!
fn divide (a, b) => a / b!
functi power (a, b) => a ** b!
union inverse (a) => 1/a!


quote:

You can make classes, but you can only ever make one instance of them. This shouldn't affect how most object-oriented programmers work.

code:

class Player {
    const var health = 10! 
}

const var player1 = new Player()!
const var player2 = new Player()! //Error: Can't have more than one 'Player' instance!

This is how you could do this:

code:

class PlayerMaker {
   function makePlayer() => {
      class Player {
         const var health = 10!
      }
      const const player = new Player()!
      return player!
   }
}

const const playerMaker = new PlayerMaker()!
const var player1 = playerMaker.makePlayer()!
const var player2 = playerMaker.makePlayer()!

quote:

To avoid confusion, the delete statement only works with primitive values like numbers, strings, and booleans.

code:

delete 3!
print(2 + 1)! // Error: 3 has been deleted

C is a multi-paradigm programming language, which means that you can delete the keywords and paradigms you don't like.

code:

delete class!
class Player {} // Error: class was deleted

When perfection is achieved and there is nothing left to delete, you can do this:

code:

delete delete!

Volmarias
Dec 31, 2002

EMAIL... THE INTERNET... SEARCH ENGINES...

quote:

You can make classes, but you can only ever make one instance of them. This shouldn't affect how most object-oriented programmers work.

:hmmyes:

quote:

When perfection is achieved and there is nothing left to delete, you can do this:


code:

delete delete!

:perfect:

nullfunction
Jan 24, 2005

Nap Ghost
Coding Horrors: Booleans are stored as one-and-a-half bits.

Xerophyte
Mar 17, 2008

This space intentionally left blank
I just got to how the compiler is implemented and, yeah, that checks out. 99% certain someone is working on a paper on that very compiler architecture, if it's not already published.

Adbot
ADBOT LOVES YOU

Volmarias
Dec 31, 2002

EMAIL... THE INTERNET... SEARCH ENGINES...

quote:

C has a built-in garbage collector that will automatically clean up unused variables. However, if you want to be extra careful, you can specify a lifetime for a variable, with a variety of units.


code:

const const name<2> = "Luke"! //lasts for two lines
const const name<20s> = "Luke"! //lasts for 20 seconds

By default, a variable will last until the end of the program. But you can make it last in between program-runs by specifying a longer lifetime.


code:

const const name<Infinity> = "Luke"! //lasts forever

Variable hoisting can be achieved with this neat trick. Specify a negative lifetime to make a variable exist before its creation, and disappear after its creation.


code:

print(name)! //Luke
const const name<-1> = "Luke"!

:stwoon:

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