« first day (2845 days earlier)      last day (2119 days later) » 

8:02 PM
@M.Aroosi that is somewhat what I am doing now
except that in my case, it is only the evaluation that is basically a tree
not the rule structure
 
8:22 PM
at least it successfully matches the inputs
now comes the horrible part
@M.Aroosi pattern rules that have nested rules, also need to include the nested matches in the match
for example, the sequence rule /abc/ should be
Match(from: 0, to: 3, tokens: ["a", "b", "c"], nestedMatches: [Match(from: 0, to: 1, tokens: ["a"], nestedMatches: []), Match(...b...), Match(...c...)])
 
you want to include them?
 
yep
 
what for?
 
the matches will contain (optional) labels, which is comparable to capturing groups
 
ok
 
8:31 PM
i got it so far that my /abcde/ included... well... the trailing empty match
which starts at index 5 and ends at index 5...
 
you could make it so that empty matches aren't stored in there
 
however, i am not sure how it got that empty one
never mind
im stupid, missed a return
 
:)
 
ok, i only have the last match in the nested matches
so, in /abcde/ i have /e/ as the nested one
i could make the recursion follow the older matches...
but then d is a nested one on e
and c is nested in d
etc
which is not really nice
i need to unfold them... nicely
[
  {
    "startIndex": 0,
    "endIndex": 5,
    "tokens": [
      {
        "identifier": "a"
      },
      {
        "identifier": "b"
      },
      {
        "identifier": "c"
      },
      {
        "identifier": "d"
      },
      {
        "identifier": "e"
      }
    ],
    "nestedMatches": [
      {

      }
    ]
  }
]
hmm... that is nice
(json lib not serializing stuff)
 
time to sleep tho
 
8:42 PM
gn
 
posted on July 31, 2018 by Scott Hanselman

There's a ton of great open source hardware solutions out there. Often they're used to teach kids how to code, but their also fun for adults to learn about hardware! Ultimately that "LED Moment" can be the start of a love affair with open source hardware and software! Arduino is great, as is Arduino talking to the Cloud! If that's too much or too many moving parts, you always start small with

 
9:03 PM
I read this question but it wasn't very helpful https://stackoverflow.com/questions/1343704/casting-c-sharp-out-parameters

Is there a way to cast the out parameter of a `TryGetValue("key", out some_object)` ? Adding a (myClass) doesn't work between the out and some_object.

Basically I have a dictionary<string,object> where each key contains a different "class structure", and they are for sure the same when being return to me. For example if the key was "employee" the object will be an object of employee class. Other than parsing each values out back into a new employee class, is there a
 
Even if you could put a cast there, you'd have to pick the thing you're casting to at compile time.
 
which is fine since I know the key and what it should cast back too.
I'm getting this dictionary from another stream of data so i can't change the stream :\
 
You could do, like

if (TryGetValue(key, out object mr_object))
{
}
whoop
and then do a big switch statement
switch (key)
{
 case "employee":
   DoEmployeeThing(mr_object as Employee)
 case "business":
   DoBusinessThing(mr_object as Business)
}
 
mr_object is an object already
but i see your point hmm
 
This whole thing is kind of a code smell, but I understand being in a situation where you can't really change it
I don't really know what you want to do with these values after you decide what type they are.
 
9:10 PM
im trying to keep it as MCVE as possible but I know it will seem like a whole XY leading problem
object x;
dict.TryGetValue("employeeData", out x);

return (Employee) x;
seems to work but it gives me a warning saying local variable x is not used or something lol :\
 
Well, you have to do out x
 
yeah out x sorry
oops that works
 
but you can do the same thing in one line as return dict["employeeData"] as Employee
 
great I think we solved this silly hack :\
 
TryGetValue is for when you want to branch on whether the key's in there or not
 
9:13 PM
here's the smelly part i know the keys of it if it exists, that's why I'm using a TryGetValue
 
