« first day (584 days earlier)      last day (4371 days later) » 

4:03 PM
it mean it can be true, false, or null
it actually compiles into Nullable<bool>
 
I know that :) I mean your above code, how would it handle a bool? since you can't create a null object, or can you?
Or maybe I'm not getting it. I'm trying to learn MVC and it's got me a bit confused on some things
 
Ok, i have a form with no frameBorder. I have made a control fill the whole thing. I want to be able to click and drag the control(panel)...and it will move the whole form?
 
@TonyHarmon it can't handle it, you'd have to make an overload that return bool?
 
I thought so and I'm shocked I was right... And I thought everything I was reading/trying was going to /dev/null :)
 
Elite gamer...that is a great questio
 
4:13 PM
@TonyHarmon it feels like that for a while, practice makes perfect ;)
 
@KendallFrey sup bro
hows things?
 
Hi. Chillin at skool
 
living the life i see... luck man!
 
yesterday was better. Victoria Day!
went hiking/biking in niagara falls
 
sweet
what bike u got?
 
4:23 PM
Idk. It is my dad's.
I don't bike much
 
ahh ok
i really like biking
guessing the scenery up near the falls must be pretty sweet
 
We didn't get to see the falls. :( We were by the rapids.
Man, I wanna do something like this: youtube.com/watch?v=Ep2lNMic_fk
 
ahh ok, u seen em b4?
 
Yeah lots.
Sorta
 
lol that looks pretty cool
 
4:29 PM
So epic.
 
lol
 
I'm trying to figure out more about neural networks.
Maybe make an intelligent game.
 
I want to select distinct objects from a list using Linq where for a given ID, take the object with the lowest price. For instance, this is the example I'm going using to de-dupe the list:

var distinctItems = items.GroupBy(x => x.Id).Select(grp => grp.First());

But I don't want just the first item from each group since they're not all "equal". I want the Min. But this doesn't work:

var distinctItems = items.GroupBy(x => x.Id).Select(grp => grp.Min(y => y.Price)));

Should I just make an actual question? This is my first experience with Linq so I feel like this is a bit of a dumb question.
 
One of the major shortcomings of the Min method is that it selects the value, not the object. Lots of people have had issues with it.
 
I'm seeing that. Wasn't sure if it was because I was using it incorrectly.
 
4:34 PM
There are several implementations of a MinBy method out there, but none for plain LINQ in the .NET libraries.
I found an answer using Aggregate: stackoverflow.com/questions/914109/…
Aggregate is a lot more powerful than most people realize.
var distinctItems = items.GroupBy(x => x.Id).Select(grp => grp.Aggregate((cur, y) => (cur == null || y.Price < cur.Price ? y : cur))));
That should do it.
 
Thanks for the help. I'm trying to type this without looking at what you've done so I can hopefully figure it out myself now that I know about Aggregate ;)
 
That kind of attitude makes great programmers. Too many people will copy/paste any code they find.
 
@KendallFrey do you have any rules of thumb for when a method should be static? ive had a look through msdn guidelines but cant find anything specific
 
@HansRudel If it doesn't require an object reference, make it static.
 
Isn't FirstOrDefault an easier path?
 
4:45 PM
I also like to make it static if it does something like compare two objects.
@Baboon To what?
 
@HansRudel I'm not Kendall, but static is for methods that don't require state
 
@KendallFrey @baboon i have a whole series of user input checks, file extensions, text has been entered, can write to the specified file. As far as i can see these should be static as well?
@baboon, howd u mean state?
 
Can you give an example of (one of) the method in question?
 
i know my naming is sh!t, i will working on it
public void ValidateOutputFilePath(List<string> errorLog, string filePath, string selectedOutput)
        {
            if (string.IsNullOrEmpty(filePath))
            {
                errorLog.Add("No filepath has been specified in " + selectedOutput + ".");
            }
        }
