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
Internet Janitor
May 17, 2008

"That isn't the appropriate trash receptacle."
i am constantly amazed at how terrible the c standard library is. nearly every function it provides is dangerous, unusably broken, obviously incomplete, riddled with subtle undefined behavior, or some absurd combination of the above

Adbot
ADBOT LOVES YOU

Sapozhnik
Jan 2, 2005

Nap Ghost

Xarn posted:

C++ is garbage

Xarn
Jun 26, 2015

Internet Janitor posted:

i am constantly amazed at how terrible the c standard library is. nearly every function it provides is dangerous, unusably broken, obviously incomplete, riddled with subtle undefined behavior, or some absurd combination of the above

You forgot slow :v:

The_Franz
Aug 8, 2003

Internet Janitor posted:

i am constantly amazed at how terrible the c standard library is. nearly every function it provides is dangerous, unusably broken, obviously incomplete, riddled with subtle undefined behavior, or some absurd combination of the above

so time travel back to the 70s and do something about it. yes, the c standard library wasn't officially made a standard until the 80s, but much of the work it incorporated goes back to the dawn of unix and c

gonadic io
Feb 16, 2011

>>=
how to choose a language: first, time travel back to the 70s

Xarn
Jun 26, 2015
Unironically yes, so that you can change the language the project has been started in :v:

gonadic io
Feb 16, 2011

>>=

somebody learning python as a first lang posted:

is there a reason to use # comment instead of ''' comment '''
do these do different things
hmm that seems odd syntax I say to myself, I should look it up

quote:

Or, not quite as intended, you can use a multiline string.

Since Python will ignore string literals that are not assigned to a variable, you can add a multiline string (triple quotes) in your code, and place your comment inside it:
lmao

cinci zoo sniper
Mar 15, 2013




gonadic io posted:

hmm that seems odd syntax I say to myself, I should look it up

lmao

# should be used for comments, string literals are typically reserved for documentation strings - they’ll automatically show up if someone does help(foo.Bar) on your library

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe
lol what, they actually standardized using ignored multiline string literals as doc comments

prisoner of waffles
May 8, 2007

Ah! well a-day! what evil looks
Had I from old and young!
Instead of the cross, the fishmech
About my neck was hung.

rjmccall posted:

lol what, they actually standardized using ignored multiline string literals as doc comments

yes, so-called docstrings were standardized a long time ago

python has a lot of accreted history

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.
docstrings are only immediately after a function declaration, right? string literals after anything else are just ignored string literals

also they don't have to be multiline iirc

cinci zoo sniper
Mar 15, 2013




pokeyman posted:

docstrings are only immediately after a function declaration, right? string literals after anything else are just ignored string literals

also they don't have to be multiline iirc

yes, though also in other contexts e.g. class definitions or module start

and yes, triple quotes are the special case multi line syntax

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.
right forgot class definition. didn't know about module start, that's handy

cinci zoo sniper
Mar 15, 2013




the real cursed poo poo is package docstrings, which is the module docstring of root-level __init__.py

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.
lol what

at that point maybe just bless having a readme.rst

dougdrums
Feb 25, 2005
CLIENT REQUESTED ELECTRONIC FUNDING RECEIPT (FUNDS NOW)
my favorite thing about python syntax lately is that
code:
@lambda f: f
def func():
  pass
is valid

dougdrums
Feb 25, 2005
CLIENT REQUESTED ELECTRONIC FUNDING RECEIPT (FUNDS NOW)
which was so gtk (iirc) could do
code:
@foo[“bar”]
def baz():
  …

cinci zoo sniper
Mar 15, 2013




pokeyman posted:

lol what

at that point maybe just bless having a readme.rst

https://www.python.org/dev/peps/pep-0257/#what-is-a-docstring pep-257 to the “rescue”

quote:

A package may be documented in the module docstring of the __init__.py file in the package directory.

Athas
Aug 6, 2007

fuck that joker

Internet Janitor posted:

i am constantly amazed at how terrible the c standard library is. nearly every function it provides is dangerous, unusably broken, obviously incomplete, riddled with subtle undefined behavior, or some absurd combination of the above

I recently was confused at why 'pow(x,2)' was much slower than 'x*x'. Well, not confused at the performance difference ('pow' is a libm call), but that the C compiler wouldn't optimise the former to the latter even under -O3. Eventually I realised that all the math functions can set loving errno, so they have side effects. Now I need to look into whether -fno-math-errno is enough to fix this. (Or the comedy option -ffast-math which implies -fno-math-errno.)

Joe Chip
Jan 4, 2014
.

Joe Chip fucked around with this message at 00:15 on Nov 19, 2021

repiv
Aug 13, 2009

Athas posted:

I recently was confused at why 'pow(x,2)' was much slower than 'x*x'. Well, not confused at the performance difference ('pow' is a libm call), but that the C compiler wouldn't optimise the former to the latter even under -O3. Eventually I realised that all the math functions can set loving errno, so they have side effects. Now I need to look into whether -fno-math-errno is enough to fix this. (Or the comedy option -ffast-math which implies -fno-math-errno.)

i can't reproduce that, both gcc and clang flatten pow(x, 2) to a single instruction without any special flags

