It is a new selection of tips and tricks about Python and programming from my Telegram-channel @pythonetc.
Previous publications.
The art of creating computer programs
From idea to implementation: modifying the existing elliptic curve signature scheme to be deterministic and providing functions on it to obtain verifiable within the blockchain pseudorandom numbers.
Earlier this week, we released Visual Studio 2019 version 16.1 Preview 1 (see release notes). It’s the first preview of the first update to Visual Studio 2019. If you’re not already set up to get preview releases, then please do that now. The preview channel installs side-by-side with the release channel and they don’t interfere with each other. I highly recommend all extension authors install the preview.
Got the 16.1 preview installed now then? That’s great. Here are some features in it you might find interesting.
ML.NET is an open-source and cross-platform machine learning framework (Windows, Linux, macOS) for .NET developers. Using ML.NET, developers can leverage their existing tools and skillsets to develop and infuse custom AI into their applications by creating custom machine learning models for common scenarios like Sentiment Analysis, Recommendation, Image Classification and more!.
Today we’re announcing the ML.NET 1.0 RC (Release Candidate) (version 1.0.0-preview
) which is the last preview release before releasing the final ML.NET 1.0 RTM in 2019 Q2 calendar year.
Soon we will be ending the first main milestone of a great journey in the open that started on May 2018 when releasing ML.NET 0.1 as open source. Since then we’ve been releasing monthly, 12 preview releases so far, as shown in the roadmap below:
In this release (ML.NET 1.0 RC) we have initially concluded our main API changes. For the next sprint we are focusing on improving documentation and samples and addressing major critical issues if needed.
The goal is to avoid any new breaking changes moving forward.
In this post we'd like to share an interesting way of dealing with configuration of a distributed system.
The configuration is represented directly in Scala language in a type safe manner. An example implementation is described in details. Various aspects of the proposal are discussed, including influence on the overall development process.
Now let’s talk about thin ice. In the previous sections about IDisposable we touched one very important concept that underlies not only the design principles of Disposable types but any type in general. This is the object’s integrity concept. It means that at any given moment of time an object is in a strictly determined state and any action with this object turns its state into one of the variants that were pre-determined while designing a type of this object. In other words, no action with the object should turn it into an undefined state. This results in a problem with the types designed in the above examples. They are not thread-safe. There is a chance the public methods of these types will be called when the destruction of an object is in progress. Let’s solve this problem and decide whether we should solve it at all.
This chapter was translated from Russian jointly by author and by professional translators. You can help us with translation from Russian or English into any other language, primarily into Chinese or German.
Also, if you want thank us, the best way you can do that is to give us a star on github or to fork repository github/sidristij/dotnetbook.
Your friendly neighborhood .NET productivity team (aka. Roslyn) focuses a lot on improving the .NET coding experience. Sometimes it’s the little refactorings and code fixes that really improve your workflow. You may have seen many improvements in the previews, but for all of you who were eagerly awaiting the GA release here’s a few features you may enjoy!
0_0
is a totally valid Python expression.We’re excited to announce the general availability of Visual Studio Live Share, and that it is now included with Visual Studio 2019! In the year since Live Share began its public preview, we’ve been working to enhance the many ways you collaborate with your team. This release is the culmination of that work, and all the things we’ve learned from you along the way.
If you haven’t heard of Live Share, it’s a tool that enables real-time collaborative development with your teammates from the comfort of your own tools. You’re able to share your code, and collaboratively edit and debug, without needing to clone repos or set up environments. It’s easy to get started with Live Share.
There are two visual differences between Memory<T>
and Span<T>
. The first one is that Memory<T>
type doesn’t contain ref
modifier in the header of the type. In other words, the Memory<T>
type can be allocated both on the stack while being either a local variable, or a method parameter, or its returned value and on the heap, referencing some data in memory from there. However, this small difference creates a huge distinction in the behavior and capabilities of Memory<T>
compared to Span<T>
. Unlike Span<T>
that is an instrument for some methods to use some data buffer, the Memory<T>
type is designed to store information about the buffer, but not to handle it. Thus, there is the difference in API.
Memory<T>
doesn’t have methods to access the data that it is responsible for. Instead, it has the Span
property and the Slice
method that return an instance of the Span
type.Memory<T>
contains the Pin()
method used for scenarios when a stored buffer data should be passed to unsafe
code. If this method is called when memory is allocated in .NET, the buffer will be pinned and will not move when GC is active. This method will return an instance of the MemoryHandle
structure, which encapsulates GCHandle
to indicate a segment of a lifetime and to pin array buffer in memory.This chapter was translated from Russian jointly by author and by professional translators. You can help us with translation from Russian or English into any other language, primarily into Chinese or German.
Also, if you want thank us, the best way you can do that is to give us a star on github or to fork repository github/sidristij/dotnetbook.
A human by nature cannot fully understand the purpose of a certain instrument until he or she gets some experience. So, let’s turn to some examples.
One of the most interesting examples in respect to algorithms is the ValueStringBuilder
type. However, it is buried deep inside mscorlib and marked with the internal
modifier as many other very interesting data types. This means we would not find this remarkable instrument for optimization if we haven’t researched the mscorlib source code.
What is the main disadvantage of the StringBuilder
system type? Its main drawback is the type and its basis — it is a reference type and is based on char[]
, i.e. a character array. At least, this means two things: we use the heap (though not much) anyway and increase the chances to miss the CPU cash.
Another issue with StringBuilder
that I faced is the construction of small strings, that is when the resulting string must be short e.g. less than 100 characters. Short formatting raises issues on performance.
This chapter was translated from Russian jointly by author and by professional translators. You can help us with translation from Russian or English into any other language, primarily into Chinese or German.
Also, if you want thank us, the best way you can do that is to give us a star on github or to fork repository github/sidristij/dotnetbook.
I feel I’m going to open the Pandora’s box for you. Let’s talk about special types: SafeHandle, CriticalHandle and their derived types.
This is the last thing about the pattern of a type that gives access to an unmanaged resource. But first, let’s list everything we usually get from unmanaged world:
The first and obvious thing is handles. This may be an meaningless word for a .NET developer, but it is a very important component of the operating system world. A handle is a 32- or 64-bit number by nature. It designates an opened session of interaction with an operating system. For example, when you open a file you get a handle from the WinApi function. Then you can work with it and do Seek, Read or Write operations. Or, you may open a socket for network access. Again an operating system will pass you a handle. In .NET handles are stored as IntPtr type;
This chapter was translated from Russian jointly by author and by professional translators. You can help us with translation from Russian or English into any other language, primarily into Chinese or German.
Also, if you want thank us, the best way you can do that is to give us a star on github or to fork repository github/sidristij/dotnetbook.
I like PHP for development speed and excellent portability. It's great to have such a tool in your pocket, always ready to solve problems.
For me it was quite sad that there was no Waves Platform SDK for PHP when i first met this nice blockchain. Well, I had to write such kit.
We are now publishing .NET Core container images to Microsoft Container Registry (MCR). We have also made other changes to the images we publish, described in this post.
Important: You will need to change FROM
statements in Dockerfile
files and docker pull
commands as a result of these changes. 3.0 references need to be changed now. Most 1.x and 2.x usages can be changed over time. The new tag scheme is decribed in this post and are provided at the microsoft-dotnet-core repo, our new home on Docker Hub.
Summary of changes:
I guess almost any programmer who uses .NET will now say this pattern is a piece of cake. That it is the best-known pattern used on the platform. However, even the simplest and well-known problem domain will have secret areas which you have never looked at. So, let’s describe the whole thing from the beginning for the first-timers and all the rest (so that each of you could remember the basics). Don’t skip these paragraphs — I am watching you!
If I ask what is IDisposable, you will surely say that it is
public interface IDisposable
{
void Dispose();
}
What is the purpose of the interface? I mean, why do we need to clear up memory at all if we have a smart Garbage Collector that clears the memory instead of us, so we even don’t have to think about it. However, there are some small details.
This chapter was translated from Russian jointly by author and by professional translators. You can help us with translation from Russian or English into any other language, primarily into Chinese or German.
Also, if you want thank us, the best way you can do that is to give us a star on github or to fork repository github/sidristij/dotnetbook.