public void ValidateWriteAccess(List<String> errorLog, string filePath, bool isGnuplot)
        {
            bool textInFile;
            try
            {
                using (StreamReader reader = new StreamReader(filePath))
                {
                    if (reader.Peek() > -1)
                    {
                        textInFile = true;
                    }
                    else
                    {
                        textInFile = false;
                    }
                }
 
Looking at the first one, is errorLog a global object (not a member of this)?
 
4:51 PM
its a formal parameter
 
Oh, yeah, missed that.
Then I see no reason for it not to be static.
 
sweet, thanks
@KendallFrey sorry one more, whats the dif between a static class and declaring all the methods in the class static?
im assuming none?
 
@HansRudel A static class can't be instantiated.
Fun fact: The CLR sees a static class as abstract sealed
 
but if all the methods in the class are static then...
 
Seems contradictory, but it is legal.
 
4:54 PM
Seems like book ends to me.
 
@HansRudel There is still the default constructor.
 
fair point
ill just make my methods static then based on what u have said + msdn.microsoft.com/en-us/library/ms229038.aspx
 
Have fun and cheers. Time for me to go.
 
There's nothing wrong with using a static class if you never plan on instantiating it.
Certainly makes it's use more clearly defined.
Later @KendallFrey
@TonyHarmon
 
@KendallFrey catch u laterbro
@SpencerRuport aye ok. Whats ur take on static properties?
 
5:00 PM
Use them wisely :)
What are you thinking of using one for?
 
@KendallFrey Whats up man!
 
@SpencerRuport the first project i worked on i used them a reasonable bit. It was to parse a csv file into a database. I used them for things like number of errors found in the file, initial row to be uploaded, final row to be uploaded.
im working on my second project now, extracting info from the database and was just curious what someone like urself thought about their use
 
@HansRudel State is keeping values in member variables that are instance-specific (i.e: variables that are not static)
and I read somewhere that static methods are faster to call
probably since there is no v-table involvement whatsoever
and it beats once again what you learn at school
where they teatch you static is evil
(at least that's what they told me, those morons)
 
@HansRudel - Using them for number of errors in a file sounds like a bad use of them.
 
Static classes are excellent for utility methods.
 
5:09 PM
@HansRudel static properties is very much like global variables
 
If you need such simplistic instance variables it makes more sense to create an instance of the class, perhaps pass the stream or path of the CSV into the constructor and then access the properties as regular instance members.
 
namespaced global variables.
 
hmm ok, sh!t
 
@Greg spot on
 
    public void datemodified_Click(object sender, EventArgs e)
    {
        if (selectdirectories.SelectedItem == null)
        {
            datemodified.Text = "";
        }
        else
        {
            DateTime lastdate = Directory.GetLastWriteTime(@"C:\Mavro\MavBridge\" + selectedPath);
            datemodified.Text = selectedPath + " was last modified on " + lastdate.ToString();
        }
    }
That code is only getting the date on the first three selections in the combobox
 
5:11 PM
I think there has been a bit to much blowback against using constructs that aren't OOP. Use the right tool for the job, even if it is procedural.
 
@HansRudel - You want to keep variables as localized as possible. Only use a more widely accessible type if there's no other way.
 
Idk why....its strange never seen that before. Anyone have a clue as to why this might be
 
Seen what @heinst?
 
@SpencerRuport the reason i did it was i thought it would be easier/cleaner than having to pass all these variables each time
 
"pass"?
I don't think you'd have to pass them at all.
 
5:12 PM
if they werent static
i would
 
Assuming the class also contained the method which was parsing the CSV
 
@SpencerRuport nah i had a class for checking the data types. Another for updating the progress bar. Both needed to know what the current row was and what the initial n final row were
 
something like
 
@SpencerRuport only the first three of the directories get date modified the rest show the year 1600
 
Keep in mind that in the old days, before OOP, you used to have to pass a structure of a certain type to each method by reference to your methods
This was a sort of workaround OOP. Don't use that pattern anymore in an OOP language.
 
5:14 PM
class MyCSVHelper {
    public ErrorCount { get; private set; }

    public MyCSVHelper(string path) {
        // do some stuff here...
        ErrorCount = 10;
    }
}
@HansRudel - You didn't have anything like that?
@heinst - Does the app have permissions to read those files?
 
@SpencerRuport nope
 
@HansRudel - Well then your design might have been flawed at a more basic level.
 
the property was in a completely sep class
 
I can't be certain obviously as I only have a superficial understanding of what you were trying to do.
 
@Greg that sounds like a bit of hassel
@SpencerRuport can i show u some of the code?
 
5:16 PM
How many lines is it?
 
im just checking
 
@HansRudel It was a bit of a hassle. Alot of fortran coders still do it. I think its one of the reasons OOP was invented.
 
@SpencerRuport 385
 
alright
 
for just the class which checks the datatype
 
5:18 PM
can you put it on pastebin or something?
 
sure
 
little easier than scrolling up and down :)
 
i'd suggest renaming your private variables like so: private int _finalRowInFile;
 
this is the class with all the static properties in
 
5:22 PM
but i commend you on your commented code
 
First thing I notice right away hans
private int SomeVariable; public int SomeVariableProp { get { return SomeVariable; } set { SomeVariable = value; } }
Is equivalent to
private int SomeVariableProp { get; set; }
 
@Greg, yeah ive had a look through the naming guidelines but its still find it tricky. Regarding the comments, thanks, first program and wanted to get into a good habit.
 
Save yourself some keystrokes ;)
 
@SpencerRuport yeah i learnt about the auto implementing properties last week
thanks though :)
new program has them in it
 