Like, if you're not wrapping it in an if or using the return value, there's no point in using TryGetValue
 
because if the key doesnt exist it's because up stream they set it to null/empty so they don't bother putting it in the dictionary i know it's stupid
i got my answer with the cast it bringing it out answer
it's messy and ugly but so is this legacy code
thanks :D
 
Follow your dreams.
 
I would be coding Python instead of messy c# code :D
anyways have a nice night
 
Hello
what is the best way to get tree ( recursive Hierarchy using Linq )
 private IEnumerable<TreeNode> FillRecursive(IEnumerable<tblHierarchy> Series, int? parentId)
        {
            try
            {
                List<tblHierarchy> AllMainParents = Series.Where(x => x.FK_PARENT_SERIES == parentId).ToList();

                return AllMainParents.Select(item => new TreeNode
                {
                    SeriesId = item.FK_SERIES,
                    Description = item.tblSeries.TX_DESCRIPTION,

                    Children = FillRecursive(Series, item.FK_SERIES)
 
9:26 PM
TryGetValue has no generic type argument right?
 
recursive Hierarchy using Linq for 5000 records very very slow
 
I mean, it's always going to be TryGetValue(TKey key, out TValue value)
 
well... again an issue where out doesnt support other language features
 
What are you talking about
 
you might be able to do out MyClass obj
but I am not sure if that is allowed
 
9:28 PM
You can if you have a Dictionary<Whatever, MyClass>
It's a newish feature, but they have it
I use it all the time
 
but i meant casting as well
i know about out var obj, but introducing a cast there might have done it
 
I mean, it wouldn't have solved that guy's problem
Because he wanted to cast it to something different based on the key
 
not really, the way how I see it is like this
IDictionary<Key<Value>, Value>
for Key<String> the result would be String
for Key<Int32> the result would be Int32
except that the key is always a string, so the keys would be "string" and "int"
but ((string) dict["string"]) is basically what he is after
as far as I understand
 
So then what's the type of newDictionary[Console.GetLine()]
 
((int) dict["int"]) for ints
@Grace i dont know
> which is fine since I know the key and what it should cast back too.
 
9:32 PM
I agree that the language can't really elegantly express that idea
but it's kind of a weird, bad idea to want to express
 
I had the same thing in Java once, where I wanted some caching thing
so, Map<Class<T>, T>
but that didnt really work either
@Bassem can you elaborate your issue?
 
Yeah, in Perfect OOP Land, all your values would implement some interface or inherit from some base class
Or you'd use some other solution
 
@MooingRawr I would make an extension method for an IDictionary that removes the messy out parameter
it would return a nullable version of the TValue
(in my codebases, it would return an Optional<TValue> since C# hasnt got null awareness)
 
These days, you could even have it return, like, (TValue val, bool hasValue)
 
@Grace you could make a wrapper for the dictionary, where you ensure that the input will always be correct
so that when you put the object in the dictionary, you check that the key is actually the type or a supertype of that object
then, you can "ensure" that the values inside the dictionary are correct
and you can cast to the type on the getter
@Grace but then you cant do nice stuff like dict[""] ?? someDefault
 
9:40 PM
I mean, if you're designing things correctly from the start, you shouldn't need to cast things around- the whole ordeal seems like a problem
 
not really true, sometimes the language holds you back
 
Every language makes you play by its rules at some point.
 
I even had times where I had to explicitly upcast because otherwise generics were giving compiler errors
because generics cannot be declared as a supertype of a known generic
only a subtype
and generic type arguments dont exist in constructors
languages will always have a downside because another language does X and this language does Y
a language that can be adapted to do both will last much longer
 
10:04 PM
-_- why is life so difficult?
and why is this room ded?
 
 
2 hours later…
11:51 PM
because I wanted to go to sleep 3 hours ago and I now realize it's 3AM... wonders of the internet
 

« first day (2845 days earlier)      last day (2119 days later) »