Live data from Hacker News

What’s New in C# 7.0

blogs.msdn.microsoft.com

271–278 of 278 posts

Re: What’s New in C# 7.0

#271
post #199

Earlier quoted context omitted.

Of course it does, as I said I was doing that. Borland C++ for Windows 3.x had an initial implementation for templates as they started to be discussed at ANSI and also supported exporting classes across dlls, providing both producer and consumer were Borland C++.

How exactly did that implementation work for templates?

No idea, not something I was too deep into. Back on those days I just used them.

Here is the link for the Borland C++ compiler documentation, I was actually using the Turbo C++ version for Windows 3.1.

https://archive.org/details/bitsavers_borlandborn3.1Programm...

The BIDS, Borland International Data Structures were the template based library that replaced the object based one and could be accessible as a DLL as well.

To export classes from DLL one would do something like

    // On the DLL side
    class _export MyClass {...}

    // On the consumer side
    class huge MyClass {...}

Described on page 336 of the manual.

If you check the the templates documentation, the generated code code could be externalized, page 152, via the -Jgx.

I was only a BIDS user across DLLs, but I can easily imagine a combination of _export/huge and -Jgd/-Jgx being what was necessary to make it all work.

Re: What’s New in C# 7.0

#272
post #104
post #90

Earlier quoted context omitted.

Well maybe you don't care, but there are folks that do (I'm on that list) ;-) I want the speed of C but the safety of C#. There are many pieces of code that you probably use every day that go to great lengths to squeeze as much power as possible. Why not help these folks help us? I'm glad there is more focus on performance because we all benefit. (Hoping to see more on the CLR side.)

Why c# and not rust or something similar that has a lower level focus?