Hmm spencer, I mostly agree, but if he intends to change the Property later, but act on the private variable locally, it might make sense to break them up.
 
5:28 PM
@SpencerRuport @Greg this is part of my first program and although it works i aint had any comments on it so id appreciate it if u guys were brutally honest. If its sh!t then please do say so.
 
@Greg - Then this works: public int SomeVariableProp { get; private set; }
 
@SpencerRuport I meant more along the lines of { get { recordDate(); return _value;}
 
One tip I picked up recently that I love now, is initializing my events with an empty delegate like so:

public event EventHandler<CompletionEventArgs> VerificationCompleted = delegate { };
That completely cuts out the need for the OnVerificationCompleted method
 
if your expecting to insert code for public reads, but not private, it makes sense to start with properties with paired privates
Kyle, that is an excellent idea.
Does it effect code access time at all?
 
Then you can just call the event directly
 
5:31 PM
no more if(myEvent == null) myEvent()
 
I wouldn't use it in absolutely performance critical scenarios
 
good advice though
 
But I picked it up from Jon Skeet's book, so it can't be all that bad ;)
 
i remember having to use an empty delegate with special properties to get a GDI+ canvas via interop to draw.
 
@KyleGagnet i will make a note of that. The code ive shown u is used to read 15,000,000 rows each row has 3 columns
 
5:33 PM
n/m
 
@HansRudel - So I guess I'm just not understanding why you don't just have the number of errors count as an instance variable of the DataVerification class.
What benefit do you get out of putting the count in another class?
 
Now I'm really curious now to know which is faster, an extra call to an empty delegate, or all the code associated with the OnXXX method, where you grab a reference to event, null check, etc.
 
hmmm, good thought kyle
sounds like a benchmark opertunity
gah, im suppose to be writing javascript, and here i am benchmarking c#
i wonder if the compiler will optimize the null check out
 
@SpencerRuport tbh im not 100% sure but i have code in form1, the dataverification class and the progressbar class which all need to access it
and at the time i thought it would be easier to have just one place which i knew would be upto date and wouldnt have to worry about passing between classes
i fully accept that my reasonings may be completely flawed
@KyleGagnet if u do check it, please let me know as id be curious to know what the answer was
 
