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
Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

The Gripper posted:

The worst is with concurrency frameworks and the like, where the most promising looking example is almost always some complex mathematical computation which probably looks clean and makes a lot of sense to someone that knows that particular math, but to anyone else it's difficult to separate "here's the code I need to use to implement this for my own use" from the "holy god m=p*x ^ 7; _,x=sub1(-y^(x)^add1(m));" part.

I know it's good to have examples that actually do something real and the developers probably have a strong math background, but giving me something like that when I don't even know which parts are the framework and which parts are the payload isn't all that productive.

I find this general thing to happen with the documentation on an un-trivial number of libraries. That is, illustrating usage of the library with examples that seem too domain-specific or outside of the knowledge base of a significant portion of their users. I can understand why this happens, and that sometimes it's the best illustration, but I don't like it!

Adbot
ADBOT LOVES YOU

Funking Giblet
Jun 28, 2004

Jiglightful!

pokeyman posted:

Well optional parameters aren't the same as parameter defaults, though in C# I understand you can't do one without doing the other.

That said, what are the caveats when using optional parameters in C#?

Visual Studio will allow a project set to v3.5 to compile optional / default parameters, but MSBuild will not. Trigger lots of "Works on my machine?" when the CI build fails.

The Gripper
Sep 14, 2004
i am winner

Funking Giblet posted:

Visual Studio will allow a project set to v3.5 to compile optional / default parameters, but MSBuild will not. Trigger lots of "Works on my machine?" when the CI build fails.
There's a ton of things in .NET that do that, I think even the newer async/await features can be compiled to target earlier .NET CLR because there's nothing special about the generated IL. It's caused grief with us as well because it's not uncommon to have a project that specifies .NET 4.0 or 3.5, runs fine on both, but can only be compiled with a > 4.0 setup.

Jabor
Jul 16, 2010

#1 Loser at SpaceChem

pokeyman posted:

Well optional parameters aren't the same as parameter defaults, though in C# I understand you can't do one without doing the other.

Well, you can use the OptionalAttribute to flag something as optional without providing a default value.

In that case the "default value" is implicitly specified as either Type.Missing, or default(T).

Dicky B
Mar 23, 2004

Does this count as a coding horror?
http://www.youtube.com/watch?v=xF0-LGoXtaw

Internet Janitor
May 17, 2008

"That isn't the appropriate trash receptacle."
You'd think that fans of a language with legendarily glacial compile times wouldn't include a phrase like "we'll keep compiling till the end" in their song.

PrBacterio
Jul 19, 2000

Dicky B posted:

Does this count as a coding horror?
http://www.youtube.com/watch?v=xF0-LGoXtaw
counterpoint: http://www.youtube.com/watch?v=5-OjTPj7K54
that is how you do something like that right

Beef
Jul 26, 2004

Internet Janitor posted:

You'd think that fans of a language with legendarily glacial compile times wouldn't include a phrase like "we'll keep compiling till the end" in their song.

I make heavy use of an Intel API which internally heavily uses templates.

6.5 hours compile time for a single object file. Average memory use, 13GB

Zombywuf
Mar 29, 2008

Beef posted:

I make heavy use of an Intel API which internally heavily uses templates.

6.5 hours compile time for a single object file. Average memory use, 13GB

Use more pimpls.

CHRISTS FOR SALE
Jan 14, 2005

"fuck you and die"
So I'm working on this Rails app today (that someone else made) and I come across this little treat. Be forewarned that I found this at the bottom of model. In a gem. That's required by the Rails app.

code:
class NullObject
  def method_missing(*args, &block)
    self
  end

  def nil?; true; end
end
What this lovely little class actually does is quite lovely. It is a replacement for nilClass, in which NullObject.nil? returns true. But the major WTF comes from the fact that it only mocks one part of what nilClass actually does. Such a class could actually have a value like "value", but when .nil? is called on it, it will still return `true`. So in essence, this class pretends to be nil, but actually isn't. It also overrides method_missing to return a reference to itself for any method call made on the object.

