Tr3v


Comments:

C# html table builder

posted by Tr3vTr3v(376) 4 years, 2 months ago 0

The download option is now working, apologies for that!

Reply

C# html table builder

posted by Tr3vTr3v(376) 4 years, 2 months ago 0

Unless I misunderstand you, does it not do that already?

Reply

C# html table builder

posted by Tr3vTr3v(376) 4 years, 2 months ago 0

Sorry, after re-reading your post, I see what you mean! I didn't think of that when I built the class, the download is for the source so anyone can adapt it to suit their individual needs. If I get round to it i'll update it to do exactly that as it would be a useful addition. Thanks for the feedback.

Reply

Descriptive Enumerations

posted by Tr3vTr3v(376) 4 years, 2 months ago 0

Nice idea, in the past I've used attributes I'll make a note to try your method out next time.

Reply

C# html table builder

posted by Tr3vTr3v(376) 3 years, 11 months ago 0

I've finally gotten around to adding that update, the AddHeaderRow and AddRow methods now return the builder so you can do .AddRow(...).AddRow(...); if you wish

Reply

Try-catching in a single line of code

posted by Tr3vTr3v(376) 3 years, 11 months ago 0

"Do you like reducing your line count at the expense of readability to others?"

Personally no. I think that the readability of code is rather important, especially in a team environment where you may need to read & understand someone else's code. Even on a personal project I still think readability is important, how many times have you done some clever/cool coding then come back to it months later and just gone WTF?!?

Reply

Try-catching in a single line of code

posted by Tr3vTr3v(376) 3 years, 11 months ago 0

Yes that is indeed true, however my comment was aimed at the question rather than the example.

Reply

10 Tools Which I Left After Using VSTS 2008

posted by Tr3vTr3v(376) 3 years, 11 months ago 0

Useful post, I use VS 2008 Pro but found a couple of extra tools to install!

Reply

.NET Coding Standard & Code Review Points

posted by Tr3vTr3v(376) 3 years, 10 months ago 0

I mostly agree with that, however you should not use Hungarian notation (int intCategoryId or string strName) in C#, if you use any code profiling tools such as FxCop they will pick up on this. Also in a case sensitive language you should use casing (private int categoryId, public int CategoryId) instead of m_ to differentiate between member and public properties.

On a personal note, I don't believe in commenting for the sake of commenting so where you have

// Instantiate category object
Categories categories = new Categories();
// Load the category
categories.Load();

I would not bother, in that case it is perfectly obvious what you are doing, comments should be used to explain certain behaviour and why it was chosen. Developers dislike commenting code, therefore it is much better to write readable code using self explanatory names for classes, properties, methods, variables etc. and just save comments to describe complex behaviour or justify business logic for future reference.

Where possible, objects that implement IDisposable should be used in a using statement which is automatically compiled down to a try, finally code block. This helps reduce the possibility of an object that has specific disposal requirements from not being disposed properly.

using(obj o = new obj())
{
obj.DoSomething();
}

gets translated into

try
{
obj o = new obj();
obj.DoSomething();
}
finally
{
obj.Dispose();
}

at compilation. obviously this only really works when you are creating, using and disposing an object inside a single method call, if you are passing an object about that implements IDisposable then you should still call the dispose method manually.

Reply

Add scripts to head dynamically

posted by Tr3vTr3v(376) 3 years, 9 months ago 0

You'd be better adding JavaScript files to the end of your page, just before the </body> tag. Look at Yahoo!'s YSlow information if you want to find out more.

Reply

Parsing Strings in C#.Net

posted by Tr3vTr3v(376) 3 years, 8 months ago 0

You'd be better off using .TryParse() for anything that supports it as it returns a boolean value indicating whether the parse was successful. In your example it works OK because your string only contains a numeric value, however if the string was alphanumeric you would get an exception thrown at runtime.

Reply

Elegant Code pt 2 of 2

posted by Tr3vTr3v(376) 3 years, 7 months ago 0

You could improve this further by replacing your second version:

int something(int goofy, int mickey)
{
bool isBigger = (goofy > mickey);
if(isBigger)
return goofy;
return mickey;
}

with this:

int something(int goofy, int mickey)
{
if(goofy > mickey)
return goofy;
return mickey;
}

As there is no point caching the result of the goofy > mikey test if you are not going to use that result again within the method.

You could go one step further and use the ternary operator and write the method like this:

int something(int goofy, int mickey)
{
return (goofy > mickey) ? goofy : mickey;
}

Reply

Gzip vs Deflate: Which is the faster HTTP compression method?

posted by Tr3vTr3v(376) 3 years, 6 months ago 0

Another question to answer would be which compacts the smallest? does one or the other method produce a smaller output stream if it does, is the bandwidth more important to you than the compression speed?

Reply

Easy Way To Understand LINQ

posted by Tr3vTr3v(376) 3 years, 2 months ago 0

It's just personal preference but I try to limit the

var q = from c in contacts where c.State == "WA" orderby c.LastName, c.FirstName select c

style linq to when it's doing a "select new" (either a type or an anonymous type). The rest of the time I use

var q = contacts.Where(c => c.State == "WA").OrderBy(c => c.LastName).OrderBy(c => c.FirstName);

Reply

Write C# instead of JavaScript - gain the productivity of C# dev.

posted by Tr3vTr3v(376) 2 years, 4 months ago 0

I like the idea and the fact that there are free and paid for options for it! A contractor I used to work with used a similar concept in Java, nice to see C# has that too now.

Reply

Loop through Enumerations in C#

posted by Tr3vTr3v(376) 1 year, 8 months ago 0

I've posted an example on your blog, you would be better off using Enum.GetValues(typeof(ImageSide)))

Reply