OSG Community College C# for Programmers Class #8 Log 03/31/2009
Pastebins are pasted at the bottom:
[11:09] Snowdrop Short: I was a bit in doubt about when to start
today
[11:10] M1sha Dallin: I just thought - this is only 1900 UTC
[11:10] M1sha Dallin: Daylight saving started
[11:10] Snowdrop Short nods
[11:10] Snowdrop Short: yes, in Europe
[11:10] Snowdrop Short: but I believe not in the US
[11:10] M1sha Dallin: they started a few weeks earlier
[11:11] Starky Rubble: Universal Time Confusion lol
[11:11] Snowdrop Short nods
[11:11] M1sha Dallin: 2100 UTC on Thursday will be very late
[11:11] M1sha Dallin: 2300 local for you Snowdrop?
[11:11] Snowdrop Short: yes... I've been thinking the same thing, so
I thought we needed to talk about when to have the classes
[11:12] Snowdrop Short: because otherwise I won't get to bed until 1
am
[11:12] Snowdrop Short: which is a bit late
[11:12] M1sha Dallin: and me midnight
[11:12] M1sha Dallin: I get up at 0615 :-(
[11:13] Snowdrop Short: well, either way we need to decide, I guess
Adelle wil be here in 45 minutes
[11:13] Starky Rubble: miy wife dets home for lunch in a half hour
lol so I am not aprt of this discussion
[11:13] Starky Rubble: get
[11:13] Starky Rubble: adelle is in the UK
[11:14] Starky Rubble: so she will likely agree with you
[11:14] M1sha Dallin: 1900 or 2000 UTC is good with me
[11:14] Snowdrop Short nods, but not here right now, so I assumed
that she'd show up at 20:00 gmt
[11:14] Snowdrop Short: I
[11:14] Starky Rubble: yep
[11:14] Snowdrop Short: I'd prefer 1900 UTC
[11:15] BlueWall Slade is Offline
[11:15] Starky Rubble: now
[11:15] M1sha Dallin: ok by me
[11:15] Starky Rubble: in other words
[11:15] Michael Skelito is Offline
[11:15] Snowdrop Short: then it's still right after the office hours
[11:15] Snowdrop Short: Starky .. you said you had some problems
attending?
[11:16] Starky Rubble: don't worry about me
[11:16] Snowdrop Short: ok
[11:16] Starky Rubble: office hours are a good time for me every day
lol
[11:16] Snowdrop Short: ok :-)
[11:17] Starky Rubble: 19-12:00 always has an interruption
[11:17] Starky Rubble: 19-21:00
[11:17] Starky Rubble: but thats ok
[11:17] Snowdrop Short: ok .. I'll try to put that on the mailing
list
[11:18] Snowdrop Short: how did things work out with your homework?
[11:18] Starky Rubble: this is just a change for Thursdau right?
[11:18] Starky Rubble: today didn't really change did it?
[11:18] Snowdrop Short: no, not really
[11:18] Snowdrop Short: it wouldn't be fair, to change things with
such short notice
[11:19] Starky Rubble: ok 19 for both then
[11:19] Snowdrop Short: but we can pass the time with Q&A
[11:19] Starky Rubble: ah
[11:19] Starky Rubble: I pretty much just flailed on this
[11:20] Starky Rubble: I figure Dictionary is better for the purpose
than Sorted list and can explain why, but thats about it
[11:21] Starky Rubble: I think it is reaaly the same issuue for the
groupd and the menbers lists
[11:21] Starky Rubble: in that they both will be written to rarely
but checked often
[11:22] Snowdrop Short: well, sorted list need some sort of ordering
[11:22] Snowdrop Short: less than and greater than
[11:22] Starky Rubble: isnt that auto-done on the key?
[11:22] Snowdrop Short: if there is a well defined ordering on the
key
[11:23] Starky Rubble: ok
[11:23] Snowdrop Short: otherwise you need to specify it
[11:23] Starky Rubble: so when will we bu using these data?
[11:23] Snowdrop Short: Dictionary is based on hash values
[11:23] Starky Rubble: joining and leaving are one-time events
[11:23] Snowdrop Short: a hash table is generally much faster for
looking up items compared to ordered lists
[11:24] Snowdrop Short: but they take up more memory
[11:24] Starky Rubble: but slower to write to
[11:24] M1sha Dallin: can be faster - if the hash function is good
[11:24] Starky Rubble: (to add to specifically)
[11:25] Starky Rubble: I thought I saw some comparisons but
[11:25] Snowdrop Short: only if you need to extend the backing
hashtable, then it becomes more costly
[11:25] Starky Rubble: ah
[11:25] Starky Rubble: I saw that Sorteds excel for dumping a srteam
into
[11:25] Snowdrop Short: extending a hasttable requires a complete re-
arranging all the elements
[11:26] Snowdrop Short: really?
[11:26] Starky Rubble: I saw some data stashing 10000 numbers in each
of the collections
[11:27] Snowdrop Short: extending a sorted list is pretty efficient
[11:27] Starky Rubble: dictionary was faster onesy - twosey
[11:27] Starky Rubble: way faster
[11:28] Starky Rubble: in that study anwway
[11:28] Starky Rubble: and what do I know so there you go lol
[11:29] Snowdrop Short: if you can spare the memory and have a good
hash function, then it is pretty much impossible to beat the speed of
a hashtable for finding data
[11:29] Starky Rubble: right
[11:29] Snowdrop Short: it'll usually be a O(1) operation
[11:29] Starky Rubble: and thats the majority of the uses
[11:30] Starky Rubble: the grpoups will be hit when accessing objects
mostly I imagine
[11:30] Snowdrop Short nods, I think so too
[11:31] Snowdrop Short: but it is a good thing to study the different
standard collections, and their respective pro's and con's
[11:31] Michael Skelito is Offline
[11:31] Starky Rubble: Oh sure!
[11:31] Starky Rubble: I love data structures lol
[11:32] Snowdrop Short: they can be great fun, but now-a-days I'm
more into patterns
[11:32] Starky Rubble: patterns?
[11:32] Snowdrop Short nods
[11:32] Snowdrop Short: kind of the equivalent of data structures,
but only for classes
[11:32] Starky Rubble: ah
[11:33] Snowdrop Short: different standard ways to combine classes
[11:33] Snowdrop Short: it was - as much else- really invented way
back by Xerox at PARC
[11:34] Snowdrop Short: as part of the smalltalk effort
[11:34] Starky Rubble: as was most everything lol
[11:34] Snowdrop Short: but nobody really noticed it
[11:34] Snowdrop Short: they described the MVC pattern
[11:34] M1sha Dallin: MVC?
[11:34] Snowdrop Short: Model-View-Control
[11:35] Snowdrop Short: a way of dividing up the code behind a user
interface
[11:35] Snowdrop Short: you have a model
[11:35] Snowdrop Short: which describes the data to be operated on
[11:36] Snowdrop Short: e.g. the class hierachy to describe a text
document
[11:36] Snowdrop Short: or a order system
[11:36] Snowdrop Short: or any other kind of model
[11:36] Starky Rubble: or render 3-space
[11:36] Snowdrop Short: like our group/member classes
[11:36] Snowdrop Short: that could be a model
[11:36] Snowdrop Short: then you have your view
[11:37] M1sha Dallin: I bought 'Head First Design Patterns' when I
bought the C# nutshell book
[11:37] Valentine MichaelSmith is Offline
[11:37] Starky Rubble: Hmmm
[11:37] Snowdrop Short: which renders what is inside the model
[11:37] Snowdrop Short: you might even have several different views
of the same model
[11:37] Starky Rubble: sure
[11:38] Snowdrop Short: in our group example we could have a list of
members in a scrollable list, etc.
[11:38] Snowdrop Short: as the view
[11:38] Snowdrop Short: and then there is the control
[11:38] Snowdrop Short: when the user changes something in the UI
[11:39] Snowdrop Short: the view doesn't change the model directly
[11:39] Starky Rubble: makes sense
[11:39] Snowdrop Short: but signals the cange to the controller
[11:39] Snowdrop Short: which then can route the "command" to the
appropriate method in the model
[11:40] Snowdrop Short: and when the model changes, it signals the
controller
[11:40] Snowdrop Short: which signals the view(s)
[11:40] Snowdrop Short: that way everything is well divided, and a
change in the ui, doesn't have to impact any other part of the system
[11:40] Snowdrop Short: that's the essentials of the MVC pattern
[11:41] Snowdrop Short: kind of a standard way to combine classes
[11:41] Starky Rubble: right - it sounds faintly familiar
[11:42] Snowdrop Short: patterns is an attempt to describe all the
well known best practice ways of combining classes
[11:42] Starky Rubble: I see
[11:43] Snowdrop Short: so, in a way, it is for OOP, what data
structures are for functional programming
[11:43] Starky Rubble: ok
[11:43] M1sha Dallin: Sounds good - avoids reinventing the wheel
again
[11:43] M1sha Dallin: if there is a best practice solution
[11:43] Snowdrop Short: the trick of course is getting the idea of
using a certain pattern to solve a problem
[11:44] Starky Rubble: interesting stuff!
[11:44] Snowdrop Short: just like getting the idea of using a certain
data structure to solve a specific problem
[11:44] BlueWall Slade: We have a region south of us now - Seems to
be lagging here a bit
[11:45] Snowdrop Short: a turtle region to boot :-)
[11:45] BlueWall Slade: I'll move us away after class
[11:45] Starky Rubble: Ok my times come - brb
[11:45] Snowdrop Short: okay
[11:46] Snowdrop Short: how are you getting along with c#?
[11:46] BlueWall Slade: I used a java toolkit named Biss-AWT that
used MVC
[11:46] M1sha Dallin: OK 'ish :-)
[11:46] Snowdrop Short: yes, MVC is used pretty much everywhere
[11:47] Snowdrop Short: if you use gnome and gtk, you'll find it all
over the place
[11:47] BlueWall Slade: yes
[11:47] Snowdrop Short: MFC (Microsoft Foundation Classes) has the
same pattern
[11:47] Snowdrop Short: but they just name it differently
[11:48] Snowdrop Short: how would you compare it to Ada?
[11:48] BlueWall Slade: we will be having some classes on the Sloodle
system pretty soon here, you might be interested in that
[11:49] Snowdrop Short nods, when will that be?
[11:49] M1sha Dallin: Difficult to say - some aspects of Ada seem
cleaner - certainly with Ada95
[11:49] Snowdrop Short: I did my compiler way back when ... 91 or 92
I think
[11:50] Snowdrop Short: I didn't like the ' thinge
[11:50] M1sha Dallin: Probably ADA83?
[11:50] Snowdrop Short: probably, I don't remember the version ..
just Ada
[11:51] M1sha Dallin: Enumeration types seem cleaner than C# - but
may just my understanding
[11:51] M1sha Dallin: Ada also had type attributes
[11:51] M1sha Dallin: e.g type'first and type'last
[11:51] M1sha Dallin: which made loops easy
[11:51] Snowdrop Short nods
[11:52] M1sha Dallin: Ada95 added protected types where locking was
automatic
[11:52] Snowdrop Short: c# has locking too
[11:52] Snowdrop Short: we just haven't talked about it, I've been
steering free of threading, so far....
[11:53] M1sha Dallin: You didn't need to do it explicitly in Ada95 -
apart from in a type declaration
[11:53] Snowdrop Short: ok
[11:53] M1sha Dallin: I suspect that you can do everything in either
- some things maybe easier than others
[11:54] M1sha Dallin: so a lot is familiarity
[11:54] Snowdrop Short: me nods, that's true for all turing complete
languages
[11:54] Snowdrop Short: and both Ada and C# are turing complete
[11:54] M1sha Dallin: I'll take your word for that - not heard the
phrase before
[11:55] Snowdrop Short: popularily it means that you can write an Ada
compiler in Ada
[11:55] Snowdrop Short: and a C# compiler in C#
[11:55] M1sha Dallin: Ah ok - yep you can
[11:56] Snowdrop Short: and then you can pretty much build what ever
you need and the language doesn't provide
[11:57] Snowdrop Short: maybe it won't be pretty, but it is possible
[11:57] M1sha Dallin: :-)
[11:57] M1sha Dallin: I think my need is now mainly practice
[11:57] Snowdrop Short: I have the same impression
[11:58] M1sha Dallin: I've got over the hurdle of actually being able
to start reading/writing
[11:58] M1sha Dallin: and in many cases I can work out how to do
something from how I would do it in something else - like Ada
[11:59] M1sha Dallin: but sometimes teh documentation is opaque
[11:59] Snowdrop Short nods
[11:59] Snowdrop Short: the mono documentation is pretty much useless
[11:59] M1sha Dallin: :-)
[11:59] Snowdrop Short: and the microsoft one is lacking in certain
areas too
[11:59] M1sha Dallin: I've found some of Microsofts not worth the
paper it is written on
[12:00] M1sha Dallin: they use a trivial example
[12:00] M1sha Dallin: but not also include a sensible example
[12:00] Snowdrop Short: yes ... or sometimes so trivial it's useless
[12:00] M1sha Dallin: yep
[12:01] Snowdrop Short: but google is your friend
[12:01] BlueWall Slade: I remeber working with the 3.11 dev kit for
windows
[12:01] M1sha Dallin: yep
[12:01] Snowdrop Short: you'll find some good pieces on "Codeproject"
[12:01] BlueWall Slade: had to debug their examples to make the run
[12:01] Snowdrop Short: 3.11 that was the days :)
[12:01] M1sha Dallin: :-(
[12:02] Snowdrop Short: I think I still have "Programming Windows"
some where
[12:02] M1sha Dallin: but I've some code that seems meaningless still
[12:02] BlueWall Slade: I have it here - about to toss it
[12:02] M1sha Dallin: I located a getopt lookalike in C#
[12:02] M1sha Dallin: used attributes?
[12:02] M1sha Dallin: code in [] brackets
[12:03] Snowdrop Short: yes, that's usually attributes
[12:03] M1sha Dallin: it ran - but I've no idea why or how
[12:03] Snowdrop Short: we'll just like I've been steering clear of
threading so far...
[12:03] Snowdrop Short: there are a few other things I still need to
cover
[12:03] M1sha Dallin: thought so :-)
[12:03] Snowdrop Short: Attributes are some
[12:04] Snowdrop Short: extension classes and lamba expressions are
another
[12:04] Snowdrop Short: there is a really neat getopt impementation
[12:04] Snowdrop Short: but it relies on linq and lamda
[12:05] Snowdrop Short: if you're not familiar with that, then it
will appear to be black magic
[12:05] M1sha Dallin: not sure if that was the one I found
[12:05] M1sha Dallin: The good news was that it was in its own
namespace
[12:05] M1sha Dallin: I could just use it
[12:06] M1sha Dallin: and it did what it said it would do
[12:07] Snowdrop Short:
http://www.ndesk.org/Options
[12:07] Snowdrop Short: that's the one I'm thinking of
[12:07] M1sha Dallin: Not the one I found
[12:08] Snowdrop Short: ok
[12:09] M1sha Dallin: That one looks good
[12:09] Snowdrop Short: the one on ndesk is pretty elegant
[12:09] Snowdrop Short: ok .. maybe we should get started
[12:09] M1sha Dallin: ok
[12:09] Snowdrop Short: it's 20:00 GMT/UTC
[12:10] Snowdrop Short: let me just load some code up on pastebin....
[12:13] Snowdrop Short: today .. I have to admit that I haven't been
telling the complete truth about classes in c#
[12:13] M1sha Dallin: :-)
[12:13] M1sha Dallin: There is always another side
[12:13] Snowdrop Short: I've skipped some of it, and I think we need
to go back and take a closer look
[12:13] Snowdrop Short:
http://www.pastebin.ca/1378241
[12:14] Snowdrop Short: but first a little intro code
[12:14] Snowdrop Short: if you look at the code
[12:14] Snowdrop Short: it is pretty simple
[12:15] M1sha Dallin: What does new int() do?
[12:15] Snowdrop Short: that's part of what I want to explore
[12:15] Snowdrop Short: int is a well known thing in the c# compiler
[12:16] Snowdrop Short: so when it encounters something like:
[12:16] Snowdrop Short: int i = 0;
[12:16] Snowdrop Short: then it goes off and implicitly creates a
variable
[12:16] Snowdrop Short: actually the same thing as is written in line
10
[12:17] Snowdrop Short: only in line 10 it is made explicit
[12:17] M1sha Dallin: ok - returns a null value?
[12:17] Snowdrop Short: default value
[12:17] M1sha Dallin: ok
[12:18] Snowdrop Short:
http://www.pastebin.ca/1378243
[12:18] Snowdrop Short: actaully this is even more explicit
[12:18] M1sha Dallin: and 9 and 10 are equivalent?
[12:18] Snowdrop Short: yes
[12:19] Snowdrop Short: but are assigned the default value of an int
[12:19] M1sha Dallin: yep
[12:19] Snowdrop Short: which is 0
[12:19] M1sha Dallin: ok
[12:19] Snowdrop Short: but what would happen if I introduced a new
line after 10
[12:20] Snowdrop Short: saying "i = null;"
[12:20] Snowdrop Short: I would get a compiler error
[12:20] M1sha Dallin: There is an int? which includes a null?
[12:21] M1sha Dallin: Seem to remember something from somewhere
[12:21] Snowdrop Short: yes, "int?" accepts null
[12:21] Snowdrop Short: but "int" doesn't
[12:21] M1sha Dallin: ok
[12:21] Snowdrop Short: the thing is, only handles to classes can be
assigned the value "null"
[12:22] Snowdrop Short: i and j are not handles to classes
[12:22] Snowdrop Short: but rather handles to something called a
value type
[12:22] M1sha Dallin: ok - I remember reading something about that
[12:23] Snowdrop Short: when I do an assignment like "i = j"
[12:23] Snowdrop Short: then it isn't handles to values which are
being moved, but rather the actual values
[12:23] M1sha Dallin: ok
[12:24] Snowdrop Short: all simple types, like bool, byte, short,
int, long, decimal are value types
[12:25] Snowdrop Short: so when assignments are made, it is the
values being shuffled around rather than handles to their values
[12:25] Snowdrop Short: but more complex types can be valuetypes as
well
[12:25] Snowdrop Short: we've already met one
[12:25] Snowdrop Short: "Guid"
[12:26] Snowdrop Short: guid isn't class, or backed by an object, but
rather a value type
[12:26] Snowdrop Short: so when you assign one guid to another, all
16 bytes are copied
[12:26] M1sha Dallin: ok
[12:27] M1sha Dallin: that must be marginal - presumably an address
is smaller
[12:27] M1sha Dallin: so a handle would be quicker
[12:27] Starky Rubble: gotta be just about the biggest value type
[12:27] Snowdrop Short: yes, a handle would be quicker, but then the
semantics of assignment would be different
[12:28] Snowdrop Short: and that's actually the key to defining when
a value type is better than a class
[12:28] Snowdrop Short: most of the time, a class is the best thing
[12:29] Snowdrop Short: but sometimes, you have rather small data
structures, and what really should be moved during assignment is the
value rather than the handle
[12:29] M1sha Dallin: ok
[12:29] Snowdrop Short: so if you wanted to implement that using
classes and object, you'd need to implement a copy function
[12:30] Snowdrop Short: which would copy all the values
[12:30] M1sha Dallin: seems logical for up to 8 bytes at least
[12:30] Snowdrop Short: that grows complicated as the nesting
hierarchy gets deeper
[12:31] Snowdrop Short: take another example (the traditional one) ,
complex numbers
[12:31] Snowdrop Short: or simple 2, 3 or 4 dimensional vectors
[12:31] M1sha Dallin: yep
[12:31] Snowdrop Short: for that purpose, c# has the struct keyword
[12:32] M1sha Dallin: similarity with K&R C ?
[12:32] Snowdrop Short: yes
[12:32] Snowdrop Short: a lot
[12:33] M1sha Dallin: ok
[12:33] Snowdrop Short:
http://www.pastebin.ca/1378259
[12:33] BlueWall Slade is Offline
[12:33] Snowdrop Short: here is an example of a struct
[12:33] M1sha Dallin: ok
[12:34] M1sha Dallin: essentially defining a record structure
[12:34] Starky Rubble: yes
[12:34] Snowdrop Short: yes
[12:34] Starky Rubble: with a default value
[12:34] Snowdrop Short: as a value type
[12:34] Starky Rubble: right
[12:35] Snowdrop Short: yes, right now it will be the float 0.0 for
all three values
[12:35] Snowdrop Short: so any assignment made will not copy a handle
to the data, but rather the actual values
[12:35] Snowdrop Short: in this case 12 bytes
[12:35] M1sha Dallin: ok
[12:35] Snowdrop Short: other than that
[12:36] Snowdrop Short: you can do almost all the same things with
structs as you can with classes
[12:36] Snowdrop Short: you can define new methods
[12:36] Snowdrop Short: like dot product
[12:36] Snowdrop Short: or anythings else which makes sense
[12:37] M1sha Dallin: useful
[12:37] Snowdrop Short: even constructors
[12:37] Snowdrop Short: but with one limitation
[12:38] Snowdrop Short: if you have a constructor, it *must* assign
an intial value to all members
[12:38] M1sha Dallin: ok - that isn't necessary witha normal class
[12:39] M1sha Dallin: can it have side effects?
[12:39] Snowdrop Short: side effects ?
[12:39] Snowdrop Short: how?
[12:40] M1sha Dallin: In a normal class constructor you might create
instances of something else as well
[12:40] Snowdrop Short:
http://www.pastebin.ca/1378273
[12:40] Snowdrop Short: I think you can.. I've never tried, but I'd
be surprised if you couldn't
[12:41] M1sha Dallin: ok - it may not be wise however :-)
[12:41] M1sha Dallin: will the last pastebin compile?
[12:41] M1sha Dallin: initX not givem
[12:42] Snowdrop Short: yes, because the default contructor will
always exist on value types
[12:42] Starky Rubble: yes it runs
[12:42] Snowdrop Short:
http://www.pastebin.ca/1378276
[12:43] Snowdrop Short: ok, I just tried, creating an instance of
MainClass in the constructor
[12:43] Starky Rubble: yes... it looks eveil but it runs
[12:43] M1sha Dallin: a side effect - I think my head will hurt with
this one
[12:43] Starky Rubble: evil even
[12:44] Snowdrop Short: yes
[12:44] Snowdrop Short: side effects can be evil
[12:44] Snowdrop Short: but necessary some times
[12:45] Snowdrop Short: so with our current knowledge we need to
revisit the "out" and "ref" qualifiers
[12:46] M1sha Dallin: out i snormally passing by value - ref is
passing the handle
[12:47] Snowdrop Short: both ref and out is passing a handle to the
data
[12:48] Snowdrop Short: but out does not allow reading of the content
[12:48] Snowdrop Short: it is only outputted never read
[12:48] Snowdrop Short: and ref is both in and out
[12:48] Snowdrop Short:
http://www.pastebin.ca/1378282
[12:49] Snowdrop Short: here is a little example
[12:49] Starky Rubble: right
[12:50] Snowdrop Short: without the "out" parameter the value of "c"
wouldn't be changed in line 27
[12:50] M1sha Dallin: ok
[12:51] Snowdrop Short: but ... here is the catch, which I skipped
last we talked about about "out" and "ref"
[12:51] Snowdrop Short: only simple values are controlled by the
"ref" and "out" declarations
[12:52] Snowdrop Short: I can change any member value
[12:52] Snowdrop Short: so if I did this....
[12:53] Snowdrop Short:
http://www.pastebin.ca/1378287
[12:54] Snowdrop Short: i.e passing Old value ... what do you think
will happen?
[12:55] M1sha Dallin: It would change the value of v.y?
[12:56] Snowdrop Short: will it?
[12:56] M1sha Dallin: Personally I would have hoped not
[12:56] Snowdrop Short: since "Vec3" is a value type
[12:57] Snowdrop Short: the value is copied when calling any method
[12:57] Snowdrop Short: here is an example where the values are
printed
[12:59] Snowdrop Short:
http://www.pastebin.ca/1378293
[12:59] Snowdrop Short: if you run it .. you'll notice that the value
hasn't changed
[13:00] Snowdrop Short: try running it
[13:00] Starky Rubble: 0,0,0
[13:00] M1sha Dallin: yep - no change
[13:00] Snowdrop Short: ok .. now try to add a "ref" to the
constructor
[13:01] Snowdrop Short: remember both the constructor and the call
needs that declaration
[13:02] Snowdrop Short: ups
[13:02] Snowdrop Short: programming error in "Print"
[13:02] Snowdrop Short: it says "x,z,z" is should say "x,y,x"
[13:02] Snowdrop Short: x,y,z .... even
[13:03] Snowdrop Short: but the results still hold
[13:04] Snowdrop Short: now ... if I changed the code back, i.e.
removed the ref
[13:04] Snowdrop Short: and then switch from a "struct" to a "class"
what would happen?
[13:05] Starky Rubble: yikes
[13:05] Snowdrop Short:
http://www.pastebin.ca/1378300
[13:06] Snowdrop Short: and you can see
[13:06] Snowdrop Short: the rules change
[13:06] Snowdrop Short: suddenly the parameter is a reference type
and not a value type
[13:06] Snowdrop Short: and can be changed
[13:07] M1sha Dallin: ok
[13:07] Snowdrop Short: only the handle it self cannot be changed in
the method
[13:07] Snowdrop Short: I admit freely that I'm still withholding a
bit of information
[13:07] Snowdrop Short: about value types
[13:08] M1sha Dallin: :-)
[13:08] Snowdrop Short: but essentially there is no real handles to
value types
[13:08] Snowdrop Short: they are simply passed by value from method
to method
[13:09] Starky Rubble: ok
[13:10] Snowdrop Short: that difference between value types and
reference types is the cause of quite a few problems
[13:10] M1sha Dallin: I can imagine
[13:10] Snowdrop Short: if you believe that you are working on a
reference type, and change some value in a method
[13:10] Snowdrop Short: you can get hurt, if it turns out to be a
value type
[13:10] Snowdrop Short: and vice versa
[13:11] Starky Rubble: I can see that one might
[13:11] Starky Rubble: do that
[13:12] Snowdrop Short: you see that a member is changed in some
method
[13:12] Snowdrop Short: but when leaving the method the change is
suddenly gone
[13:12] Starky Rubble: right
[13:13] Snowdrop Short: if you don't think about value/reference
types you are up to a surprise
[13:13] Starky Rubble: could get ugly lol
[13:13] M1sha Dallin: yep
[13:13] Snowdrop Short: but for small simple values, structs can have
some benefits
[13:14] Snowdrop Short: some of you may be used to unions
[13:14] M1sha Dallin: yep
[13:14] Snowdrop Short: i.e. two different types of data, residing in
the same memory space
[13:14] Starky Rubble: yes
[13:14] Snowdrop Short: sometimes it is also refered to as "variant
records"
[13:15] Snowdrop Short: that concept doesn't really exist in c# or
any other managed language
[13:15] Snowdrop Short: at least not without going through some nasty
hoops
[13:16] Snowdrop Short: and in worst case, that kind of think can
cause a hard crash
[13:16] Starky Rubble: ouch
[13:17] Snowdrop Short: where even the runtime engine crashes
[13:17] Snowdrop Short: so.. for the moment forget about unions
[13:17] Starky Rubble: good
[13:17] M1sha Dallin: :-)
[13:17] Snowdrop Short: use inheritance to get a similar
functionality
[13:18] Snowdrop Short: and remember .. structs can inherit from
structs :-)
[13:19] Snowdrop Short: ok .. that's it for value types
[13:19] M1sha Dallin: phew :-)
[13:19] Snowdrop Short: before we move on...
[13:19] Snowdrop Short: I'd like to know if you have any questions
[13:19] M1sha Dallin: I'm OK I think
[13:19] Starky Rubble: nope
[13:20] Snowdrop Short: ok
[13:20] Snowdrop Short: then I'd like to talk abit about extension
methods
[13:21] Snowdrop Short: it is a relatively new feature
[13:21] Snowdrop Short: wich became part of c# in version 3
[13:21] Snowdrop Short: but since Mono 2.4 was just released
yesterday
[13:21] Snowdrop Short: it is available on both mono and .net
[13:22] Starky Rubble: heh - timely lol
[13:22] Snowdrop Short: well, there was some support for c# 3.0 in
2.2 mono
[13:22] Snowdrop Short: but it is complete now
[13:22] Snowdrop Short: except for some framework classes
[13:23] Snowdrop Short: extension methods ... are just that
[13:23] Snowdrop Short: lets say you are working on some thing
[13:23] Snowdrop Short: and decide that it would be really really
neat if the "string" class had some special method
[13:24] Snowdrop Short: like "ToCamelCase()"
[13:24] Snowdrop Short: or some other thing
[13:24] Snowdrop Short: you have two choices
[13:24] Snowdrop Short: you can subclass "string"
[13:25] Snowdrop Short: and create a new class, which inherits from
string and then has your special "ToCamelCase()"
[13:25] Snowdrop Short: or ... with c#
[13:26] Snowdrop Short: you can extend the string class
[13:26] Snowdrop Short: i.e. add a new method to the existing class
[13:27] Snowdrop Short: hold on .. pastebinning
[13:30] Snowdrop Short: ok
[13:30] Snowdrop Short: of all times for my dev environment to die on
me
[13:30] Snowdrop Short: ok .. I'll do something else
[13:31] Starky Rubble: :-(
[13:31] Snowdrop Short:
http://www.pastebin.ca/1378326
[13:31] Snowdrop Short: this one is from MSDN
[13:31] Snowdrop Short: in order to get this to run, you need to add
a reference
[13:32] Snowdrop Short: to "System.Core"
[13:32] Snowdrop Short: do you know how to do that?
[13:32] Starky Rubble: no
[13:33] Snowdrop Short: ok ...
[13:33] Starky Rubble: using?
[13:33] Snowdrop Short: in your project, there will be a folder
called "refences"
[13:33] Starky Rubble: yes
[13:33] Snowdrop Short: if you right click on it you'll get a choice
for "Add reference" or something like that
[13:34] Snowdrop Short: find the name "System.Core" ... and checkmark
it
[13:34] Snowdrop Short: then click ok
[13:34] Snowdrop Short: that way the c# compiler will include the
classes in that dll to you program when it is compiling
[13:34] Snowdrop Short: it might already be there
[13:35] Snowdrop Short: I believe c# express does that by default
[13:35] Starky Rubble: oh yes ok
[13:36] Snowdrop Short: there are certain limitiations on extension
classes
[13:36] Snowdrop Short: they must *always* be static
[13:37] Snowdrop Short: and the key to identifying that it is an
extension method is the use of "this" in the parameter list
[13:37] Snowdrop Short: public static int WordCount(this String str)
[13:37] Starky Rubble: ok
[13:37] Snowdrop Short: the "this string str"
[13:37] Snowdrop Short: tell us it is an extension method to the
string class
[13:38] Starky Rubble: ok
[13:38] Snowdrop Short: and once that's defined, you can write code
wich says "Hello World".WordCount()
[13:39] M1sha Dallin: ok
[13:39] Snowdrop Short:
http://dotnetext.codeplex.com/
[13:40] Snowdrop Short: is a site
[13:40] Snowdrop Short: with a collection of different neat extension
methods
[13:41] M1sha Dallin: ok
[13:41] Starky Rubble: make simple tasks simpler
[13:41] Snowdrop Short: some people enjoy doing the weirdest things
[13:42] Snowdrop Short: like writing huge extensions to existing
standard classes
[13:42] Snowdrop Short: later on we'll revisit extension classes
[13:43] Snowdrop Short: but for now, it is enough to know that they
exist
[13:43] Starky Rubble: ok
[13:43] Snowdrop Short: and that we know how to use them
[13:43] M1sha Dallin: ok
[13:44] Snowdrop Short: if you search for "extension methods" on the
web, you'll find all sorts of interesting extension methods
[13:44] Snowdrop Short: remember our Easter calculation from way back
when?
[13:45] M1sha Dallin: yep
[13:45] Starky Rubble: yes
[13:46] Snowdrop Short: with what we have now, we can actually create
an extension method, which will operate on a DateTime value and return
the date of easter sunday for that year
[13:46] Michael Skelito is Offline
[13:47] Starky Rubble: ok lol
[13:48] Snowdrop Short: so .. the question now becomes, when would
you go for a subclassing strategy and when would you go for an
extension method?
[13:48] Starky Rubble: well if static is inappropriate...
[13:49] Starky Rubble: I dunno - when would you?
[13:49] M1sha Dallin: If the new methid is self contained?
[13:49] M1sha Dallin: doesn't need to build on anything else perhaps
[13:50] Starky Rubble: ah I see what you mean
[13:50] Snowdrop Short: well, it really is a matter of personal
preferences
[13:50] Snowdrop Short: but some pointers could be:
[13:51] Snowdrop Short: you already have a ton of code, which uses,
lets say "string", and now you are faced with a change
[13:51] Snowdrop Short: if you subclass string, then you need to
change the declarations of string all over the place
[13:51] Starky Rubble: ok
[13:52] Snowdrop Short: to the name you gave your subclass
[13:52] Snowdrop Short: in that case, it would often be easier to
"just" implement an extension method
[13:52] M1sha Dallin: ok
[13:52] Snowdrop Short: but ... if you needed to store and additional
value along with the string
[13:53] Snowdrop Short: then you'd be in trouble, because the
extension method needs to be static
[13:53] Starky Rubble: right
[13:53] Snowdrop Short: so ... if the "subclass" would be very small,
and didn't need to carry additional data, only add new methods
[13:54] M1sha Dallin: I must go Snowdrop
[13:54] Snowdrop Short: then an extension method might be better,
especially if you have a lot of code referencing the class already
[13:54] Snowdrop Short: yes... time for me as well
[13:54] Starky Rubble: like the string manipulations we just looked
at
[13:54] M1sha Dallin: ty for class
[13:54] Snowdrop Short: yes
[13:54] Snowdrop Short: it is a good example
[13:55] Snowdrop Short: so ... to finish up..
[13:55] Snowdrop Short: something to be used wisely
[13:55] M1sha Dallin: Bye all
[13:55] M1sha Dallin is Offline
[13:55] Snowdrop Short: and next time will be right after the meeting
[13:55] Starky Rubble: ok bye and thanks Snowdrop
[13:55] Snowdrop Short: at 20.00 BMT
[13:55] Snowdrop Short: bye Starky
[13:55] Starky Rubble: heh
[13:55] Snowdrop Short: have a nice day
http://www.pastebin.ca/1378241
using System;
namespace Generics
{
class MainClass
{
public static void Main(string[] args)
{
int i = 0;
int j = new int();
}
}
}
http://www.pastebin.ca/1378243
using System;
namespace Generics
{
class MainClass
{
public static void Main(string[] args)
{
int i = default(int);
int j = new int();
}
}
}
http://www.pastebin.ca/1378259
using System;
namespace Generics
{
public struct Vec3
{
public float x,y,z;
}
class MainClass
{
public static void Main(string[] args)
{
int i = default(int);
int j = new int();
Vec3 v = new Vec3();
}
}
}
http://www.pastebin.ca/1378273
using System;
namespace Generics
{
public struct Vec3
{
public float x,y,z;
public Vec3(float initX)
{
x = initX;
y = 0.0f;
z = 0.0f;
}
}
class MainClass
{
public static void Main(string[] args)
{
int i = default(int);
int j = new int();
Vec3 v = new Vec3();
}
}
}
http://www.pastebin.ca/1378276
using System;
namespace Generics
{
public struct Vec3
{
public float x,y,z;
public Vec3(float initX)
{
x = initX;
y = 0.0f;
z = 0.0f;
MainClass c = new MainClass();
}
}
class MainClass
{
public static void Main(string[] args)
{
int i = default(int);
int j = new int();
Vec3 v = new Vec3();
Vec3 w = new Vec3(2.0f);
}
}
}
http://www.pastebin.ca/1378282
using System;
namespace Generics
{
public struct Vec3
{
public float x,y,z;
public Vec3(float initX, out MainClass a)
{
x = initX;
y = 0.0f;
z = 0.0f;
a = new MainClass();
}
}
public class MainClass
{
public static void Main(string[] args)
{
int i = default(int);
int j = new int();
Vec3 v = new Vec3();
MainClass c;
Vec3 w = new Vec3(2.0f, out c);
}
}
}
http://www.pastebin.ca/1378287
using System;
namespace Generics
{
public struct Vec3
{
public float x,y,z;
public Vec3(float initX, out MainClass a, Vec3 old)
{
x = initX;
y = 0.0f;
z = 0.0f;
a = new MainClass();
old.y = 4.0f;
}
}
public class MainClass
{
public static void Main(string[] args)
{
int i = default(int);
int j = new int();
Vec3 v = new Vec3();
MainClass c;
Vec3 w = new Vec3(2.0f, out c, v);
}
}
}
http://www.pastebin.ca/1378293
using System;
namespace Generics
{
public struct Vec3
{
public float x,y,z;
public Vec3(float initX, out MainClass a, Vec3 old)
{
x = initX;
y = 0.0f;
z = 0.0f;
a = new MainClass();
old.y = 4.0f;
}
public void Print()
{
Console.WriteLine("(x,y,z) = ({0}, {1}, {2})", x, z, z);
}
}
public class MainClass
{
public static void Main(string[] args)
{
int i = default(int);
int j = new int();
Vec3 v = new Vec3();
MainClass c;
Vec3 w = new Vec3(2.0f, out c, v);
v.Print();
}
}
}
http://www.pastebin.ca/1378300
using System;
namespace Generics
{
public class Vec3
{
public float x,y,z;
public Vec3()
{
}
public Vec3(float initX, out MainClass a, Vec3 old)
{
x = initX;
y = 0.0f;
z = 0.0f;
a = new MainClass();
old.y = 4.0f;
}
public void Print()
{
Console.WriteLine("(x,y,z) = ({0}, {1}, {2})", x, y, z);
}
}
public class MainClass
{
public static void Main(string[] args)
{
int i = default(int);
int j = new int();
Vec3 v = new Vec3();
MainClass c;
Vec3 w = new Vec3(2.0f, out c, v);
v.Print();
}
}
}
http://www.pastebin.ca/1378326
namespace ExtensionMethods
{
public static class MyExtensions
{
public static int WordCount(this String str)
{
return str.Split(new char[] { ' ', '.', '?' },
StringSplitOptions.RemoveEmptyEntries).Length;
}
}
}