« first day (3166 days earlier)      last day (1998 days later) » 

06:06
Good morning
Good morning :D
Why is this not an unneccessary cast?
@Rob you left
oh no
What do you mean with "conditional parameer" ?
a parameter you may use
or may not use
06:12
They're called optional parameters in C#, and you go like public int SomeMethod(string ImaOptionalString = null){};
ok the = null
Yeah exactly
not for int
lol
getting error
you have to give it a default value that applies ifthe parameter isn't provided.
int cant be null, you cna use any int though.
06:18
public AnotherMethod(int someNumber = 500){}
You can use anything, as long as it's compile time constant.
So you can't give it new object() as default value
mr5
mr5
@Squirrelkiller because you're comparing against null which is applicable to all reference types
I kinda understand what you're saying, I just don't understand the timing
mr5
mr5
lol. How long ago was that?
Ohhh I see
I always forget replies can actually oitn to specific messages, that's really helpful :D
mr5
mr5
wat
you didn't know that?
06:23
I didn't understand you replied to my earlier question^^
I usually forget it
mr5
mr5
u iz old
But can't I compare any property to null? A value type will always resolve to false, a reference type can be null
> 5 == null
false
Why care if it's a string?
GoOoOoOoOoOoOoOoOoOoOoOd Mornin' squirrelerinos!
mr5
mr5
nerdintraining is back
You can use:
bool IsNotDefault<T>(T value) => !EqualityComparer<T>.Default.Equals(value, default);
Why would I do that?
Madness!
06:30
wow you can even have the first parameter be optional
As long as you don't have a non-optional parameter after an optional parameter, it's all good.
mr5
mr5
because you want to check if the T is on its default value?
72
A: Test for equality to the default value

