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
biznatchio
Mar 31, 2001


Buglord

Dessert Rose posted:

Re: nullable values in C#:

code:
if (nullableBool.GetValueOrDefault(false)) { ...

That's an awfully verbose way of saying

code:
if (nullableBool ?? false) { ...

Adbot
ADBOT LOVES YOU

Crazy Mike
Sep 16, 2005

Now with 25% more kimchee.
We really want to load/reload our comboboxes.
code:
if (selectedStoredProcedure != "None") 
{
	// 50 lines to run whatever SPROC we picked
	Load_Reload_ComboBoxes("After Initialization");
}
else
{
	MessageBox.Show(" You have not selected a SPROC. ");
	Load_Reload_ComboBoxes("After Initialization");
}
ClearComboBoxes();
Load_Reload_ComboBoxes("After Initialization");

ShoulderDaemon
Oct 9, 2003
support goon fund
Taco Defender
Here's some code I just wrote that I'm ashamed of.

The idea is, I have a variadic template that I'm using in a few places. I need to write a function which takes as parameters a number of strings equal to the number of types I'm passing to this variadic template. As near as I can tell, expanding a parameter pack while ignoring its actual expansion is not trivial.

C++ code:
template<typename C, typename X>
struct Constant {
  typedef C type;
};

template<typename ...dataType>
void set_dataType_names(typename Constant<std::string const &, dataType>::type... name) {
  // In here I can use name, which is a parameter pack the same size as dataType,
  // but consists entirely of std::string references.
}

MrMoo
Sep 14, 2000

Munkeymon posted:

I know? I meant that because of someone's poor choice of reserved character, constructing a URI with an IP6 address that contains a zone identifier is now just that much more annoying because you have to remember to escape the % with %25 so now your Windows zone identifier looks even more like line noise: [url]http://fe80::abcd%251/:psyduck:[/url]

This doesn't make sense and the URL is invalid, for IPv6 you must wrap in square brackets:

http://[fe80::abcd%1]/

But then you'd be stupid to use link-local URLs as they're unique to each host, the use case is incredibly small to actually put one in a webpage.

Plorkyeran
Mar 22, 2007

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

ShoulderDaemon posted:

Here's some code I just wrote that I'm ashamed of.

The idea is, I have a variadic template that I'm using in a few places. I need to write a function which takes as parameters a number of strings equal to the number of types I'm passing to this variadic template. As near as I can tell, expanding a parameter pack while ignoring its actual expansion is not trivial.

C++ code:
template<typename C, typename X>
struct Constant {
  typedef C type;
};

template<typename ...dataType>
void set_dataType_names(typename Constant<std::string const &, dataType>::type... name) {
  // In here I can use name, which is a parameter pack the same size as dataType,
  // but consists entirely of std::string references.
}

Trivially better:
C++ code:
template<typename C, typename _> using Constant = C;

template<typename ...dataType>
void set_dataType_names(Constant<std::string const &, dataType>... name) {
  // In here I can use name, which is a parameter pack the same size as dataType,
  // but consists entirely of std::string references.
}
set_dataType_names is a pretty horrifying name.

ShoulderDaemon
Oct 9, 2003
support goon fund
Taco Defender

Plorkyeran posted:

Trivially better:
C++ code:
template<typename C, typename _> using Constant = C;

Thanks, my code is now less ugly!

Plorkyeran posted:

set_dataType_names is a pretty horrifying name.

The actual name in the code is newEventType, and it takes a few other parameters; I just wanted to make the usecase in the code sample somewhat more comprehensible.

Gul Banana
Nov 28, 2003

Smugdog Millionaire posted:

I don't see the problem with the way "nullable" value types were added. Do you have a preferred alternative implementation?

one which isn't restricted to value types
it's extremely irritating to not be able to have eg Nullable<System.Object>

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

Gul Banana posted:

one which isn't restricted to value types
it's extremely irritating to not be able to have eg Nullable<System.Object>

But that's pointless. System.Object is already nullable. System.Int32 is not.

PrBacterio
Jul 19, 2000

pokeyman posted:

But that's pointless. System.Object is already nullable. System.Int32 is not.

I don't know that it's necessarily pointless, a reference type is, at its core, in some way a (pointer) value type as well, after all, and so you might make the distinction of a valid (non-null) reference to a null object and a null reference value not referring to any object at all :razz:

In more seriousness though, it seems like a kind of pointless limitation, though. In, say, Caml there's nothing stopping you from making a foo option option value, for example. Is there a reason for the existence of this limitation?

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

PrBacterio posted:

I don't know that it's necessarily pointless, a reference type is, at its core, in some way a (pointer) value type as well, after all, and so you might make the distinction of a valid (non-null) reference to a null object and a null reference value not referring to any object at all :razz:

In more seriousness though, it seems like a kind of pointless limitation, though. In, say, Caml there's nothing stopping you from making a foo option option value, for example. Is there a reason for the existence of this limitation?

An unrestricted option type and banning nulls sounds awesome to me. But my impression of C# is that it's designed by people who wouldn't go halfway on that. Plus, I think Nullable joined the language in 2.0? So nulls already existed prior to Nullable, and they needed to make it work.

PrBacterio
Jul 19, 2000

pokeyman posted:

An unrestricted option type and banning nulls sounds awesome to me. But my impression of C# is that it's designed by people who wouldn't go halfway on that. Plus, I think Nullable joined the language in 2.0? So nulls already existed prior to Nullable, and they needed to make it work.
Only I wasn't even talking about banning nulls, there's no reason why you couldn't have an unrestricted option type even in the face of already existing null references is what I was trying to get at, and that they (apparently) explicitly put in this restriction therefore seems strange to me. Caml was only the first example that came to mind of a language with such an option type but you're right it's a bad example because it doesn't have null values to begin with.

Gul Banana
Nov 28, 2003

essentially I'd like to be able to write this
void DoSomething<T>(Nullable<T> optionalParameter)
{
if(optionalParameter.HasValue)
//etc
else
//etc, able to use .Value on this path

//or:
optionalParameter.someCombinator //such as GetOrElse, SelectMany..
}

no reason that couldn't be unified for ref and value types.

Macichne Leainig
Jul 26, 2012

by VG

biznatchio posted:

That's an awfully verbose way of saying

code:
if (nullableBool ?? false) { ...

I've actually never seen this, but thankfully I haven't dealt with too many nullables yet.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

PrBacterio posted:

Only I wasn't even talking about banning nulls, there's no reason why you couldn't have an unrestricted option type even in the face of already existing null references is what I was trying to get at, and that they (apparently) explicitly put in this restriction therefore seems strange to me.

Having read a bit about the design of C# and who designed it, it doesn't seem strange to me. That's all I'm trying to say :)

(And it was a lucky guess that Caml doesn't do nulls.)

Scaevolus
Apr 16, 2007

biznatchio posted:

That's an awfully verbose way of saying

code:
if (nullableBool ?? false) { ...
Are we still arguing about this?

Scaevolus posted:

"if (x ?? false)" more obviously indicates that you're dealing with a nullable type.

LOOK I AM A TURTLE
May 22, 2003

"I'm actually a tortoise."
Grimey Drawer
Eric Lippert, one of the designers of C#, has mentioned on many occasions that he regrets that Nullable<T> can only be applied to value types, as opposed to all types. He has also confirmed that the reason is basically that the features -- i.e. 1. Nullable types and 2. The distinction between reference types and value types -- entered the language in the wrong order. From a theoretical point of view the biggest problem is that it prevents the Nullable<T> type from being truly monadic, since you can't have a Nullable<Nullable<T>>. This series of posts touches on it: http://ericlippert.com/category/monads/

Simulated
Sep 28, 2001
Lowtax giveth, and Lowtax taketh away.
College Slice
On a slightly different note, I've said it before but when I first saw that a message to nil in Objective-C does nothing and returns zero I thought it was the dumbest thing ever. Now I realize that's the way all languages should work. 99.9% of the time when some reference is null, I just want to ignore it and/or skip that section of code. It is extremely rare that I want to throw an exception, assert, crash, etc.

Yet in most languages, I have to constantly litter my code with if (dicks != null) { dicks.butts(); }


If you aren't going to do that, then all references should be non-Nullable unless they are Nullable<T>. At least then I would know.

Rothon
Jan 4, 2012

Ender.uNF posted:

On a slightly different note, I've said it before but when I first saw that a message to nil in Objective-C does nothing and returns zero I thought it was the dumbest thing ever. Now I realize that's the way all languages should work. 99.9% of the time when some reference is null, I just want to ignore it and/or skip that section of code. It is extremely rare that I want to throw an exception, assert, crash, etc.

Yet in most languages, I have to constantly litter my code with if (dicks != null) { dicks.butts(); }


If you aren't going to do that, then all references should be non-Nullable unless they are Nullable<T>. At least then I would know.

The return value is only *usually* 0. If you call something that returns a struct by value that's larger than a register, the contents of it are undefined!

Dr Monkeysee
Oct 11, 2002

just a fox like a hundred thousand others
Nap Ghost
That behavior has occasionally bitten me in that my ObjC code merrily continues along without me realizing all those async operations I just fired off were no-ops because my connection was nil. I do agree that in general it makes for cleaner code though. There have been more times then not where I've realized I can remove some guard check because nil will just degrade to the right thing.

IT BEGINS
Jan 15, 2009

I don't know how to make analogies
php:
<?
while(strstr($field_value,"TABLE.")){
    $new_field_value = $new_field ="";
    $field_explode = explode(" ",$field_value);
    foreach($field_explode as $words){
        $new_field = trim($words);
        if(strstr($words,"TABLE.")){
            $new_field  = str_replace("TABLE.","",$new_field);
            $buffer_field = $new_field;
            $new_field = create_field($new_field,$variations,$library[$new_field],$level,$overwrite_table);
            //echo "field: $buffer_field-->$new_field<br>\n";
            if(strstr($new_field,"global_dynamic_vars") && isset($global_dynamic_vars[$buffer_field])) {
                $new_field  = "'".$global_dynamic_vars[$buffer_field]."'";
            }
            if(empty($new_field)) {
                $new_field = "DO NOT DISPLAY";
            }
        }
        if($testing++ > 100000) break;

        $new_field_value .= "$new_field ";
    }
    $field_value =$new_field_value;
}
?>

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



MrMoo posted:

This doesn't make sense and the URL is invalid, for IPv6 you must wrap in square brackets:

http://[fe80::abcd%1]/

But then you'd be stupid to use link-local URLs as they're unique to each host, the use case is incredibly small to actually put one in a webpage.

Huh, I hadn't seen that before, but I don't see anything in RFC 3986 that would allow for a zone identifier in an IP6 literal unless I'm reading the BNF wrong.

E: I guess the URI parser could jsut be written to assume that square brackets means it's an IP literal and therefore some other code's problem, but still.

Munkeymon fucked around with this message at 18:54 on Oct 10, 2013

Colonel Taint
Mar 14, 2004


OK, am I insane for thinking that C include files should include any dependencies in them?

For some reason it got into the head of a few programmers here that forcing users to do this:

#include "someheaders_dependency.h"
#include "someheader.h"

is more right than just putting the dependency in in the header, which leads to me chasing down dependencies over the past hour and winding up with a list of 30 or so headers included because I need info about a single struct type that's apparently at the bottom of the dependency tree.

They gave me a reason once but I forgot it. Probably because I thought it was total bs, but is there really any valid reason to do this?

Smugdog Millionaire
Sep 14, 2002

8) Blame Icefrog

Dessert Rose posted:

I mean, all the dirty parts are hidden from me, so I don't really care about the oddities, but it has some leaky bits (like the fact that a nullable type is never truly null)

They're null in contexts where it's possible for them to actually be null, i.e. when they get boxed to a reference type: http://dotnetpad.net/ViewPaste/qHZgIkLGOU21OHPOCxDThQ

Gul Banana posted:

it's extremely irritating to not be able to have eg Nullable<System.Object>

This has never irritated me :shobon:

Qwertycoatl
Dec 31, 2008

SintaxError posted:

OK, am I insane for thinking that C include files should include any dependencies in them?

For some reason it got into the head of a few programmers here that forcing users to do this:

#include "someheaders_dependency.h"
#include "someheader.h"

is more right than just putting the dependency in in the header, which leads to me chasing down dependencies over the past hour and winding up with a list of 30 or so headers included because I need info about a single struct type that's apparently at the bottom of the dependency tree.

They gave me a reason once but I forgot it. Probably because I thought it was total bs, but is there really any valid reason to do this?

It sounds like total bs to me. I hate it when people write headers that aren't self-contained.

astr0man
Feb 21, 2007

hollyeo deuroga

SintaxError posted:

They gave me a reason once but I forgot it. Probably because I thought it was total bs, but is there really any valid reason to do this?

There's some coding standards that say you shouldn't use #include in header files to protect yourself against a case where some header file doesn't have the proper include guards in it. But if you are working somewhere that enforces this dumb rule you should quit and go somewhere else.

Blotto Skorzany
Nov 7, 2008

He's a PSoC, loose and runnin'
came the whisper from each lip
And he's here to do some business with
the bad ADC on his chip
bad ADC on his chiiiiip

SintaxError posted:

OK, am I insane for thinking that C include files should include any dependencies in them?

For some reason it got into the head of a few programmers here that forcing users to do this:

#include "someheaders_dependency.h"
#include "someheader.h"

is more right than just putting the dependency in in the header, which leads to me chasing down dependencies over the past hour and winding up with a list of 30 or so headers included because I need info about a single struct type that's apparently at the bottom of the dependency tree.

They gave me a reason once but I forgot it. Probably because I thought it was total bs, but is there really any valid reason to do this?



It's a yet another dumb thing that was popularized by Rob Pike for a reason that was quasi valid 25 years ago:

Rob Pike posted:

Simple rule: include files should never include include files. If instead they state (in comments or implicitly) what files they need to have included first, the problem of deciding which files to include is pushed to the user (programmer) but in a way that's easy to handle and that, by construction, avoids multiple inclusions. Multiple inclusions are a bane of systems programming. It's not rare to have files included five or more times to compile a single C source file. The Unix /usr/include/sys stuff is terrible this way.

There's a little dance involving #ifdef's that can prevent a file being read twice, but it's usually done wrong in practice - the #ifdef's are in the file itself, not the file that includes it. The result is often thousands of needless lines of code passing through the lexical analyzer, which is (in good compilers) the most expensive phase.

Just follow the simple rule.

nielsm
Jun 1, 2009



Otto Skorzeny posted:

It's a yet another dumb thing that was popularized by Rob Pike for a reason that was quasi valid 25 years ago:

quote:

The result is often thousands of needless lines of code passing through the lexical analyzer, which is (in good compilers) the most expensive phase.

Lexing? Expensive? Yeah maybe it was in a different time, pretty sure compilers spend most of their time doing optimizations these days. Also, compilers understanding include guards and not needlessly re-reading includes.

Zorro KingOfEngland
May 7, 2008

Java code:
List<?> getAllButts(Filter, Filter, Filter, int, int, int, String, String, String, String, String, String, String, String, boolean, int, int, int, String, String)
I couldn't expand intellisense to be wide enough to see all the parameters, figured it belonged here.

Suspicious Dish
Sep 24, 2011

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

nielsm posted:

Lexing? Expensive? Yeah maybe it was in a different time, pretty sure compilers spend most of their time doing optimizations these days. Also, compilers understanding include guards and not needlessly re-reading includes.

And yet it's still super slow. I want modules, dammit.

Cat Plus Plus
Apr 8, 2011

:frogc00l:
I present to you a PHP-like EDSL in C++, the future of "fast, robust, secure and easy to scale" web development.

Start with lib/core.h and lib/core.cpp. And if you've ever seen MediaWiki skins, this should be pretty familiar (it's somehow worse).

I'm definitely buying a commercial license to secure my competitive advantage. :allears:

Dren
Jan 5, 2001

Pillbug
One of the main goals of Go was to solve the problem of the C compiler taking forever to parse nested C header includes. I don't support the practice of forcing users to include all header dependencies, I think it's better to write a self contained header with guards and suffer the compilation slowdown, but your code probably compiles faster for the trouble you're enduring.

Qwertycoatl
Dec 31, 2008

Compilers these days can detect when a header has include guards and skip it the second time without having to re-read it.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

LOOK I AM A TURTLE posted:

Eric Lippert, one of the designers of C#, has mentioned on many occasions that he regrets that Nullable<T> can only be applied to value types, as opposed to all types. He has also confirmed that the reason is basically that the features -- i.e. 1. Nullable types and 2. The distinction between reference types and value types -- entered the language in the wrong order. From a theoretical point of view the biggest problem is that it prevents the Nullable<T> type from being truly monadic, since you can't have a Nullable<Nullable<T>>. This series of posts touches on it: http://ericlippert.com/category/monads/

Good find, thanks. The money quote is in the second post:

Eric Lippert posted:

And even this is essentially an accident of history; it just so happened that when C# was first implemented it had always-nullable reference types, non-nullable value types, and no generic types at all. In a counterfactual world where the CLR had generic types from the get-go, it seems plausible that Nullable<T> could have been implemented to work on any type, and reference types would then be non-nullable by default. We could have a type system where Nullable<string> was the only legal way to represent "a string that can be null". Keep this in mind the next time you design a new type system!

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

Rothon posted:

The return value is only *usually* 0. If you call something that returns a struct by value that's larger than a register, the contents of it are undefined!

Isn't that only the case if you're abusing objc_msgSend with a struct return when you should be using objc_msgSend_stret?

Also is that still true on arm64?

Vanadium
Jan 8, 2005

Suspicious Dish posted:

And yet it's still super slow. I want modules, dammit.

Coding horror: Rust lang has modules but it takes even longer to compile. :(

Workaday Wizard
Oct 23, 2009

by Pragmatica

Vanadium posted:

Coding horror: Rust lang has modules but it takes even longer to compile. :(

Rust compiler is slow because it is written in Rust which is missing a lot of optimizations.
Give it time :shobon:

Dren
Jan 5, 2001

Pillbug

Qwertycoatl posted:

Compilers these days can detect when a header has include guards and skip it the second time without having to re-read it.

Got any keywords I can use to search about this? Like, is it in the version of gcc I'm stuck on? (4.4.7) Does it need #pragma once?

Fuck them
Jan 21, 2011

and their bullshit
:yotj:
So I get this on the skype chat with the team today:

$CLIENT accedently deleted all of their servers on their server, Including all of our testing ones. 70+ VM's


I should add that $CLIENT is a loving state government.

:stonk:

ManoliIsFat
Oct 4, 2002

2banks1swap.avi posted:

So I get this on the skype chat with the team today:

$CLIENT accedently deleted all of their servers on their server, Including all of our testing ones. 70+ VM's


I should add that $CLIENT is a loving state government.

:stonk:
Well it shouldn't be too bad, I'm sure with an environment where something like that is possible, the beautiful and intellectually well-regarded state of Floirda must have a first class backup setup. (good luck)

Adbot
ADBOT LOVES YOU

Plorkyeran
Mar 22, 2007

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

Dren posted:

Got any keywords I can use to search about this? Like, is it in the version of gcc I'm stuck on? (4.4.7) Does it need #pragma once?

Yes and no (Chromium actually found that #pragma once was (trivially but statistically significantly) slower than include guards). It's not a remotely new optimization.

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