Jump to content
Xtreme .Net Talk

snarfblam

Leaders
  • Posts

    2156
  • Joined

  • Last visited

  • Days Won

    2

Everything posted by snarfblam

  1. I actually like that for loop, mskeel. I've used an equivalent while loop a few times, but never thought to use a for loop. It demonstrates that the for loop can be very flexible. What it really shows, though, is that the C-style for loop is more of an organization tool than anything. It is just a "while" loop that groups together statements related to control flow. (Either way, a DotNet purist would scoff at us for not using the ForEach loop.) To answer your question, and this may ring a bell, In my spare time I've been tinkering with a project that is now over a year old (and its still hardly functional). The original idea was simply a Windows command prompt replacement with (mostly) C-style syntax and functions as the equivalent of batch files. Someone (PD, I believe) kindly pointed out to me, early on in the project, that Microsoft was releasing a new command prompt packed with all of the nifty features I was planning to include in my own (except the syntax), hence my project has become a strictly academic endevour which has been moved to the back burner. And then I keep introducing features and concepts into the program, which only helps to slow the development process. PD, to be frank, the order of the loop parameters doesn't bother me. What bothers me is that it may bother others. It seems quite intuitive to me, really. You specify only the information you need to, and in the most common sense order. But I know that not everyone thinks like me. In fact, I would venture to say that most people don't think like me. So I figured getting some extra input would make sense.
  2. Thanks for the input. I'm sure plenty of people appreciate the... explicitness... of the C-style for loop. As for simpler or more concise, I would disagree. I think it is rather redundant. It is almost always seen in a very standard form: declaring a control variable, initializing it, a less than comparison with a termination value, and an increment operation (don't forget the loop's contents). Any deviation tends to be viewed as bad style because it becomes convoluted (and a simpler while loop becomes more appropriate), yet we are still expected to write out every last fundamental bit of the logic with the exception of the actual GOTO command. The C-style for loop is nothing more, really, than some syntactic sugar that glues together several statements, and, frankly, it leaves a sour taste in my mouth. I see no need to have to write out any more of the loop than what actually ever changes from one for loop to the next: the control variable and the limits of the loop. And if one can be omitted, then why not? That being said, I don't think your opinion is invalid. I simply don't share your opinion, but I will take it into consideration. I do know that others have complained about how the C-style loop is a little to involved, specifically users of VB (the language often criticized for being overly verbose). I don't know if the idea is a little sillier or less relevant that I thought, or if maybe these boards have become too quiet to be a worthwhile place to get some input, but there certainly seems to be a lack of interest in a simplified for loop here, which strengthens your case, I suppose, for the superfluousness of said loop, which I will also take into consideration. I do remember asking a very similar question a while back and getting a much bigger response...
  3. Re: Partial classes Mandelbrot, I certainly understand your point of view on the fact that hiding designer code can actually be confusing and frustrating for a user experienced with DotNet programming, but plenty of people disagree. When VS2005 came out everyone started asking, "Where's my designer generated code?!" The hidden designer code brings back that mysterious black-box feeling of VB6, where many things seem to happen magically because you aren't quite sure what is going on when you can't see what happens under the hood. Some of us don't appreciate that we are distanced from the underlying workings of the designer, but others appreciate the simplification and reduction in clutter. I couldn't stand it at first, especially with VB Express, where, by default, there is no way to access designer generated code through the IDE, but I've grown to appreciate the separation. Designer generated code never really got in the way, but when you are doing something where you need to get at designer code, such as developing controls, it is nice to have a separate tab for the generated code and to be able to get to it without losing your place in your own code. I think Microsoft made a couple of mistakes in the implementation, especially completely hiding generated code in VB, but on the whole the feature adds more value than it takes away.
  4. How and where these types of details are stored depends on the file type. For JPEGs, the width and height are stored within the file. MP3s contain most of this type of extra data in ID3 tags within files. Some information for certain file types is stored in "alternate file streams," a feature of NTFS. So, as far as I know, there is no simple and standard technique that can be used in a general fasion to get this type of data from files.
  5. Just hoping to get some input for a DotNet project I'm working on, and figured that C# programmers would be the best to ask. If a simplified looping structure were introduced to C# (using the hypothetical "loop" keyword) I would like to hear thoughts on a few points. This hypothetical loop construct would be a simplified version of the for loop whose form can very depending on how specific the programmer would like to be. The form would be: [color="Blue"]loop[/color](controlVariable, start, count) [color="Magenta"][i]statement[/i][/color]; The start value can be omitted (assumed to be zero), or the controlVariable and the start value can be omitted, so some possible variants would be: [color="SeaGreen"]// Curly braces aren't really necessary.[/color] [color="Blue"]loop[/color](numberOfTimes) { MessageBox.Show("You will see this a number of times."); } [color="Blue"]loop[/color]([color="Blue"]int[/color] i, numberOfTimes) { MessageBox.Show("You have seen this " + (i + 1).ToString() + " times."); } [color="Green"]// This will loop from 5 to 14 (start at five, ten iterations)[/color] [color="Blue"]loop[/color]([color="Blue"]int[/color] i, 5, 10) MessageBox.Show("I started at 5, and now I'm at " + i.ToString()); The idea, of course, is to take the ugly c-style for loop and create something a little more elegant and something even more concise than the VB for loop. My biggest concern is the fact that with different forms of the loop the expressions appear in a different order (i.e. the control variable might be first, or the count might be, and the initial value might be second, or the count may be). Does this seem like it has potential for confusion? I could change the order around to eliminate this problem, but the order I have chosen seems most intuitive to me. Another concern of mine is that some people have questioned whether the programmer should be specifying a number of iterations or a terminating value. For example, should loop(int i, 5, 10); loop from 5 to 10 (10 is the terminating value) or should it loop from 5 to 14 (10 is the number of iterations). I personally prefer the latter. Even though it is slightly less intuitive, it results in neater code (you avoid the "-1" that is ever present in VB's for loops). If it makes any difference, this simplified loop would be used primarily in scripting rather than compiled code. Any thoughts are welcome.
  6. Re: Code in InitializeComponent Eduardo, I'm glad the problem seems to be resolved, but I have a recommendation. Investigate the AddHandler keyword in VB and see how it relates to the Handles clause. C#'s use of += is the same as VB's use of AddHandler, which can produce the same effect as Handles. Being familiar with the relationship between these things will give you a thorough understanding of how events work in C#.
  7. I would go with a binary serializer, like PD said, but just to throw this out there, there is always the option of using the Marshal class to do this. It might be quicker (or it could be slower, I haven't tested it) and the binary result may or may not be the same as that of the binary serializer (I'm not sure if they both align data the same way). Basically, you could use Marshal.SizeOf to get the number of bytes in the structure in packed form (no padding for 32-bit alignment). Then you could use Marshal.AllocHGlobal to allocate memory, Marhsal.StructureToPtr to copy the structure to that memory, Marshal.Copy to move that into a byte array, and Marshal.FreeHGlobal to release the memory that you allocated (the memory can be re-used as many times as you like before you free it). Now, this has about a 1% chance of benefitting your project, but its fun to get your hands dirty with binary and you will learn some of the things you can do with the marshal class. Of course, if this seems a bit over the top or confusing, by all means, ignore my post.
  8. Re: AddHandler during constructor I don't have VB on this machine to test it, but I do believe that the Handles clause manages handlers outside the constructor. I personally think that this is more intuitive than convoluted. It is like associating a handler with a variable instead of an object, which can be quite a convinience as long as you understand what the code is doing.
  9. Re: String methods Good catch, Mister Paul. You know, assuming that this is the case, I wouldn't have caught that, even if I saw the code. Even now I find myself stumped from time to time when I use the String.Replace method.
  10. Unfortunately, controls can not be converted in such a manner. The ToolStrip designer supports a feature along these lines, but it is limited to converting ToolStrip controls.
  11. Being a C# programmer, I naturally discourage the use of the "My" feature (it is not supported in other languages and is, really, superfluous) but everyone has their own opinion. I'm actually not familiar with the FileSystem class. Is it from VB6? Why not use System.IO.File.GetAttributes and System.IO.File.SetAttributes? These, as far as I know, are the de-facto DotNet standard.
  12. Why not create a form with a textbox on it and a simple menu or toolbar to save and print, and use that to present the text to the user. Either that or launch notepad and have it open the text file.
  13. I think ApiViewer 2004 should do the trick. It includes a list of constants and their values, and presents them in the syntax of your choice (VB6, VB.NET, C#, etc.).
  14. There is no incredibly quick and easy way to do this, but with some effort you should be able to write a program to automate this process and perform batch-processing. You would have to use the Image class in conjunction with the Graphics class. The process would not really be reversible (you would naturally want to keep the originals) and there might be loss of image quality. Assuming all the files are in the same folder, you would start by asking the user which folder the files are found in. I'm guessing that the images would be JPEGs. You can use the Directory.GetFiles method and specify a file pattern (i.e. "*.jpeg;*.jpg" but I'm not positive about the format) to get a string array containing filenames. Loop through the files, opening them with the Bitmap constructor. Use the Graphics.FromImage function to create a Graphics object which can manipulate the image. You can simply write some text to the image (Graphics.DrawString), use a pre-prepared semi-transparent image (Graphics.DrawImage), or use a pre-prepared but not semi-transparent image and use a color matrix to render the image semi-transparent. After watermarking the image, save it. To optimize image quality and file size, you will probably want to enumerate image saving codecs to find the JPEG codec, with which you can specify the image quality (I can help you with this). Dispose of the image and Graphics objects. Repeat. Hope that helps, and I'll be glad to help out if you hit some bumps along the way.
  15. Re: Dispose and scope I'm not too sure about COM components. I would guess that if they expose a Dispose method, that would be the way to go, and if not, you shouldn't worry about it, but you probably want to check out MSDN documentation on COM in DotNet and check out the COM classes located in the DotNet framework. Or find someone who knows what they are talking about.
  16. Re: StreamReader That is correct.
  17. It is generally recommended that you turn on "Option Explicit" and "Option Strict." You are using late binding here (where the function that will be called is determined at runtime based on the type of object), which is an option that does work, but is generally looked down upon because it can allow certain types of errors in your code to go unnoticed. If you absolutely need to use late binding, you should research reflection (which has support for events), but in this case I would actually recommend that you use an interface, which also supports propertites, functions, and events.
  18. Re: Dispose and scope Are you talking about DotNet Framework objects, classes you are writing, or objects in general? Do you understand the IDisposable interface and the difference between Dispose in DotNet and delete in C++? To answer from a slightly different angle, simply put, managed resources (resources on DotNet's own heap) are automatically collected for you. When unmanaged resources are allocated (such as Windows handles and objects from unmanaged libraries) they need to be released explicitly, which is where Dispose comes in. If it is there, call it when you are done with an object, as you would do in C++ (or try the using keyword). When it isn't, don't worry, DotNet will take care of it. When you are writing your own classes that use unmanaged resources, implement IDisposable and release the resources in the Dispose method.
  19. Re: StreamReader An easier way would be to use the ReadAllText method of the File class. [color="Magenta"]C#[/color] [color="Blue"]string[/color] text = System.IO.File.ReadAllText(filename); [color="Magenta"]VB[/color] [color="Blue"]Dim [/color]Text [color="Blue"]As String [/color]= System.IO.File.ReadAllText(Filename)
  20. A good place to start might be an index of keywords. It would probably be a good idea to familiarize yourself with most keywords, because you never know when they will come in handy. [edit]The link provided is an index of VB.NET 2003 keywords, you might want to search for an updated list for 2005.[/edit]
  21. Should you be setting the name attribute of the input?
  22. I'd say George is right on this one. Obviously, I don't want my desktop computer to lock me out and become a single-purpose machine, but when you are dealing with something such as a kiosk (or an ATM), that is exactly what you want. In business applications, there can be many reasons to want to limit functionality and to use a PC as a single purpose machine. A computer dedicated to inventory management in a warehouse, or to be used as a cash register (I know I have seen registers powered by Windows). While locking a user out can be malicious, It can also be very useful.
  23. It seems to me that running scripts on the client side instead of making more logical and better structured code, even if it is on the server side, is tantamount to micro-optimization. In other words, the extra effort and cost that goes into so-called optimizations is not made back by the negligible gain in performance. Even if the gain is measurable, it isn't necessarily a wise investment. Consider how much more work is being made for the programmers.
  24. It might be worthwhile to try to disassemble this library and see how it achieves the animation (at least, for those of use who use C#), but that depends on whether or not it is actually kosher to disassemble DotNet libraries.
×
×
  • Create New...