The fact that the guy who had my job before me could even fathom such a confusing and lovely way to code is ludicrous to me. May God have mercy on the souls of his current and future team members...

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.
Call the gem 'andandfuckyou'

hobbesmaster
Jan 28, 2008

ToxicFrog posted:

I can't help but feel that a lot of code like this would be more readable if the mathparts could be written in - and rendered properly by the editor as - LaTeX.

Doxygen supports LaTeX... code with LaTeX equations and citations in comments is weird.

ToxicFrog
Apr 26, 2008


hobbesmaster posted:

Doxygen supports LaTeX... code with LaTeX equations and citations in comments is weird.

I was actually thinking something more like: you open it in your IDE of choice and rather than a clusterfuck of calls into the math library, you see beautifully formatted LaTeX equations in the code itself, which the compiler translates into the appropriate calls into the math library.

Deus Rex
Mar 5, 2005

essentially:

php:
<?
class Bar {
    public function __construct(...) { // typical constructor... }
}

class Foo {
    public function __construct(...) {
        // ..
        return new Bar(...);
    }
}
?>
:wtc:

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
Does that actually do what it appears to be trying to do?

If it does I'm torn between being horrified and being amused at how it sort of solves one of the sort of problems with new.

Haystack
Jan 23, 2005





PHP apparently just ignores the constructor's return value. Which, I suppose, is more sane than the alternative. Ideally it would throw an error, but then again it's PHP.

Proof

Doc Hawkins
Jun 15, 2010

Dashing? But I'm not even moving!


CHRISTS FOR SALE posted:

code:
class NullObject
  def method_missing(*args, &block)
    self
  end

  def nil?; true; end
end

I've never read it, but Avdi Grimm makes the case for this in Exceptional Ruby, and also on his blog.

quote:

Very often in Ruby code, we would like to execute some action only if an object is present:
code:
def slug(title)
  if title
    title.strip.downcase.tr_s('^[a-z0-9]', '-')
  end
end
What we are really checking for is the presence of either a “falsy” object (nil or false, most likely nil), or a “truthy” object (anything other than nil or false). So in effect this is an instance of typecasing.

Switching on object type is a smell in object-oriented languages. In general, we don’t want to ask an object what it is; we want to tell it what to do and let it figure out the best way to do it based on its type. This is the essence of polymorphism.

What we need is an object to represent the special case of “do nothing on missing value”. As it happens, there is a pattern for that: Null Object. Quoting Wikipedia: “a Null Object is an object with defined neutral (‘null’) behavior”.

He then goes on to explain how returning self makes it very easy to silently nullify method chains. He goes on even further after that.

Zhentar
Sep 28, 2003

Brilliant Master Genius
Objective-C works like that. It's easily one of my favorite features of the language.

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
At some level, the problem is with the of the concept of a NULL pointer, even with stricter type systems such as Java, in that it's the only value which is allowed to lie about its interface.

In that case of the "slug" example, if they created a URL from a slugified NullObject, they'd crash and burn anyway, as attempting to convert the NullObject to a string would just return another NullObject object, correct?

Opinion Haver
Apr 9, 2007

code:
Prelude Control.Applicative> ("prepend " ++ ) <$> Just "a string"
Just "prepend a string"
Prelude Control.Applicative> ("prepend " ++ ) <$> Nothing
Nothing
:colbert:

Look Around You
Jan 19, 2009

yaoi prophet posted:

code:
Prelude Control.Applicative> ("prepend " ++ ) <$> Just "a string"
Just "prepend a string"
Prelude Control.Applicative> ("prepend " ++ ) <$> Nothing
Nothing
:colbert:

Maybe monads legitimately rule.

Doc Hawkins
Jun 15, 2010

Dashing? But I'm not even moving!


Suspicious Dish posted:

In that case of the "slug" example, if they created a URL from a slugified NullObject, they'd crash and burn anyway, as attempting to convert the NullObject to a string would just return another NullObject object, correct?

The twist ending of the blog post I linked is that the whole thing isn't really useful.

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.

yaoi prophet posted:

code:
Prelude Control.Applicative> ("prepend " ++ ) <$> Just "a string"
Just "prepend a string"
Prelude Control.Applicative> ("prepend " ++ ) <$> Nothing
Nothing
:colbert:

I'm glad someone posted this. Monads rule.

SavageMessiah
Jan 28, 2009

Emotionally drained and spookified

Toilet Rascal

CHRISTS FOR SALE posted:

So I'm working on this Rails app today (that someone else made) and I come across this little treat. Be forewarned that I found this at the bottom of model. In a gem. That's required by the Rails app.

code:
class NullObject
  def method_missing(*args, &block)
    self
  end

