|
Anyone learning C# should be taught OO principles right from the start, as it's an OO language and you can't understand how to do anything beyond the trivial without getting it.
|
|
|
|
|
Good answer, I think your reasoning is spot on.
|
|
|
|
|
Hi Bill,
All comments are always welcome, whether in agreement or not. A sensible discussion of the different ways this can be approached can only be beneficial to the OP
BillWoodruff wrote: From an OO point of view, what is modeled in this scenario, imho, is not a 'pizza,' but a process which takes a pizza-spec as an input, and returns certain calculated data useful to the pizza-creator
Hmm.. possibly but as we need to get more than one calculation (slices, area, area per slice) from just one specified diameter then an instance that is essentially a diameter wrapper makes more sense to me.
BillWoodruff wrote: our consistent use of Public properties as a substitute for methods/functions is interesting
You are quite correct, CalculateSlices() etc methods may be more 'normal'. Where the object is immutable, therefore the methods will always return the same value for a given instance, I always feel that properties are more suited. This is just a personal thing and I have never really thought about it - it's just what I do naturally in that situation.
BillWoodruff wrote: mho people vary greatly in the extent to which they "take naturally" to OO programming
Undoubtedly, but that normally stems from any pre-existing experience and/or the way they are initially taught. IMO there is no reason not to introduce very basic OOP from the outset rather than trying to lay it on afterwards.
|
|
|
|
|
Hi, I appreciate your thoughtful response !
I am reminded of many years ago when I created the first computer educational program for the French-American bi-lingual school in San Francisco (oh yeah, Apple II's, floppy disks, Logo ... and finally ... after a 'revolt' by parents ... I was forced to switch to Basic).
I had students from age eight- to sixteen+.
It fascinated me to observe that some children as early as age eight could easily understand the idea of recursion, and others, as old as sixteen, seemed to encounter the proverbial "brick wall" trying to "get it."
Years later, as an educator of adults, I observed similar differences in abilities of people to grok OO vs. procedural code, as well as recursion.
This thread is not the place to get into educational pedagogy, but I am a fan of Steven Pinker's (MIT) view of innate cognitive styles particularly as expressed in "The Blank Slate"[^].
While I do not believe a given person's innate cognitive styles are some 'fixed constellation' of traits, and I am a definite optimist about any individual's capability to change, I do believe that in terms of content and message, education does need to be informed by the idea "one size does not fit all."
By the way, I am a fan of George Spindler's (Stanford, retired long ago) work on discontinuities in the process of socialization as a stimulus to cognitive development.
On a practical level, this might mean that if I were designing an educational curriculum, I might have students learn some absolutely rigid strongly typed procedural language for six months, and then switch them to Lisp; and then, when they recovered from that, maybe Eiffel or F#
Please take all this with a large "grain of salt," since you are hearing from someone who started programming at age 41 after a lifetime in the liberal arts, academic social sciences, and psychotherapy ... and whose first language was 6809 assembly, followed by Lisp, and then ... PostScript
And now ... well ... to me .NET and C# are ... the best ... of all possible worlds.
best, Bill
"Use the word 'cybernetics,' Norbert, because nobody knows what it means. This will always put you at an advantage in arguments." Claude Shannon (Information Theory scientist): letter to Norbert Weiner of M.I.T., circa 1940
|
|
|
|
|
I rather agree with Davey on the use of properties here – when the values you want to read are uniquely specified by the current state of the object, and reading them has no side effects and does not require extensive processing*, a property is appropriate. As it happens, they are implemented as dynamic calculations, but logically those values are part of the state (you could set them when you modify the state, i.e. the diameter) and so querying them is querying the object state, which is what properties are for.
(*: This is one of those things that, in principle, shouldn't matter, but if you call a property getter you expect that to be almost free in terms of time, so it does. Also, as an aside, I once wrote an XML class which constructed the entire DOM tree when you assigned its Text property. I think that's probably abuse, although the rules for a property setter are more relaxed; setting a property can cause extensive recalculation and side effects such as data binding and screen refreshes.)
Toppings are not part of the problem space, the class could easily be extended to other facets of pizzas if they became relevant to the business case in future.
imho people vary greatly in the extent to which they "take naturally" to OO programming, and, depending on the person, or group, developing the ability to write good solid procedural code in the classic get inputs => calculate => create outputs is a good foundation to build on.
I disagree with you here. Procedural programming and OO programming are quite different in approach, and if you're learning an OO language (which almost everyone is and should be these days) you should be starting out down the OO road. Otherwise you end up with people writing procedural spaghetti, like half of what we see in Q&A. You need to know the language fundamentals (like flow of control statements which seems to be what the OP is learning at the moment) but the way in which you structure your approach to solving a problem is very important and needs to be introduced right at the start, in my opinion.
|
|
|
|
|
Hi Bob, Points well taken; I'm not on a jihad to keep Properties pure Although it's my 'style,' for whatever that's worth, to separate out methods and properties. And, for new students to OO, I think it's worth keeping them rather distinct ... at first.
I will comment that one way this problem as stated, is not 'real-world' is that in this scenario pizzas can vary in diameter.
In any actual 'pizza-prep' solution, there would be a finite set of baking pans of certain sizes and areas/slices could/should all be calculated in advance, and just returned by 'look-ups.'
When I look at QA questions, I see just as many OO equivalents to procedural spaghetti-code (... mmm ... what's the right moniker for that ?).
imho someone taught procedural coding in a structured, modern, style, and who internalizes/masters key principles like 'divide and conquer,' refactoring, and debugging, should not be 'tarred and feathered' with bugaboo accusations of spaghetti-witchcraft.
To focus back on pizza: I can see a procedural solution to the scenario here, but then a transition to an object model when the scenario is expanded to include multiple overlapping pizza-orders, and to deal with the problem of how to allocate the finite supply of baking pans, and the oven space, to optimize speed-of-delivery so pizzas with maximum profit margin are ready first This being the MOO approach (Machiavellian Object Oriented).
For some people whose innate cognitive styles make their plunge into OO difficult (see my remarks in response to DaveyM69 today), I think that learning procedural programming well gives them a sense of efficacy, and confidence, that then makes their transitioning to OO much easier.
best, Bill
"Use the word 'cybernetics,' Norbert, because nobody knows what it means. This will always put you at an advantage in arguments." Claude Shannon (Information Theory scientist): letter to Norbert Weiner of M.I.T., circa 1940
|
|
|
|
|
Nowhere in the instructions posted does it say anything about constants. The only possible constants are the Minimum and Maximum diameters.
The only place you are instructed to use if/else if is in determining the number of slices.
All the code in the class could be done in a procedural way instead (without the class) using a method level variable diameter obtained from the user input. Just use the code in the relavant property getters.
|
|
|
|
|
|
Only partially - he still has to get the user input, validate it successfully (TryParse anyone?), display as instructed and then loop if required.
Also, hopefuly it will teach him something about OOP, so more of a lesson IMO. The stuff I've done is just simple maths - if he can't work that out for himself if he needs it again then he'll fail anyway - sooner rather than later.
|
|
|
|
|
Do you have an idea of where you are "stuck" here: is the difficulty figuring out how to write the if/then/else statements required ?
What's your goal here: just to get a working solution, or to explore and learn so in the future you can create solutions for many types of problems ?
best, Bill
"Use the word 'cybernetics,' Norbert, because nobody knows what it means. This will always put you at an advantage in arguments." Claude Shannon (Information Theory scientist): letter to Norbert Weiner of M.I.T., circa 1940
|
|
|
|
|
This is pretty straightforward, and having someone give you the answer is much less valuable than you going back and reading over the control structures part of your course so you can do it. Flow of control (if/else, switch and loops) are fundamental to programming (at least in a conventional language) and you need to understand them – when you do, this exercise is trivial.
Since I need to get some silliness out of the way before production code catches it, here is a tongue-in-cheek version of the logic (which will probably fail your test, heh):
double area = diameter * diameter * 0.25 * Math.Pi;
int slices = diameter < 12 ? 0 :
diameter < 16 ? 8 :
diameter < 24 ? 12 :
diameter < 30 ? 16 :
diameter < 36 ? 24 : 0;
if(slices == 0) throw new ArgumentException("Size out of range");
double sliceArea = area / slices;
Or how about
int[][] sliceMap = {{12, -1},{16, 8},{24, 12},{30, 16},{36,24}};
int slices = -1;
foreach(int[] mapping in sliceMap){
if(diameter < mapping[0]){ slices = mapping[1]; break; }
}
if(slices < 0) throw new ArgumentException("Size out of range");
Remember, don't hand something like this in . Go and read about if/else since that's clearly what the exercise is checking.
|
|
|
|
|
We are using below method to convert byte array into bitmap . we have successfully converted 16,24,32 etc. Pixel formats but we are facing issue while converting 4 and 8 pixel formats image is rendering in blur format and image starting and ending positions are changed.
///
/// Converting the raw data into bitmap
///
/// <param name="buffer" />Byte array of the image rawdata
/// <param name="nWidth" />Image width
/// <param name="nHeight" />Image height
/// <param name="nBitCount" />Image Pixel format
/// <returns>
internal Bitmap ConvertRawDataToBitMap(byte[] buffer, int nWidth, int nHeight, int nBitCount,PDIB pDIB=null)
{
Size imageSize = new Size(nWidth, nHeight);
PixelFormat imagePixelFormat = GetPixelFormat(nBitCount);
Bitmap bitmap = new Bitmap(imageSize.Width, imageSize.Height, imagePixelFormat);
Rectangle wholeBitmap = new Rectangle(0, 0, bitmap.Width, bitmap.Height);
BitmapData bitmapData = bitmap.LockBits(wholeBitmap, ImageLockMode.WriteOnly, imagePixelFormat);
//Marshal.Copy(buffer, 0, bitmapData.Scan0, buffer.Length);
Marshal.Copy(buffer, 0, bitmapData.Scan0, bitmapData.Stride * bitmap.Height);
bitmap.UnlockBits(bitmapData);
bitmap.RotateFlip(RotateFlipType.Rotate180FlipX);
return bitmap;
}
///
/// Returns the pixel format from given bit count.
///
/// <param name="nPixelBitCount" />Pixel bit count example 4 or 8 or 16 or 24 ..etc
/// <returns>
private PixelFormat GetPixelFormat(int nPixelBitCount)
{
PixelFormat pixelFormat = PixelFormat.Undefined;
switch (nPixelBitCount)
{
case 4:
pixelFormat = PixelFormat.Format4bppIndexed;
break;
case 8:
pixelFormat = PixelFormat.Format8bppIndexed;
break;
case 16:
pixelFormat = PixelFormat.Format16bppRgb555;
break;
case 24:
pixelFormat = PixelFormat.Format24bppRgb;
break;
case 32:
pixelFormat = PixelFormat.Format32bppRgb;
break;
case 48:
pixelFormat = PixelFormat.Format48bppRgb;
break;
case 64:
pixelFormat = PixelFormat.Format64bppArgb;
break;
default:
pixelFormat = PixelFormat.Undefined;
break;
}
return pixelFormat;
}
Please help me to find the solution.
Thanks in Advance
Madhava Reddy, Madhu
|
|
|
|
|
Those formats are indexed, as the name implies. You need to provide a palette as well.
Where is the data coming from? Does it have palette information on the front? The pixel mismatch looks like you are not starting at the right place in the data array.
|
|
|
|
|
We tried using palette information eventhough we faced same issue.
Here is the code used to assign palatte
ColorPalette palette = bitmap.Palette;
for (int i = 0; i < palette.Entries.Length; i++)
{
int
cval = 17 * i;
palette.Entries[i] = Color.FromArgb(0, cval, cval, cval);
}
bitmap.Palette = palette;
Instead of palette.Entries.Length we also tried giving 256.
Thanks for the reply.
|
|
|
|
|
We tried using palette information eventhough we faced same issue.
here is the code used to assign palatte
ColorPalette palette = bitmap.Palette;
for (int i = 0; i < palette.Entries.Length; i++)
{
int cval = 17 * i;
palette.Entries[i] = Color.FromArgb(0, cval, cval, cval);
}
bitmap.Palette = palette;
Instead of palette.Entries.Length we also tried giving 256.
Thanks for the reply.
|
|
|
|
|
Hi Guys,
How to Programatically find the name application pool of an application.
Thanks
Yaju
|
|
|
|
|
Does this[^] article help?
/ravi
|
|
|
|
|
hi Ravi
The article you mentioned gives me list of all application pools configured but what i am looking for is a way to programatically find out the application pool in which my application is residing.
Thanks
Yaju
|
|
|
|
|
If you scroll towards the bottom you'll see the example titled "I use this code snippet to get the application pool in which my website is running." Hope that helps.
/ravi
|
|
|
|
|
i need to get machine localization in my website.
i change my machine localization ("Regional and Language Options" control panel.)
and check with below code but always it shows as 'en_US'..
string strCluture = CultureInfo.CurrentCulture.Name;
what i need to do to get current localization. am i missing some setting or what?
|
|
|
|
|
Mugdha_Aditya wrote: i change my machine localization ("Regional and Language Options" control panel.)
and check with below code but always it shows as 'en_US'..
string strCluture = CultureInfo.CurrentCulture.Name;
what i need to do to get current localization. am i missing some setting or what?
Did you restart your application after you changed the setting? The CultureInfo is set for the app when it starts, and (luckily) doesn't change while running - even if the user changes it. The new CultureInfo should be displayed after you start your app.
Mugdha_Aditya wrote: i need to get machine localization in my website.
Care to explain a bit? You're fetching the culture of the webserver, not of the connected clients.
Bastard Programmer from Hell
|
|
|
|
|
Hey...
Thanks for the your reply.
I have restarted my application as well as my pc.
still its not applying selected culture.
|
|
|
|
|
Apart from CurrentCulture , there is also CurrentUICulture .
Since you're talking about a web site, do not forget to set the CurrentUICulture to the desired value whenever a new thread (!) is started - otherwise your web site will always run in the localization of your web server.
E.g.
System.Threading.Thread.CurrentThread.CurrentUICulture = System.Globalization.CultureInfo.GetCultureInfo("de-DE");
Threads get their culture specific settings from the operating system, not from the thread they were started from.
|
|
|
|
|
i dontt want to set culture , i want to getculture info.
i have done below changes in page load but still its not working.
System.Threading.Thread.CurrentThread.CurrentUICulture = System.Globalization.CultureInfo.GetCultureInfo("de-DE");
string strCluture = CultureInfo.CurrentCulture.Name;
strCluture returns en-US
|
|
|
|
|
how can i prevent my system in case of any theft also i want to block os installation?
|
|
|
|
|