Because some of us believe in GC enabled systems programming languages, as done already at Xerox PARC (Cedar), DEC (Modula-2+/Modula-3), ETHZ (Oberon, Active Oberon, Component Pascal) and MSR (Sing# / System C#).

What is missing is a company like Microsoft to push it down to mainstream developers, at all costs, like it happen to all luddites.

Re: What’s New in C# 7.0

#273
post #259

Earlier quoted context omitted.

Much like any other project in any other language. Yes, you can write good or bad code in any language. But some languages have an endemic culture of not caring about good code. IME, VB is one of them, as is PHP. All the VB6 code I've seen has been a random mashup of databinding directly to the and click handling. The tools encouraged this approach.

I see your point to a degree. The tools made it easy for folks to get apps up and running quickly, RAD being a popular buzzword at the time. I don't think it's fair to say the culture was that of people who didn't care about the code. I've certianly seen lot's of terrible VB6 code, but also lots of Vb6 apps that were better designed than some WinForms C# apps I've seen. I know this is all subjective.

My experience tells me that any company whose business isn't selling software, doesn't care about the code.

I have learned the hard way that they don't care one single second about quality, only that it works the way required to support business, anything else is secondary.

Re: What’s New in C# 7.0

#274
post #225

Earlier quoted context omitted.

I'm probably missing your point, but public static IList FindEphraimitesToKill(IList ephraimites) { var ephraimitesToKill = new List (); foreach (var ephraimite in ephraimites) if (ephraimite.Speak("shibboleth") == "sibboleth") ephraimitesToKill.Add(ephraimite); return ephraimitesToKill; } or: public static IList FindEphraimitesToKill(IList ephraimites) { return ephraimites.Where(e => e.Speak("shibboleth") == "sibbol…

The thing is, though, would those be allowed by style guides at the enterprise companies where C# is most common? The C# style guide of a former employer of mine (an enterprise C# user) forbids both of these snippets because of the unbraced statements in the former and the LINQ and lambdas in the latter. But admittedly I don't know what's common among C# users, so maybe they were in the minority.

I think its strange comparing languages and then saying that the point doesn't stand because code guidelines of companies don't support the more compact version.

I don't like the version without brackets, but I don't think it would make the code less compact if you'd add brackets.

Re: What’s New in C# 7.0

#275
post #273

Earlier quoted context omitted.

I see your point to a degree. The tools made it easy for folks to get apps up and running quickly, RAD being a popular buzzword at the time. I don't think it's fair to say the culture was that of people who didn't care about the code. I've certianly seen lot's of terrible VB6 code, but also lots of Vb6 apps that were better designed than some WinForms C# apps I've seen. I know this is all subjective.

My experience tells me that any company whose business isn't selling software, doesn't care about the code. I have learned the hard way that they don't care one single second about quality, only that it works the way required to support business, anything else is secondary.

In some sense it's true, but what's your point? Still in those companies, a better language/framework can go a long way in conducing better code quality, even if the boss gives zero shit about it.

Re: What’s New in C# 7.0

#276
post #275
post #273

Earlier quoted context omitted.

My experience tells me that any company whose business isn't selling software, doesn't care about the code. I have learned the hard way that they don't care one single second about quality, only that it works the way required to support business, anything else is secondary.

In some sense it's true, but what's your point? Still in those companies, a better language/framework can go a long way in conducing better code quality, even if the boss gives zero shit about it.

The boss giving zero shit about it means not getting the approval IT requires to support anything you might want to do.

In such environments even root access is time limited to a few hours and requires a ticket asking for it with a reason that should be validated by the boss.

Re: What’s New in C# 7.0

#277
post #271

Earlier quoted context omitted.

How exactly did that implementation work for templates?

No idea, not something I was too deep into. Back on those days I just used them. Here is the link for the Borland C++ compiler documentation, I was actually using the Turbo C++ version for Windows 3.1. https://archive.org/details/bitsavers_borlandborn3.1Programm... The BIDS, Borland International Data Structures were the template based library that replaced the object based one and could be accessible as a DLL as wel…

Okay, so that was something that I have mentioned in passing earlier:

"it doesn't allow any templates across ABI boundary, except when you manually instantiate them (extern template)"

So you can export template instantiations, yes. But you cannot export the template itself. For fairly obvious reasons - to instantiate a template requires compiling C++ code after substituting the tempalte parameters, so to export it across ABI boundary would require including the entirety of the C++ language (or at least a substantial subset - I guess you could desugar a bunch of stuff like, say, lambdas before) in that ABI.

And virtual templates are a whole other kettle of fish, because every instantiation of a virtual template would require a new slot in the vtable - or else the generic would have to dispatched by a single method, and the caller would have to supply runtime type information. In practice, C++ just forbids virtual templates outright.

In C#, this all works just fine, because generics still exist on bytecode level, which is what gets exported - and at runtime, the JIT will instantiate the generic by compiling that bytecode to native code, separately for every instantiation (in practice they unify them for reference types, because pointers are always of the same size; but value types get distinct JIT-compiled versions each).

For virtual generics, I'm actually not entirely sure how this works, but I would assume that vtable slots are allocated in batches and filled with instantiations as needed - and when you run out of slots and need to reallocate the vtable (and potentially shift indices of other methods in it), you can just JIT-recompile the bytecode for any method that happens to use the class with affected vtable.

Re: What’s New in C# 7.0

#278

Earlier quoted context omitted.

Thank you, in turn, for replying. I'm of the opinion that out variables have little value if you have tuples and deconstruction, but I wanted to understand your point. I'm not sure I do, unfortunately. I'm little out of practice with C#, so bear with me. Back to this code: if(!memo.TryGetValue(rdr.GetInt32("student_id"), var out complete) memo.Add(new Student(rdr out complete).ID, complete); There's a parens missing…

You're right, there were missing tokens; sorry about that. Here is the equivalent C# 6 version of the code (i.e. something very similar to the pattern that I currently use): IEnumerable GetStudents(SqlCommand cmd) { var rdr = cmd.ExecuteReader(); var memo = new Dictionary (); while(rdr.Read()) { Student.Completion completion; //this declaration will be unnecessary in C# 7 if(!memo.TryGetValue(rdr.GetInt32("student_id…

Thanks for continuing to indulge me in this conversation. So, if I understand you correctly, your data looks something like this:

    StudentId|    Name |CourseId
    ============================
            1|      Bob|       1
            2|     Jane|       1
            1|      Bob|       2
            1|      Bob|       3
            2|     Jane|       4
With many more columns of course. The point being that it's a denormalized listing of student-course pairs. If so, you'd be able to get immutability by reading the query result into a data table and doing something like:

    var result = from row in dt.AsEnumerable() 
    group row by row.Field("StudentId") into grp 
    select new Student(
        grp.Key,
        grp.First().Field("Name"),
        from courseRow in grp select new Course(courseRow)
        );
This seems to satisfy all of the conditions that you list (namely immutable objects), but with the added advantages of not needing a inner Completion class, and a number of less lines of code.

Furthermore this is less coupled because now the Student class doesn't need to worry about DataReaders or DataTables or which column names to read from.

I would also argue that this version is a lot easier to read and reason about.

I think you could make a similar transformation for any circumstance in which you wanted to use an out variable in the fashion you outline.

Does that make sense? Is there another case in which you would advocate for our variables in new code?

Post reply on HN