Programming title
MSDN Interview with C # programmingRainbow (translation) keyword C#,jeffrey richter source http://www.mdsn.com[tr]
Programmer World
the conversation of Robert Hess and Jeffrey Richter (a famous programming writer, columnist, and consulting expert). ROBERT HESS: Welcome back. We're going to be dealing with problems with C # programming. In order to help us understand these problems, I invited my good friend Jeffery Richter to come here. Jeffery happens to be a programmer who writes a lot of programming books, and his latest book is programming Server Side applications for Windows 2000. Now you're also a consultant and have your own company Wintellect, right?
JEFFREY RICHTER: Wintellect.
ROBERT HESS: I guess you have a website?
JEFFREY RICHTER: there, wintellect.com. We specialize in training, commissioning and advertising.
ROBERT HESS: Well, I understand that you have done a lot of work on C # recently.
JEFFREY RICHTER: Yes, it's been more than a year now, and I've spent a lot of time specializing in C # programming.
ROBERT HESS: It's been a year? I think we just released C #.
JEFFREY RICHTER: Yes, but I've been in the loop, in the Microsoft Circle, if you like. I myself placed a small office on the 42nd floor, where I engaged in C # research and related. NET has been working for more than a year now.
ROBERT HESS: So Microsoft will help you because you are not a Microsoft employee ...
JEFFREY RICHTERTo
ROBERT HESS: They just help you understand C # as a language, so you can write more books like this?
JEFFREY RICHTER: Yes, they want me to write more books, I got help, found bugs, attended similar conventions and communicated with people, so I thought I learned a lot more than just writing a book, and the fact has contributed to C # to some extent. So I can tell you that the first thing I was interested in when I first started out was the new language, which I would use to write all the code, and I knew that the code was written for the foreseeable future, so let's not mention it. I have a very deep C, C + + background, after reading and the C # related documents and programming references and other materials one weeks, I feel already quite proficient in C #. And within a week, I was able to really write something useful.
ROBERT HESS: Just a week later.
JEFFREY RICHTER: Yes, just a week later. Because it's very similar to C + +, you know, where the braces are the same, the return values are the same, the parameters are the same, and many things are the same.
ROBERT HESS: When you continue to use objects, destructors, constructors, double colons (::), and so on, you seem to lose some of the peculiar naming habits they have, right?
JEFFREY RICHTER: Yes, yes, double colon (::) are dotted (.) Instead, the arrow number (->) is replaced by the dot number, which greatly simplifies the language. So it was too easy for me, and it was time-sensitive, and I still had to go back and look at the language reference, perhaps find out how to overload the operator, or something very ordinary, to know that when I was programming, I rarely did anything vague. And now most of the things are more natural to me. In fact, it's just a process problem to solve.
ROBERT HESS: Since you've been in this job for over a year now, have you noticed the evolution of the language itself during this time? Are they still very much the same today as they were a year ago?
JEFFREY RICHTER: I think it's quite the same. But there must be some little tricks (tweak) that do exist in the beta phase, there are many nondeterministic destructors (non deterministic destructor), and the object's destructor (destruction of objects) or something like that. Therefore, the base Class library has added a IDisposable interface, and I think it will appear in Beta 2.0, not in Beta 1.0. At the same time, C # has added some new language constructs to help you get things that are closely related to the deterministic deconstruction of objects (deterministic destruction of objects). So I would say that Microsoft is already very concerned about what people say about the language, and they are also trying to add something new to the response. I also learned that in the future, after version 1.0, they plan to add generics (generics), something like a template in C + +, and I'm sure that C # is going to evolve to support these capabilities. In fact, all languages can use generics when they are in the common language runtime (common language runtime).
ROBERT HESS: Because they are part of it and because they are the common language runtime, they have the right to use all those features. So what do you think of C # as a language in general?
JEFFREY RICHTER: Well, as I said, C # is very similar to C + +, so I quickly became familiar with it. It's very, very clean, I'd say it's very clean. I came from a C + + background, especially as a Windows C + + programmer. Ansii has the C + + specification and Microsoft wants to preserve some of the skills in C + + to showcase the features in Windows, and make these techniques look a bit like the nobles in C + +, but they never really meet the requirements. And Microsoft is still adding __try, __finally and __declspec and other similar things.
ROBERT HESS: This is the C # you are talking about.
JEFFREY RICHTER: Yes, and C + +, of course. So the language is a bit scary, and after a while you're not completely clear, as in the const usage, when declaring a pointer or a constant pointer, should the asterisk (*) be placed in front of it or in the back? You will not be able to determine exactly where these modifiers should be placed at that line. I always need to look up information. So in C #, because Microsoft had already made the ECMA (European Computer Manufacturers Association) 's proposal for standardization in the design, it was very clean, for example, and nothing started with a sliding bar. Of course, because there is no real pointer in the. NET runtime, you will never see such modifiers in your code, such as the * number and the & number, from beginning to end. So when you think about it, it looks clean and really feels cool.
ROBERT HESS: Don't you think there is something missing? I mean, when I'm programming with C, I like to use pointers to solve problems, to sort the pointers, to use the same old things as the pointer algorithm, and you'll get a lot of pleasure from it. Don't you miss it when you're using C #?
JEFFREY RICHTER: Well, I have to admit, I am always a little bit of a little bit of the same, but sometimes I read it. Of course, in general, with C # and the. NET framework, you can always interoperate with other languages (interoperate out), so if you really have to do that, I'm programming with C + + instead of C #. C # also does provide an unsafe keyword (unsafe keyword), so that you can create a method and say that it is unsafe and that you have the right to use pointers and manipulate memory directly. However, I have never experienced it personally. As for the fun of coding, the. NET Framework and Basic OS class libraries provide a wealth of features that make programming interesting. Therefore, when I cannot keep virtual memory and commit it thinly, nor do I work with a memory image file in the. NET framework, at least not directly, it can be done interactively, and there are other things like serialization and Web services, They help create truly valuable applications that are truly powerful and rich in content.
ROBERT HESS: Now in your training class, you are teaching and instilling such things, you are still in C # training?
JEFFREY RICHTER: Yes, actually just this week, I gave my first C # programming Class A class where there were two Visual Basic programmers who were not object-oriented programmers and I didn't really introduce the C # language to them because I focused on the common language runtime and base class libraries, about C # I want to talk about it later. However, these two VB programmers on the Machine internship, C # to start quickly, almost no trouble, and unexpectedly can use it for development, efficiency is also high. I am very surprised!
ROBERT HESS: The reason for this is that in C # you use Name.name.name.name instead of the old stuff like name,->, Name.name,-> name.*, *, (), & ...
JEFFREY RICHTER: That's true.
ROBERT HESS: These are not used in VB.
JEFFREY RICHTERRight
ROBERT HESS: So the format looks quite consistent.
JEFFREY RICHTER: Yes, quite consistent. Of course, they use curly braces {} instead of begin and end, which may make some people not fit. But I think it takes them less than 5 minutes to get over it and more productive.
Rrobert HESS: So in a company position, if a company hires you to open a C # training course, I have to find out if they're starting to think about porting some of the company's results to C #, is that what you're suggesting they do? Or what stage do you think they should be in?
JEFFREY RICHTER: Well, of course it depends, first they have to decide whether to adopt the. NET framework as the development platform. I think it's very valuable, for me there is no problem, that is the platform I really aspire to. If you are developing the application software for the. NET framework and are writing new code, it seems to me effortless. C # is very easy to use, it is a vibrant language, using the right way you will be very prolific. I personally believe that a lot of VB programmers, VB6.0 programmers, will turn to C # rather than VB7.0.
ROBERT HESS: Then why?
JEFFREY RICHTER: Because I think C # exposes more features in the common language runtime (common language runtime), giving you a little more control over the code and the methods it expresses. You will talk more directly to runtime, runtime gives you more power.
ROBERT HESS: Of course, we are not VB programmers, so will be clearly based on the development of C.
JEFFREY RICHTER: You are right.
ROBERT HESS: So that's what it's worth, we're a little off the point. So what do you like about C # as a language? Is it simpler, more thorough (clean) programming?
JEFFREY RICHTER: Well, the main thing is to get rid of the useless stuff. For example, well, C # does not allow you to declare parameters as constants (const), and you cannot have a const entity method, which you can in C + +. I know some people would think that would really lose the character of language, but the fact is that in C + + The const will always be mercilessly discarded so that you can do whatever you like in your code. Because C # really does not allow you to use const, it is completely and easily understood. Now, I think I should say: For me,. NET frameworks really interesting thing is the common language runtime. It defines how an object works, or how it is created, and what defines these types of behavior. So you have a base class library, and of course it's a huge class library that gives you the right to use a lot of things, so you don't have to rewrite everything even if you want. Your choice of language is your personal thing, and I chose C # because it is a really good high-level language and it allows me to talk to the framework. But in a way, the really best language for using the. NET runtime and base class libraries should be the intermediate language (immediate language) assembly language.
ROBERT HESSSaharan Speaking of assembly language?
JEFFREY RICHTER: Yes, speaking of assembly language. I mean, it gives you full access to the bottom of the platform, but it's inefficient in the assembly language environment, with so many programs that you have to write one line at a line. So the C # language is one level higher. While some of the performance in C # is not very common, C # designers like Anders have decided not to expose them. In some cases, in order to access the runtime functionality not provided by C #, I might turn to another language. But in general, C # is the highest level of language, and it allows me to solve a lot of problems in such an environment in accordance with my own needs, and highly efficient.
ROBERT HESS: Not all the problems, but only the majority?
JEFFREY RICHTER: No, this is rarely the case: I also need to access something, but C # does not allow access. This is on the other hand, I just think it's very easy to forget that when you want to visit. NET, and C # or some languages are not available to you, you can go to another language. Just code to create this method, possibly a static method, a static method in a class, with APL or COBOL or whatever language you choose, may derive, and then implement the entity method in some languages that may really give you access to some of the underlying functionality. So I think it's a very powerful paradigm, and I've never really learned to choose the best language to do my job.
ROBERT HESS: Well, I bet you viewers might want to look at some examples of C # code so that we can understand some of the problems we're talking about. Do you have an example to show us?
JEFFREY RICHTERHave I did bring a source code file with some examples that I can barely handle, and I'll give it to you at the end of the show. You are welcome to upload it to the website so that you can download it. So here, if you like, I'm going to start by demonstrating that in C #, each method must be in a class. There is no global method, and there are no variables outside the class, so everything is limited to a certain range.
Using System;
Class App {
public static void Main () {
Console.WriteLine ("Hello World");
}
}
This is the Hello World program that must be kept, very simple. In the program, there is a class called app, in which I have a main method of my own, and main is a static method, because it must be called from the outside. We don't have to have an instance of the app to call main. In my case, main returns void, and no parameters are accepted. Simply inside the main, it calls the Console.WriteLine, which displays "Hello World" on the monitor. So this is the smallest program you can write that can learn the relevant concepts.
ROBERT HESS: is main still a reserved method in C #? Just like in C + +?
JEFFREY RICHTER: Main is the default, it has a capital m, lowercase letter a-i-n, because C # is a case-sensitive language, like C + + rather than VB and. NET. So when the compiler compiles the code, it looks for a static method called Main and then uses it. However, there is a compiler command line that can overwrite main and select one of the different. By the way, this is actually a very useful technique. Some people put multiple main in a single application for group testing, and when compiling, you can set different switches to perform different main to test specific components.
ROBERT HESS: a wonderful skill. Do you also use parameters such as argv and argc to pass to the main function by default?
Using System;
Class App {
public static void Main (string[] args) {
Console.WriteLine ("Hello World");
}
}
JEFFREY RICHTER: Yes, it's up to you. Here, I'll modify the code on the spot, which means that string is an array of strings, args
Click the definition that I play on the slide. By the way, what is this args? is a data type! It is a pointer to a string, or a reference to a string. When it comes to pointers, you only see the band *, but args is really a pointer. The boot code resolves the command line long before the main is invoked, creates an array of strings, and then passes the pointer to the array. Like a call to args.length I can solve some of the problems that the call returns the length property of the array, which contains the number of elements in the array, and then I can just loop with a normal for statement, or you can use a for each of C #, a special for Each statement is used for a quick loop.
ROBERT HESS: Very novel, which is not in C or C + +.
JEFFREY RICHTERRight And I did have the demo code, and I found it.
static void Arraydemo () {
Declares a reference to an array
Int32[] IA; Default value is null
ia = new int32[100];
ia = new int32[] {1, 2, 3, 4, 5};
.
.
.
This is an example of a code with an array, so I'll mention it a little bit. In this example, you first declare a reference to a int32s array and arbitrarily take a "ia" for an array of integers. It is simply a pointer, with a 32-bit or 64-bit value, and is always initialized to null if it is still running on a 64-bit system, and the reference is always initialized to null until it is explicitly set. In the following line, I randomly new (constructed) an array with 100 Int32 values. New returns a reference, and then I save the reference to the "IA" variable. The next line just shows another way to construct it, and here I'm new a int32s array, the specialized C # syntax starts with an opening brace followed by the elements of the array, and of course the elements are separated by commas, followed by a closing parenthesis. When you first see this syntax, you'll find it a bit clumsy. This is just another use of new, of course, it can calculate the number of elements.
ROBERT HESS: And that's just predefined values:
.
.
.
Display the contents of an array
foreach (Int32 x in IA)
Console.Write ("{0}", x);
Using multidimensional arrays
stringbuilder[,] sa = new stringbuilder[10][5];
for (int x = 0; x < x. x + +) {
for (int y = 0; y < 5; y++) {
Sa[x][y] = new StringBuilder (10);
}
}
Using an array of arrays (jagged arrays)
Int32 numpolygons = 3;
point[][] polygons = new point[numpolygons][];
Polygons[0] = new Point[3] {...};
POLYGONS[1] = new Point[5] {...};
POLYGONS[2] = new point[10] {...};
}
JEFFREY RICHTER: Yes, that's right. This is foreach, which appears in the first line of code. "Foreach" is a C # syntax, I'm sure of all. NET language provides this syntax, it is an extremely common programming paradigm, in this way, you can traverse the elements in the collection. So, in the foreach Int32 x here, "X" is a variable, and Int32 is of course a type, and then I give the reference to the array. foreach automatically calculates how many elements there are in the array, and whenever you loop to Console.Write, the value of the element is displayed and then moved to the next element.
ROBERT HESSand "for (I=0, I<ia.length, i++)" Does the same thing, but if you want to iterate through all the elements, it's awkward and difficult to follow, so it's much easier to keep doing the very same things all the time.
JEFFREY RICHTER: Yes, brilliantly. Still, I'll give you a hint, because foreach is a bit cool and ingenious, so it eliminates a lot of coding. It also does some other work on the type conversion (casting), which is also good for you. So generally, when I write a loop, I usually start with foreach, and then when I continue coding, sometimes, I then realize that I need an iterator (iterator), and I need an X from 0 to the actual number. Yes, I must know which element number. So I ended up rewriting this loop, quite frequently ...
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.