why is this not working?
ThreadStart b = new ThreadStart(fillAutoCorrect(Request.QueryString["name"].ToString()));
I want to use the querystring in several methods in several seperate threads, and the threads can't access the querystring , so I try to pass it to the method
 
5:41 PM
@HansRudel - Does the ProgressBar class consume the OnUpdateProgressBar event?
Why don't you just pass the number of errors in there along with the rest of the event args you're providing?
 
i have a method that get a dictionnary from two cells in a table in my database, i want that a drop down list shows the list of values contained in this dictionnary
 
@ScottSelby - Because the ThreadStart method is expecting the method address, not the return value of the method as a parameter.
 
@SpencerRuport yeah it does
 
@SpencerRuport the fillAutoCorrect() is the method address and it accepts a string , method returns void
 
@SpencerRuport number of errors is used after completion to write to a txt file
 
5:44 PM
Scott it should be something like
Thread t = new Thread (new ParameterizedThreadStart(fillAutoCorrect));
t.Start (Request.QueryString["name"].ToString());
@ScottSelby fillAutoCorrect() isn't the method address. fillAutoCorrect is.
As soon as you put the parenthesis it executes the function.
@HansRudel - I thought you said the progressbar class used the error count
 
comboBox.DataSource = new BindingSource(myDictionary, null);
comboBox.DisplayMember = "Value";
comboBox.ValueMember = "Key";
 
@KyleGagnet is the comboBox similar to drop down list or not
 
        /// <summary>
        /// Updates the progress values for that specific progress bar.
        /// </summary>
        /// <param name="initial">Percentage division calculation (numerator).</param>
        /// <param name="final">Percentage division calculation (denominator).</param>
        public void PB(double initial, double final)
        {
            double result = Math.Round((initial / final) * 100);

            //Hack required to force progressbar to instantly update between values.
 
@ScottSelby - Take a look at:
27
Q: C# ThreadStart with parameters

JL.How is it possible to start a thread with parameters in C#

 
@SpencerRuport no it only uses the initial, final i believe. def not number of errors.
sorry if i gave that impression
 
5:49 PM
I tried that , I got - No Overload for 'fillAutoCorrect' matches the delegate System.Theading.ParamaterizedThreadStart
 
@ScottSelby - Show me your function definition for fillAutoCorrect
@HansRudel - haha okay so besides DataVerification what other classes use the error count then?
 
@SpencerRuport protected void fillAutoCorrect(string name)
{
 
form1 thats all
 
@HansRudel - And form1 already has an instance of DataVerfication?
@ScottSelby - change it to
protected void fillAutoCorrect(object name)
 
@SpencerRuport yes. FileInformation class holds the property. Form1 creates an instance of DataVerification, DataVerification updates the number of errors found. Once finished, Form1 accesses the property in FileInformation and see's how many errors there are.

thinking about it now, that seems a bit stupid
 
5:53 PM
There ya go ;)
 
lol
 
Just let DataVerification keep track of the error count and then expose a public readonly property that Form1 can use to access it.
Suddenly no more statics.
 
@KyleGagnet Ran some bench marks
 
@SpencerRuport ok so for numberoferrors it does seem like a bit of a stupid idea. What about the row count? are they a valid example of static properties?
 
@KyleGagnet it looks like null checking is about twice as fast as the delegate for a simple operation like delegate {j=J+2}
 
5:56 PM
@SpencerRuport + apart from that stupid mistake on my part, if u had asked someone to write a csv parser and someone gave u that for the file validation, would u had it back to them or would it be ok?
 
@HansRudel - I don't see rowcount anywhere. What variable or methods are you referring to?
 
@SpencerRuport
while (operation.CurrentRow <= operation.FinalRow && operation.CurrentRow >= initialRow && reader.Peek() > -1)
                        {...
 

« first day (584 days earlier)      last day (4371 days later) »