https://godbolt.org/z/xd4Gr7TEb

animist
Aug 28, 2018

dougdrums posted:

my favorite thing about python syntax lately is that
code:
@lambda f: f
def func():
  pass
is valid

that's amazing. wait, can you use an arbitrary expression as a decorator?

Sweeper
Nov 29, 2007
The Joe Buck of Posting
Dinosaur Gum

animist posted:

that's amazing. wait, can you use an arbitrary expression as a decorator?

I think it’s because the lambda is a function and a decorator applies a function to a function, it’s just anonymous in this case

cinci zoo sniper
Mar 15, 2013




yeah, functions are first class, and the pie (don’t ask) syntax is just syntactic sugar to avoid doing foo_decorator(foo()) every time you call foo. lambdas in decorator is imo a crazy code smell, but there’s no reason for that to not work

prisoner of waffles
May 8, 2007

Ah! well a-day! what evil looks
Had I from old and young!
Instead of the cross, the fishmech
About my neck was hung.

cinci zoo sniper posted:

the pie (don’t ask)

I’m asking

e: found it. PEPs are useful for historical research I guess

quote:

Barry Warsaw named this the 'pie-decorator' syntax, in honor of the Pie-thon Parrot shootout which occurred around the same time as the decorator syntax, and because the @ looks a little like a pie. Guido outlined his case [8] on Python-dev, including this piece [9] on some of the (many) rejected forms.

cinci zoo sniper posted:

lambdas in decorator is imo a crazy code smell, but there’s no reason for that to not work

agreed on both points

prisoner of waffles fucked around with this message at 05:22 on Nov 14, 2021

redleader
Aug 18, 2005

Engage according to operational parameters

rjmccall posted:

lol what, they actually standardized using ignored multiline string literals as doc comments

'use strict'

b0lt
Apr 29, 2005

repiv posted:

i can't reproduce that, both gcc and clang flatten pow(x, 2) to a single instruction without any special flags

https://godbolt.org/z/xd4Gr7TEb

that's because pow(x, 2) cannot set errno. try with a negative or non-integral exponent (which will set errno for zero and a negative x respectively)

mystes
May 31, 2006

b0lt posted:

that's because pow(x, 2) cannot set errno. try with a negative or non-integral exponent (which will set errno for zero and a negative x respectively)
The original post was also about pow(x,2) though?

gonadic io
Feb 16, 2011

>>=
https://twitter.com/m_ou_se/status/1459856266440941574?s=20

dougdrums
Feb 25, 2005
CLIENT REQUESTED ELECTRONIC FUNDING RECEIPT (FUNDS NOW)

animist posted:

that's amazing. wait, can you use an arbitrary expression as a decorator?
yup
code:
decorator ::= "@" assignment_expression NEWLINE
of course if it’s not callable it will raise an exception at runtime

https://www.python.org/dev/peps/pep-0614/

dougdrums fucked around with this message at 15:04 on Nov 14, 2021

mystes
May 31, 2006

Cool, but also, gross.

dougdrums
Feb 25, 2005
CLIENT REQUESTED ELECTRONIC FUNDING RECEIPT (FUNDS NOW)

dougdrums posted:

yup
code:
decorator ::= "@" assignment_expression NEWLINE
i guess now that i think of it, you might be able to do something like
code:
@func := lambda f: f(f)
def func():
  pass
or something sillier, but i haven’t tried it

dougdrums fucked around with this message at 15:21 on Nov 14, 2021

dougdrums
Feb 25, 2005
CLIENT REQUESTED ELECTRONIC FUNDING RECEIPT (FUNDS NOW)
also I got qt mixed up with gtk lol

prisoner of waffles
May 8, 2007

Ah! well a-day! what evil looks
Had I from old and young!
Instead of the cross, the fishmech
About my neck was hung.

redleader posted:

'use strict'

dunking on javascript in the PL thread is easier than shooting ducks in a barrel

cinci zoo sniper
Mar 15, 2013





im going to very slowly poop in keyboards of every person involved in making this happen

mystes
May 31, 2006

prisoner of waffles posted:

dunking on javascript in the PL thread is easier than shooting ducks in a barrel
Have you tried to get the ducks into the barrel?

gonadic io
Feb 16, 2011

>>=

cinci zoo sniper posted:

im going to very slowly poop in keyboards of every person involved in making this happen

mara does some pretty great rust shitposts
https://twitter.com/m_ou_se/status/1368632701448818691

cinci zoo sniper
Mar 15, 2013





ah, respect then. unfortunately some people unironically enjoy using matplotlib

prisoner of waffles
May 8, 2007

Ah! well a-day! what evil looks
Had I from old and young!
Instead of the cross, the fishmech
About my neck was hung.

mystes posted:

Have you tried to get the ducks into the barrel?

easier than getting a good create-react-app config

Adbot
ADBOT LOVES YOU

dougdrums
Feb 25, 2005
CLIENT REQUESTED ELECTRONIC FUNDING RECEIPT (FUNDS NOW)

prisoner of waffles posted:

e: found it. PEPs are useful for historical research I guess
that just raises more questions

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