Marc GravellTo avoid boxing for struct / Nullable<T>, I would use: if (EqualityComparer<T>.Default.Equals(value,default(T))) { // do stuff } This supports any T that implement IEquatable<T>, using object.Equals as a backup, and handles null etc (and lifted operators for Nullable<T>) automatically. Th...

Madness?

THIS IS C#!!!

*sends a stream towords killerino that throws him in a pit*
mr5
mr5
if (T is default)
For one, there is no T. It's dynamic... :(
mr5
mr5
06:34
please make this feature request
ugh
Also it's always either a string or empty.
mr5
mr5
What would happen if you pass it though?
Haven't had experience working with dynamic
What's empty? Empty string?
dynamic...jsut works. It's black magic.
null
string or null
dynamic is basicallly javascript
You throw in json form the outside, and just call the properties
mr5
mr5
Just change its type to object
static async Task Main(string[] args)
{
	Coffee cup = PourCoffeeAsync(100);
	Console.Write("coffee is ready\r\n");
	var eggTask = FryEggsAsync(3000);
	var baconTask = FryBaconAsync(4001);
	var toastTask = maketoastWithButterAndJamAsync(5001, 10001, 5001);

	Egg eggs = await eggTask;
	Console.Write("eggs are ready\r\n");
	Bacon bacon = await baconTask;
	Console.Write("bacon is ready\r\n");
	Toast toast = await toastTask;
	Console.Write("toast is finally ready :)\r\n");
	Juice oj = PourOjAsync(100);
ok so this is an exercise i created for asynchronous continuation
static async Task Main(string[] args)
{
	Coffee cup = PourCoffeeAsync(100);
	Console.Write("coffee is ready\r\n");
	var eggTask = FryEggsAsync(3000);
	var baconTask = FryBaconAsync(4001);
	var toastTask = maketoastWithButterAndJamAsync(5001, 10001, 5001);

	Egg eggs = await eggTask;
	Console.Write("eggs are ready\r\n");
	Bacon bacon = await baconTask;
	Console.Write("bacon is ready\r\n");
	Toast toast = await toastTask;
	Console.Write("toast is finally ready :)\r\n");
	Juice oj = PourOjAsync(100);
ok now it makes sense. wow yea you can make all the parameters conditional
or I guess you're just setting them to default values
but still that is awesome
i don't think you can do such a thing in js
06:44
@ChristianMatthew Sure you can.
,,,
lol like that
i think I am thinking of typescript where you can conditional a parameter but it has to be after a default one like this foo(param1, param2?, param3?)
Can I somehow let that method take either of the types?
@ChristianMatthew All parameters in JavaScript are non-mandatory, because JavaScript. Default parameters are allowed since ES2015.
(And still have IntelliSense suggest the overloads)
Guys, I'm having trouble phrasing this into a question.

I have a shitty designed database, there exists a TableA witch column ColumnA, it should always have the same value as TableB's column ColumnB.
Now the problem arouse because the values aren't the same and I have to write an SQL script that iterates over all datasets in TableB and finds the correct Datasets in TableA and changes the value for TableA.ColumnA to the correct value (TableB.ColumnB).

In pseudocode sth like:
forAll(dataset in TableB)
06:56
@ChristianMatthew Change minutes to seconds
it's make believe
lol
give it that added realism you know
@ChristianMatthew Move 'Console.Write("eggs are ready\r\n");' etc. into the async function
i am not finished yet
i am applying work to this tutorial
they gave me a tutorial with no instructions on how to do it lol
it is pretty cool though to see exacty how this async stuff works. the exercise has been extremely enlightening especially with @Rob help
I (will) learn this too.
now
@kame for real... do you think it is a good exercise
07:08
@ChristianMatthew There are to many elements just coffee and toast is enough :D
nobody can survive on 2 breakfast items
in the USA we eat cow for breakfast
all parts of the chicken
mother, fetus
fetus on the mother
the things we do to chicken
@Squirrelkiller Use object category and then do an if (category is string categoryString)
static async Task Main(string[] args)
{
	Coffee cup = PourCoffeeAsync(100);
	Console.Write("coffee is ready\r\n");
	var eggTask = FryEggsAsync(3000);
	var baconTask = FryBaconAsync(4001);
	var toastTask = maketoastWithButterAndJamAsync(5001, 3001, 3001);

	var allTasks = new List<Task>{eggTask, baconTask, toastTask};
	while (allTasks.Any())
	{
		Task finished = await Task.WhenAny(allTasks);
		if (finished == eggTask)
		{
			Console.Write("eggs are ready\r\n");
			allTasks.Remove(eggTask);
			var eggs = await eggTask;
@kame here is final version
@ChristianMatthew I have to leave for two hours
it's ok i have to go to bed. but wanted to leave you with final version
07:22
@Roel but muh IntelliSense for the LogCategory enum :/
> Now the problem arouse
@Squirrelintraining Uhh
To each their own I guess
you can make an implicit convert operator
but what you really want is (String | LogCategory)
Rob
Rob
@Squirrelintraining Sounds like you just need a simple update script that joins the two tables together
You don't even need to check whether or not the value is correct
Rob
Rob
Update TableA SET TableA.A = TableB.B FROM TableA inner join TableB on TableA.Something = TableB.SomethingElse
@Rob Thanks, i found that answer online aswell after I just started hammering random words which might describe my problem concisely into google
Rob
Rob
07:28
;)
1254
A: SQL update from one Table to another based on a ID match

Mark S. RasmussenI believe an UPDATE FROM with a JOIN will help: MS SQL UPDATE Sales_Import SET Sales_Import.AccountNumber = RAN.AccountNumber FROM Sales_Import SI INNER JOIN RetrieveAccountNumber RAN ON SI.LeadID = RAN.LeadID; MySQL and MariaDB UPDATE Sales_Import SI, RetrieveAc...

That is one nice question header, short, concise, exactly something I wouldn't come up with!
mr5
mr5
07:57
Do you guys know how to bypass a Task without forcing it to become an async Task?
I have a method that doesn't really do any awaitable calls but I marked it Task for future reasons.
Rob
Rob
Why do you mean bypass a task?
If you want to return a concrete value wrapped in a task, use Task.FromResult(data)
mr5
mr5
I think Task.Yield() would do.
@mr5 not sure you should use that.. I remember reading somewhere that it's discouraged
mr5
mr5
Yes. I could also do that.
Well, I'm reading a json data from an embedded resource but it doesn't require to be async so...
And from the top answer in SO, Task.Yield() says could be use to "force" it to run on other SynchronizationContext?
morn
Rob
Rob
08:00
Task.Yield() isn't the right choice here. It's an empty task that forces the execution to be passed back to the context
xy problem mr5. need more information
Rob
Rob
If you just want to return data, but want to return Task<T> to future proof, use Task.FromResult()
what he said ^
mr5
mr5
@Default Task<string> GetSomething() { return "1"; }; // error because no await keyword
Rob
Rob
return Task.FromResult("1")
Gah, that took too many attempts
08:02
lol, FromDefault - I like that
return Task.FromResult((default(int) + 1).ToString())
mr5
mr5
lol
But, but it's ugly
@mr5 that error is only a suggestion, right?
mr5
mr5
yep. it's actually type incompatibility
mr5
mr5
08:04
I also hate warnings
you could use async to not deal with the Task.MakeStuff
but it will yell at you for using async when it is unnecessary
you could also do synchronous coding until you need asynchronous
Rob
Rob
Remove the async keyword and use the above
there are many possibilities here to avoid the warning
you could try
Rob
Rob
08:05
You only need async if you're awaiting something
you could pragma disable the warning :)
mr5
mr5
I'm actually not using any async keyword, Wiet is
Rob
Rob
Oh, good
yea, you arent using the async keyword, you are using a compiler error
pick your poison
@Wietlol rat
08:07
dont you all just love async?
mr5
mr5
Okay. I'll use the ugly Task.FromResult
Rob
Rob
@Wietlol return await await await await await await Task.FromResult(Task.FromResult(Task.FromResult(Task.FromResult(Task.FromResult(Task.FromResult("1"))))));
Make sure it's super async
whatIsLove?.
    babyDontHurtMe()
    .dontHurtMe()
    .noMore()
@Wietlol Yes, what I want is (string | LogCategory)
mr5
mr5
My next question is, how do you serialize a KV of JSON like below into Dictionary<string, string>?
{
	...
	"2150": "Nordhavn",
	"2200": "Copenhagen N",
	"2300": "Copenhagen S",
	"2400": "Copenhagen NV",
	"2450": "Copenhagen SV",
	...
}
08:09
JSONConvert.Deserialize<Dictionary<string, string>>(yourObject);
@Rob ironically, I had some code a while back that did return await await DoStuff();
mr5
mr5
that's actually in my code.
Or dynamic yourDictionary = yourObject; and then just use it as if it wa a dictionary.
mr5
mr5
haven't executed it yet.
it might be worth to try an approach before looking at another one
if it works and it is good, you have a solution
if it works but is shit, you at least have a shitty, working solution
08:11
use yaml, not json
if it doesnt work, then just look for another approach
ew, yaml
that can be parsed without necessarily having to parse the whole thing
there isnt any difference between yaml and json apart from syntax
except maybe type information
json probably has more type information than yaml
json has type information?
"type information"
08:13
json:
"foo"
42
42e10
false
null
mr5
mr5
I think JSON can have a separate file for schema?
yaml:
all strings (iirc)
so its monday again
ugh :(
that's not really type information. It simply gets parsed properly because it can't be confused for other types
08:14
yaml can deal with just as many types
but isnt yaml all strings anyway?
it isn't purely string
objects, arrays and strings
in what sense? Isn't json all strings anyway?
json has a distinction between the values mentioned above
08:15
well so does yaml, from that definition
and if you parse such a value, you get
System.String
System.Int32
System.Double
System.Boolean
System.Object (null)
in return
(without expecting a type)
a: 123                     # an integer
b: "123"                   # a string, disambiguated by quotes
c: 123.0                   # a float
d: !!float 123             # also a float via explicit data type prefixed by (!!)
e: !!str 123               # a string, disambiguated by explicit type
f: !!str Yes               # a string via explicit type
g: Yes                     # a boolean True (yaml1.1), string "Yes" (yaml1.2)
h: Yes we have No bananas  # a string, "Yes" and "No" disambiguated by context.
morning o/
good morning
yet 123 could just as well be a string instead, no?
I mean, technically it's C# that parses it into whatever types it requires
not yaml
if you have a number too large to be a float, then you obviously use double
> b: "123" # a string, disambiguated by quotes
morn squirrel cpt.
but stuff without quotes is also a valid string
a: abc
that is a string
@Hans1984 that's cpt. squirrel to you
08:18
your point?
my bad
if that bothers you, surround it always with quotes
a: 123 is then both a string and an integer
"surrounding it always with quotes" is equivalent of json btw
@Wietlol hmm, no
08:19
if it could be a number, it is a number
mr5
mr5
What do you think of this ugly implementation?
@mr5 I think I would try to make a distinction in the code between deserializing and handling postal codes
deserializing should be left generic
mr5
mr5
You mean, changing the name of the method?
or should be the serializer be a member of the Service?
@mr5 no, I mean it just seems like you're both parsing and determining the city
Those are two separate actions
If you don't want to parse the whole thing, parse it one line at a time, and then use handlers to determine what to do with it
08:25
@Hans1984 How nice to see Cousin John is doing fine!
responsibilities:
- reading a json file from resources
- deserializing the json (dictionary, no type information)
- dealing with direct records ("postalCode" -> "city")
- dealing with range records ("postalCode-postalCode" -> "city")
@mr5
try to move all of these into separate functions
@Squirrelintraining I gave him a hazelnut for his accomplishments
also... is a postal code an int?
I mean I guess it isn't a big deal if the method were smaller, but it is already a bit too long for my tastes
Also, I did a horrible thing to buy Satisfactory
It's so damn addicting
a method is too long if it has more than one responsibility
SatisFactory is the first person version of factorio?
mr5
mr5
08:28
@Wietlol 4 functions for those?
mr5
mr5
@Wietlol it's a string
@Hans1984 But he's allergic to hazeluts \(>o<)ノ
but you do int.Parse(postalCode)
@Wietlol you could think of it as a mix between factorio with 3d graphics and subnautica
08:29
so you assume that it is an int
@Squirrelintraining ooopss
mr5
mr5
damn. I think I'm still not doing my abstractions well if I didn't think that though
yes.
I generate the data
HANS KILLED COUSIN JOHN?!
technically, he killed himself
mr5
mr5
because I have a range key for postal code
08:31
except if hans pushed the nuts into John's mouth
^ feel free to take that out of context
NSFW
!!Is John doing fine ?
@Hans1984 By all means
See, everythings fine
this room is out of control!
did you mean C#?
08:42
in SQL, Apr 15 at 8:44, by Héctor Álvarez
Good, I finally found a job
@HéctorÁlvarez And that message still is on the star board!
mr5
mr5
@Wietlol @Neil please take a look at my revised gist: gist.github.com/mr5z/052573d34a8e2e33ceb237d34ef6665b
I'm not sure how do I decouple the direct records and range records
@mr5 like this, it's far more readable :)
@mr5 I would rename GetCity to FindCity
it helps if you have a clear distinction between nullable and non-nullable
mr5
mr5
@Neil thank you :)
08:47
May 5 '16 at 15:17, by BoltClock
THIS ROOM IS OUT OF CONTROL
for me, it is simple, everything is non-nullable (because it is either a value or wrapped in a wrapper for null awareness)
mr5
mr5
@Wietlol yes sure. I'm also thinking that after I have made a FindCityFromRangeRecords method
but Find vs Get could help with the distinction too
ngl, i read that as everything is nullable
mr5
mr5
if (int.TryParse(PostalCode, out _))
    City = await postalCodeService.GetCity(PostalCode);
Very good suggestion from VS
It was int.TryParse(PostalCode, out var unused)
08:49
now, you can extract this to a class
make the dictionary a property
Morning all :D
morn
then, make the function that parses the json stream to return an instance of that class
you seem to be in a good mood, for a monday
(the class itself doesnt use the json stream or whatever)
the function could be a static function in that class though
08:50
@Wietlol is it a common good practice not to parse stuff directyl in a caller function?
CityLookup.FromJson() for example
@Raimonds could you elaborate?
Well if I got you right you are suggesting to separate parsing of json response to class to somewhere else. In my case I am doing it straight after receiving json
I find it good practise to separate the concerns of where you got that json from and what you are going to do with the json
In your example CityLookup is responsible for conversion in my case it's JsonConvert from Newtonsoft
in my example, CityLookup is not resposible for the conversion, only a function inside it is doing the default variant of the conversion
since the function is static, it doesnt belong to a CityLookup
08:55
It does make sense I am just thinking would it be overkill in my case
and nowhere in the class CityLookup, that function is called
so it doesnt depend on it
I would need to either derive each class from common class thas has FromJson or write it each time
why would you do that?
Howlong can a friggn UPDATE [TABLE] Statement take? :anger:
Been waiting for atleast 1,5min for updating 60k elements
@Squirrelintraining depends, did you put a where clause on it?
08:58
An InnerJoin
that's not a where clause
So yeah a fancy WHERE i guess
It's a fancy where!
:fiteme:
does it say WHERE
if it doesn't
it ain't a WHERE
08:59
@Wietlol I am bit lost ...
FromJson return type is CityLookup right?
But the fact you are doing an innerjoin on an update could be why it is taking a while

« first day (3166 days earlier)      last day (1998 days later) »