  def nil?; true; end
end
What this lovely little class actually does is quite lovely. It is a replacement for nilClass, in which NullObject.nil? returns true. But the major WTF comes from the fact that it only mocks one part of what nilClass actually does. Such a class could actually have a value like "value", but when .nil? is called on it, it will still return `true`. So in essence, this class pretends to be nil, but actually isn't. It also overrides method_missing to return a reference to itself for any method call made on the object.

The fact that the guy who had my job before me could even fathom such a confusing and lovely way to code is ludicrous to me. May God have mercy on the souls of his current and future team members...

I've actually written something pretty similar:
code:
class Magic
  def method_missing(meth, *args, &block)
    self
  end
end
but in my defense it was to make it easier to do some analysis of an embedded dsl. Basically I mocked the top level methods that implemented it to record some info and then return this, which nop-ed the rest of the method chains. It's an awful hack, but it sure did work! (and made me laugh/cry)

Atimo
Feb 21, 2007
Lurking since '03
Fun Shoe
There's a certain database driver I have to use that has two wonderful features:

    If the database server itself becomes unavailable after you open a connection your query will throw an access violation, forcing you to catch base exception around the calls.

    Text fields treated as integers are silently converted for you - until the value is null. Then it crashes your production server, requiring a reboot.

A A 2 3 5 8 K
Nov 24, 2003
Illiteracy... what does that word even mean?

Atimo posted:

Text fields treated as integers are silently converted for you - until the value is null. Then it crashes your production server, requiring a reboot.

Let the punishment fit the crime.

Vanadium
Jan 8, 2005

Look Around You posted:

Maybe monads legitimately rule.

TRex EaterofCars posted:

I'm glad someone posted this. Monads rule.

It's the Functor method, don't need no monads. :colbert:

floWenoL
Oct 23, 2002

From Die EmacsWiki, Die!:

quote:

Some of the features of the wiki are simply abhorring - like the lack of user access control; anyone can enter any user name and edit the wiki… Yep, this is not a joke…

...

As crazy as it seems a lot of people are using the wiki as a software distribution mechanism. Instead of hosting their projects in version control (say GitHub) they develop stuff locally, upload them to the wiki and say that this is the canonical way to obtain their software. Needless to say - this is a horrible, horrible practice. I’ve often encountered on the wiki source files authored by someone, then edited by 10 different guys, that have a tendency to add their names to the copyrights sections instead of thinking how their poor users will understand what exactly was changed in these files. Sometimes the authors themselves are to blame (for being loving lazy), but often someone just copies a snapshot of a project from version control and uploads it to the wiki, creating problems of epic proportions for the maintainers, who start receiving bugs about stuff they never developed in the first place.

...

Tools like audo-install (an extension that supports installing software from EmacsWiki) should never have existed. el-get should not have added support for the installation of stuff from the wiki. As long as such practices are tolerated they will not stop.

Today I learned I can backdoor Emacs users just by editing an unauthenticated Wiki!

Jonnty
Aug 2, 2007

The enemy has become a flaming star!

floWenoL posted:

From Die EmacsWiki, Die!:


Today I learned I can backdoor Emacs users just by editing an unauthenticated Wiki!

I understand what they mean but I enjoy the idea of anyone being able to edit a wiki being "abhorrent."

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.

Vanadium posted:

It's the Functor method, don't need no monads. :colbert:

I will defer to those who know better but isn't the Maybe monad what's doing all the magic there?

ShoulderDaemon
Oct 9, 2003
support goon fund
Taco Defender

TRex EaterofCars posted:

I will defer to those who know better but isn't the Maybe monad what's doing all the magic there?

The Maybe type is indeed what is in play there, but the fact that Maybe happens to be a Monad isn't relevant. The instance of Functor for Maybe (a much simpler categorical structure) is all that's required for that code.

wwb
Aug 17, 2004

I found appmodel.m today. It took a long while to find appmodel.m; but when I did, I understood. You see, appmdel.m is where I found the entire logic for the application. In terms of that whole branching logic thing. About 57/58kb of non-xcode generated, non third-party source code weight. Thank god the app is pretty. And it technically does work.

But for the live of christ can some one walk these graphic designers cum iOS devs through sepa-loving-rations of concerns.

ToxicFrog
Apr 26, 2008


Jonnty posted:

I understand what they mean but I enjoy the idea of anyone being able to edit a wiki being "abhorrent."

The problem isn't the "anyone can edit", it's the "anyone can edit any page while claiming to be any user, with no form of access control or authentication".

Even fully public wikis generally require one to create an account and associate your edits with that name by logging in.

Look Around You
Jan 19, 2009

ShoulderDaemon posted:

The Maybe type is indeed what is in play there, but the fact that Maybe happens to be a Monad isn't relevant. The instance of Functor for Maybe (a much simpler categorical structure) is all that's required for that code.

Yeah. You don't really need to use the monadic properties of Maybe in this instance (and <$> is infix for fmap of a Functor typeclass). A really, really awesome introduction to functors, applicative functors, monoids and monads (including what they are and the differences between them) is chapters 11-13 of Learn You A Haskell.

All Hat
Jul 11, 2008

He that is without int among you, let him first cast a long

ToxicFrog posted:

The problem isn't the "anyone can edit", it's the "anyone can edit any page while claiming to be any user, with no form of access control or authentication".

Even fully public wikis generally require one to create an account and associate your edits with that name by logging in.

Well, to be fair it is a Wiki for the GNU/RMS text editor.

RMS posted:

Ever since passwords first appeared at the MIT-AI lab I had come to the conclusion that to stand up for my belief, to follow my belief that there should be no passwords, I should always make sure to have a password that is as obvious as possible and I should tell everyone what it is. Because I don't believe that it's really desirable to have security on a computer, I shouldn't be willing to help uphold the security regime. On the systems that permit it I use the “empty password”, and on systems where that isn't allowed, or where that means you can't log in at all from other places, things like that, I use my login name as my password. It's about as obvious as you can get. And when people point out that this way people might be able to log in as me, i say “yes that's the idea, somebody might have a need to get some data from this machine. I want to make sure that they aren't screwed by security”.

Beef
Jul 26, 2004
Lucky for him, he doesn't connect to the internet often. He would need to change back his background from goatse every odd hour.

qntm
Jun 17, 2009
That's the stupidest thing I've ever heard a computer person say.

That, or that statement somehow predates the Fall of Man and the arrival of evil in the world.

All Hat
Jul 11, 2008

He that is without int among you, let him first cast a long

It's from 1986, http://www.gnu.org/philosophy/stallman-kth.html. I'm not sure if his view on security has changed in any way, but it's freedom all the way down.

Beef
Jul 26, 2004
It's also to be taken in the context of a hacker/research group, before the advent of decent network infrastucture.

Adbot
ADBOT LOVES YOU

Malloc Voidstar
May 7, 2007

Fuck the cowboys. Unf. Fuck em hard.

Beef posted:

It's also to be taken in the context of a hacker/research group, before the advent of decent network infrastucture.
Yeah but now that there is decent network infrastructure, Stallman reads websites using wget and email, so I'm not sure why you think his bizarre opinion on passwords would have changed.

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