![](/uploads/1/2/7/0/127061388/911594537.png)
This section covers the list of topics for C# programming examples. These C# examples cover a wide range of programming areas in Computer Science. Every example program includes the description of the program, C# code as well as output of the program. All examples are compiled and tested on Visual Studio.
Microservices are increasingly used in the development world as developers work to create larger, more complex applications that are better developed and managed as a combination of smaller services that work cohesively together for more extensive, application-wide functionality.Tools such as are rising to meet the need to think about and build apps using a piece-by-piece methodology that is, frankly, less mind-boggling than considering the whole of the application at once.Today, we’ll take a look at microservices, the benefits of using this capability, and a few code examples. What are Microservices?Microservices are an architectural style that develops a single application as a set of small services. Each service runs in its own process. The services communicate with clients, and often each other, using lightweight protocols, often over messaging or HTTP.Microservices can be thought of as a form of service-oriented architecture (one of the most ) wherein applications are built as a collection of different smaller services rather than one whole app.Instead of a monolithic app, you have several independent applications that can run on their own. You can create them using different programming languages and even different platforms. You can structure big and complicated applications with simpler and independent programs that execute by themselves. These smaller programs are grouped to deliver all the functionalities of the big, monolithic app.Microservices captures your business scenario, answering the question, “ What problem are you trying to solve?”Instead of large teams working on large, monolithic projects, smaller, more agile teams develop the services using the tools and frameworks they are most comfortable with.
Each of the involved programs is independently versioned, executed, and scaled. These microservices can interact with other microservices and can have unique URLs or names while being always available and consistent even when failures are experienced. What are the Benefits of Microservices?There are many benefits to using microservices. Some of them are related to how they allow your developers to write code.
Other influence your architecture.Microservices are small applications that your development teams create independently. Since they communicate via messaging if at all, they’re not dependent on the same coding language. Developers can use the programming language that they’re most familiar with. This helps them come work faster, with lower costs and fewer bugsSince your teams are working on smaller applications and more focused problem domains, their projects tend to be more agile, too. They can iterate faster, address new features on a shorter schedule, and turn around bug fixes almost immediately. They often find more opportunities to reuse code, also.Microservices improve your architecture’s scalability, too.With monolithic systems, you usually end up “throwing more hardware” at the problem or purchasing expense and difficult-to-maintain enterprise software.
With microservices, you can scale horizontally with standard solutions like load balancers and messaging.Also, as more and more enterprises embrace the cloud, you’re probably looking that way, too. Microservices are a great way to get there. Deploying microservices in containers isn’t just a good idea.
It’s a best practice, too. I’ve mentioned several times that microservice teams should choose their own tools. How do operations and dev-ops manage the chaos this creates?
By using containers, so you can deploy and orchestrate your system with a single set of tools.There’s a reason why RESTful services and microservices are often associated with each other. It’s because the best microservices architectures treat their services as stateless. REST’s state transfer that pushes state down to the clients means that you can treat your servers as stateless, and run your code as interchangeable parts of a whole. You only need to worry about making sure that there are enough services available to handle the load. And, if one fails, another can pick up the slack. Additional Resources and Tutorials on MicroservicesFor further reading and information on microservices, including some helpful tutorials, visit the following resources:.In this article, we’ve discussed what microservices are, and how they can help you improve your enterprise architecture. After defining what these services are, we covered their major benefits.
Then we looked at some of the most popular microservice APIs for Java. Then, we wrapped up with a look at microservices best practices and a list of resource here on Stackify’s website.Microservices are a great addition to your enterprise. But, it helps to have a tool like to help you monitor them.Retrace is a code-level solution that can manage and monitor your app’s performance throughout the entire development lifecycle. Plus, it offers many other features, such as error tracking, log management, and application metrics.
Article Index |
---|
Getting Started With C/C++ On The Micro:bit |
A simple example project |
Anyone who wants to use the BBC micro:bit to its full potential as an IoT device needs to look outside the coding environments provided by its own website. As an mbed device, however, the micro:bit is capable of being programmed in C/C++. Here we look at how to use the mbed online compiler for a simple demo program.
Important note:
This article and the rest of the book have moved to our sister site:
Where you will find any updates and more chapters.
The fact that the micro:bit is an mbed device brings with it both good and not so good news. The good news is that you can program the micro:bit in C/C++ because it is an mbed system. The bad news is that the documentation only gives you a hint as to how to do it. Here we explore how to use the online compiler. In a follow-on tutorial we'll find out how to do the same job offline using NetBeans. While I'm specifically looking at the Micro:bit, much of this will apply to any mbed device.
If you want to get started withC/C++ on the micro:bit quickly and don't mind signing up to an online service then it is all very easy. On the other hand, if you have a preference for a desktop IDE or just a command line interface things are a bit more difficult. The reason is that mbed comes with a brand new make replacement called yotta. It's not that yotta is bad, it is just another thing to learn. It is also surprising how complicated embedded programming has - become so much so that it actually need something this complicated. We seem to be a long way from the C programming running on almost bare metal. Once upon a time the hardware was the tough part - now it's the software as well.
So if you want an easy life go for the online compiler.
If you want more control, but perhaps more complexity, go for the offline approach.
I personally prefer the off line approach using NetBeans and suggest that after you have tried things out with the online compiler you spend a few hours getting things set up for NetBeans development, which is described in the next article.
Why C/C++?
Before you spend time finding out how to program in C/C++ there is the good question of why bother? After all, you have the choice of Touch Develop, JavaScript and MicroPython to program the micro:bit and they are all fairly easy to use.
The answer to the question of why C/C++ is that it gets you closest to the hardware. Not all of the features and facilities of the micro:bit are accessible from the higher level languages. For example, at the moment you can't get access to the micro:bit's radio. Using C/C++ and the microbit library you can use the BlueTooth radio as a simple point to point radio connection between micro:bits. This makes it possible to build radio control robots and similar gadgets - something much harder if all of the connections have to go through the BlueTooth stack.
Another example is the LED control. In MicroPython you have nine brightness levels. In the micro:bit's other supplied languages the LEDs are either on or off. In C/C++ you can set any of 255 levels.
Going beyond the standard hardware you can also implement missing hardware facilities. For example, there is no SPI bus available under any of the supplied languages, only an I2C bus. Using C/C++ you can access a standard mbed SPI driver and work with SPI peripherals. You can even use your own code to implement protocols that are not supported such as the one-wire bus and the DHT11/22 temperature humidity sensor.
The reason you can implement these additional protocols is that C/C++ is about as fast as you can get on any machine. You might be able to get some more speed out of an assembly language version of a program, but it would only be a few percent. Using C/C++ lets your programs run tens of times faster. For example, the blinky program given below runs about 20 times faster than the equivalent MicroPython program. When you are writing embedded programs often speed really does matter. You might not be able to write it in MicroPython and have to move to C/C++. If you can't write it in C/C++ then there is a good chance it can't be done using the hardware you have.
C/C++ isn't significantly harder to work with than other languages. C is particularly simple and easy to use. The micro:bit library is written in C++, but for most of the time you can make use of it in a dialect of C which is quite good enough for the task.
The online compiler
The online compiler for the micro:bit is the best way to get started.
To use the online compiler you have to sign up with mbed.
Go to:
and sign up for an account. At the time of writing, to find the online compiler a you have to go to the mbed Classic Developer site, but this could change.
![Tp177 Micro Example Programs Using Opt Tp177 Micro Example Programs Using Opt](/uploads/1/2/7/0/127061388/195153538.png)
Once you have an account and have signed in, your first task is to get the compiler set up with the micro:bit as its target. You can either go to Platforms and select the vendor as BBC to see the one and only product in that category, i.e. the micro:bit
Alternatively you can go to the compiler and select the target device icon in the top right, which initially shows as 'No device Selected'. Click the Add Platform button and you are back to the Platform selection page. Select the BBC micro:bit and you are back in the same place.
The micro:bit page contains a lot of information but if you just want to work with it in the compiler simply select the Add to your mbed Compiler at the right of the screen:
Following this when you go back to the compiler you will see the BBC micro:bit as the target platform in the top right hand corner:
Hello Blinky
You are now ready to start work on a project but at the moment there isn't a good starter project template. However Lancaster University has provided a template called Blinky to flash an LED - the equivalent of a Hello World program for the device.
There are two way to work with the micro:bit as a pure mbed device or using the specific library that Lancaster University have built. As long as you don't want to change to a different device the Lancaster library is the one to use. The mbed library makes it easy to write a single program that will work on different hardware and this is its big advantage. You can use the mbed library with the micro:bit but unless you really do want to move to another piece of hardware it is better to use the micro:bit library.
To get a starter project you have to select the samples template because the blinky templates use the mbed library.
It takes some time to build the project but eventually you will see the finished project ready for you to edit.
The C/C++ programs are all in the source directory as usual but the difference is that you are using the microbit library rather than the usual mbed library.
If you want to you can compile (ignore the compiler warnings) and run the sample without modification just to check everything works. If you select the compile button the program is compiled and then downloaded to your machine. You then have to download the file - microbit-samples_NRF51_MICROBIT.hex - the the micro:bit via the usb drive in the usual way. When you run the program you will discover that by default you will see a Hello World message scroll across the screen.
If you want to see any of the other demos in action simply open the MicroBitSamples.h file and uncomment the line corresponding to the one you want to run.
![](/uploads/1/2/7/0/127061388/911594537.png)