Software Architect at Genzeon Corporation in Malvern, Pennsylvania, Microsoft .NET MVP, Husband, Dad and Geek.
30521 stories
·
21 followers

The Big Picture—is now available! – Richard Seroter's Architecture Musings

1 Share

I’ll be honest with you, I don’t know much about horses. I mean, I know some things and can answer basic questions from my kids. But I’m mostly winging it and relying on what I remember from watching Seabiscuit. Sometimes you need just enough knowledge to be dangerous. With that in mind, do you really know what “cloud-native” is all about? You should, and if you want the foundational ideas, my new on-demand Pluralsight class is just for you.

Clocking in at a tight 51 minutes, my course “Cloud-native Architecture: The Big Picture” introduces you to the principles, patterns, and technologies related to cloud-native software. The first module digs into why cloud-native practices matter, how to define cloud-native, what “good” looks like, and more.

The second module calls out cloud-native patterns around application architecture, application deployment, application infrastructure, and teams. The third and final module explains the technologies that help you realize those cloud-native patterns.

This was fun to put together, and I’ve purposely made the course brief so that you could quickly get the key points. This was my 18th Pluralsight course, and there’s no reason to stop now. Let me know what topic you’d like to see next!

Read the whole story
alvinashcraft
1 hour ago
reply
West Grove, PA
Share this story
Delete

Flutter developers survey: Documentation is key to Flutter’s success

1 Share

It’s been a good year for Flutter. Designed to make creating mobile apps for both Android and iOS easier, this SDK offers native cross-platform development to developers all over the world. Flutter is meant to improve developer’s productivity and speed thanks to a focus on native performance and advanced visuals.

Flutter has continued to soar ever since their last beta release. Earlier this year, the beta 3 release gave developers increased widgets, Dart 2 upgrades, syntax changes, GIF support, and a whole lot of documentation.

Recently, the Flutter team took to the internet to poll users and see how things are shaking out. The results of their survey aren’t a surprise: developers overwhelmingly enjoy using Flutter.

SEE ALSO: Dart 2 marks the rebirth of the programming language powering Flutter

Flutter developer survey 2018

This July, the User Experience Research team conducted a survey to review user satisfaction and needs. A respectable 1,016 developers responded to the survey. So, what did they find out?

First off, Flutter developers are a diverse bunch with all kinds of backgrounds. Given that it’s for mobile development, it’s a given that Android developers are well represented (67%), but web developers (45%) and iOS developers (30%) made a decent showing.

flutter

Source: July 2018 Flutter User Survey

After all, given the general imbalance between Android and iOS developers, this disparity is pretty understandable.

Additionally, while 15% of users had reported that they’d already published a Flutter app, a further 52% responded that they are working on an app that should be released in the next six months. So, get ready for a whole swarm of Flutter apps in the near future!

Overall, Flutter users are generally satisfied with the platform. 92% of respondents reported that they were satisfied or somewhat satisfied with the mobile SDK. In a win for future platform growth, more than half said that they’d recommend it to others.

Nearly 80% of users found that Flutter was very helpful in helping developers reach their maximum engineering velocity and implement their ideal UI.

SEE ALSO: Flutter beta 3 sails into production for cross-platform development

Importantly, the comments of the survey highlighted praise for Flutter’s documentation. We’ve talked about how documentation is crucial for a technology’s success; after all, if new users can’t figure out how to use your cutting edge tech, they won’t adopt it.

Flutter is safe on that account: 93% of respondents consider the quality good, very good, or excellent. However, the team identified a number of ways the documentation can improve, including adding more sample code, making it easier to find samples, and more. In particular, the research team decided that each widget’s API should have a sample of code to make it easier for developer to utilize properly.

More Cupertino-style widgets are coming and improving. The CupertinoApp is a convenience widget that wraps a number of widgets that are commonly required for an iOS-themed application.

Getting started with Flutter

Want to try Flutter out for yourself? Head on over to their website or GitHub page to try this free, open source mobile app SDK.

As an open source project, all help is welcome.

Read the whole story
alvinashcraft
1 hour ago
reply
West Grove, PA
Share this story
Delete

How Building a Women Who Code Chapter Made Me a Better Engineer

1 Share

And a way better person.

In January 2017, back when I was living in Ukraine, I noticed an ad on a local forum for IT professionals about the first meeting of a newly created Women Who Code Kyiv branch, where the organisers promised to tell more about this global organisation and how it supports women.

I must say, I was growing up in a tough poor environment, and the girls from my school made me genuinely hate women. I felt like I'm an exception from my gender: I loved to study, I was really into STEM and did it way better than even all the boys around me, and I didn't want to gossip about someone's appearance or personal issues. The reality is my sample was too small and too homogeneous to draw any conclusions, but nevertheless it was affecting my life views for a while. I regret it, but at least I have a legit excuse :-p

So I was very sceptical about the whole women community thing-y. As a "proper" systems programmer, with a master's degree and a few years of experience, I was sure that my area of expertise is a very complex one, that only chosen can master the sacred knowledge of memory management, and other, more user-oriented areas with automated garbage collection, are easy. I never met a woman that would love to poke operating systems, so I was sure I was alone in the world with such passions. Now I know that I just wasn't looking hard.

On that evening there were four speakers: a manual QA, a project manager, a designer and a student. So I texted my husband: "Can see women, can't see code." I also was arrogant enough to post it on Facebook in comments, where one of the newly assigned branch directors invited me to help and introduce the "code" part. Good news - I immediately felt really ashamed of my words and felt determined to help with bringing a programmer's perspective. Now I know that my former behaviour was influenced by social pressure due to my gender, but back then I didn't blame the society in general, I didn't blame men that were considering women as lesser minds, I didn't even notice every discriminating action that such men did. I blamed women for being less smart and hence damaging to my gender's reputation.

Anyway, I joined the forces. Along with a dozen of other new members. We announced the start of organisational meetings to outline the short- and long-term goals of such community. The first N meetings we would start with a brief introduction of ourselves and why we ended up sitting around that table caring about women in IT. As a result I met so many brilliant women in such different areas of expertise in IT. With every single story I listened to I was like "And where the hell have you been all my life?"

One of the first organisational meetings
One of the first organisational meetings

Simultaneously I discovered that so many women were forced to give up their dreams, listen to their parents, husbands or whoever else intimidated them for more "feminine" choices. I discovered I wasn't alone on this. When I was 14 and told my mum I'm going to study computer engineering she didn't support my choice and tried to make me change my mind with arguments I have to get married and get kids instead of studying all my life, but to me it sounded hypocritical, because my mother had a master's degree in applied mathematics, half of her life worked with punched cards and later programmed in Fortran, and was teaching mathematics in university during my concious years. She was my only female role model, and yet she was discouraging me to follow my heart (or brain in that case :-D). Now I know that she probably didn't want me to experience gender discimination, but back then it appeared to be odd. Nevertheless, I didn't change my mind, I won the battle, but many women did indeed give up in such situations.

We decided to establish the rules of the community first:

  1. Openness to anyone. Every single person can join our organisational meeting, can read the meeting notes later, can participate in discussions online, can vote. By the way, every single our post on Facebook gets approved by at least 4 members in our Slack channel before getting published. We made an extensive use of erratic volunteers by documenting our standards of quality, dividing areas of responsibility into small pieces, and actively encouraging and publicly praising our collaborators.
  2. Code of Conduct. Offenders would be warned for the first time, and excluded from the community if the misbehaviour continued. During 19 months of our work we had only two people excluded. As a result we helped so many women to become first-time speakers and gain confidence, ask questions and gain confidence, or simply gain confidence, because we guaranteed a friendly environment, where no one would be judged or, worse, harassed.
  3. Open to men. Blah-blah-blah, women should stick together, but the truth is with the help of male allies there will be more progress in fighting the gender bias: without male advocates women can easily be outvoted in business. So for every single event the organisers outline that we do not restrict the event to any gender. What we do restrict - the quotas for speakers: so far we had only one male speaker (who was also happy to practice his speaking skills in a positive environment) and tens of female, but we're ready to have up to 25% of men.
Deep Learning meetup
Deep Learning meetup. Yup, sometimes there are more men than women sitting and enjoying talks of our fellow female engineers.

Okay, we set a course to make a first technical meetup (remember, I promised the "code" part?). My point in diversity initiatives is not to make marginalised groups listen to mantras "you are strong, you can do it", but to provide a safe educational space, where everyone can safely assess their technical skills. We found speakers, I discovered design skills in myself and compiled a memorable logo to print on stickers and mugs, we befriended a great company DataArt, who immediately agreed on providing us with a space and snacks, and eventually we were ready to launch our tech initiatives!

Hotfixing stickers
The printing house messed up with stickers, so we had to cut them manually on the last evening before the first event

We had a great turn-out on the event, we had tons of great questions, we had people smiling the whole evening. I haven't seen so many people at a tech event with such happiness in their eyes! Worthless to say, so many happy female engineers!

After the first tech meetup
Hey, ladies, what do you think of our first technical event? Lady Ada approves too.

It was a success according to the feedback, which we collect after every single event. Asking for a feedback was one of the many collective ideas. We worked smoothly as a team, didn't even try to dictate any decisions and justify them with authority.

Family photo
Every single event we do a family photo

On the first event we announced an introductory course based on MIT's 6.0001 "Introduction to Computer Science and Programming Using Python". The course, as any other our event, was free, the applicants had to solve a few puzzles and write a motivational letter in order to apply. These motivational letters were heartwarming and heartbreaking at the same time. One of my favourites was a physics major, who wanted to work at CERN, and she felt that having solid programming skills would help her to become a better scientist.

Going through the applications for the course
Going through the applications for the course

We picked 28 women and 2 men to start studying with us. We had 4 mentors (3 of which were first-time mentors), students would read the course materials and solve the assignments during the week, ask questions online, and then we would meet every Sunday in a space provided by another company that immediately agreed to help us, Beetroot, spend 3 hours studying offline, and then go exhausted but delighted home.

Our CS course group
What women do on Sundays at 10am? Study Computer Science, what else would you think?

28 people made it to the finish line. I can say that 12 of those understood the course well, but we anyway didn't have a goal to teach everyone how to become a programmer: someone wanted to try it out and see whether it works, someone needed basic programming skills in their current positions, someone indeed has changed their career and got a new job in IT.

A celebratory cake
A celebratory cake

One of the most important outcomes for us, mentors, was that all of us became better coaches. A good leader must be a coach, so that worked well for our existing IT careers.

I wouldn't say that finding sponsors was an easy task in Ukraine: companies there are not getting sued for gender discrimination, so unless someone from the top management deeply and sincerely cares - no one wants to blindly throw money into advertising their diversity efforts or "efforts". We had to explain again and again, why companies would benefit from hosting us, but eventually we won, and now we don't have this problem anymore: a lot of businesses are keen to host our community and are practically competing who is going to host us next. Why? Because our team was diverse, and we had journalists among us for good publicity, SMM professionals to help with social media, photographers to document every single event, and amazing engineers among speakers and attendees, who justified all the battles as perspective candidates for our sponsors.

How all of that helped me to become a better engineer?

  1. I grew into a more compassionate person (read: pay attention to documentation, monitoring and tooling), caring about other people's opinions and feelings (read: be a better code reviewer).
  2. I learned to delegate and give up my legos (read: I will never be hoarding the knowledge and damaging the business with this).
  3. I made tons of useful connections (read: people give me their professional advises with great desire).
  4. I practiced negotiation skills (read: I will most likely get what I want, and I anyway always have my épée around :] ).
  5. I set the course on fighting the impostor syndrome, because people would openly tell me their appreciation when I do my job well (read: I've got ready to fight when I think my solution would be better for maintainability and availability). Eventually I learned to openly support other people if I agree with them, which helped to establish bonds across the team.
  6. I matured as a manager, because handling a what was then an 800 members community (1600+ now) was not a trivial task to do. And none of us would have done it on our own. You have probably noticed that I extensively use "we" instead of what is expected in IT interviews, "I". That's because I value the team work here way more than my individual contribution. I suggested many initiatives and solutions, but none of them would have been so good without polishing by the best team I could ever wish. I was asked to become one of the directors of the chapter, which would have brought extra poshness to my CV, but I already knew I am going to move to London soon, so that would've been unfair.

We held many meetups, workshops and networking parties, we shared the knowledge online. I am very happy that none of us have become a silo: the community can easily continue to function without the fear of the bus factor. My fellow colleagues by community, my friends, continue to make robust technical events and attract more and more people to the thought of women being true technical professionals.

Helping to build Women Who Code Kyiv was one of the best time investments for my professional and personal development. I improved on all sides and made great friends, who I dearly miss.

P.S. You can follow more stories of our community by hashtag #wwcodekyiv.

Read the whole story
alvinashcraft
1 hour ago
reply
West Grove, PA
Share this story
Delete

Telltale Games is Shutting Down

1 Share

Bad news, video game fans: Telltale Games, makers of highly-rated interactive stories like The Walking Dead, is shutting down.

The post Telltale Games is Shutting Down appeared first on Thurrott.com.

Read the whole story
alvinashcraft
1 hour ago
reply
West Grove, PA
Share this story
Delete

.NET Oxford Meetup XVIII: Bots, Chimps, and Critical Pilot Making

1 Share

For this month's .NET Oxford meetup we had two talks - one from .NET Oxford co-founder Matt Nield, speaking about Bots; and the other from Clifford Agius talking about Pilot Decision Management.

matt

This time, it was Matt's turn to do the intro. He started off with the usual house keeping (fire exits, etc), before talking about our sponsors (see below), then moving onto the usual news and prize draws (also see below).

As Matt was also doing the first of the two full length talks - he even got to introduce himself!

The slides for the intro talk can be found here, and the Reveal.js source code can be found here.

News

VSTS renamed to Azure Dev Ops

The first news item this month was about the rebranding of VSTS to 'Azure Devops'. They've not only changed the name, but also split out the different components to have their own names. Eg. 'Azure Pipelines' for the build/test/deploy platform, 'Azure Boards' for the issue tracking platform, 'Azure Artifacts' for the package hosting (nuget, npm, etc), 'Azure Repos' for their hosted Git repositories, and 'Azure Test Plans' for managing test plans. They've also re-themed their UI.

.NET Conf

The next news item was about the .NET Conf - a 2-day virtual conference, which coincidentally was two days after the meetup. Obviously at the time of writing has now finished, but all the videos can be watched free on Channel9.


"Chatting with your Data" - Matt Nield

matt

After finishing the intro talk, Matt then stayed on-stage for the first talk of the night - which was all about bot frameworks - with a strong focus on Google Actions with their DialogFlow. He even brought in a Google Home device so he could interact with it vocally as part of his demos! Although, I must admit, when the device was active and listening - it took a lot of willpower to not make prank call-outs asking the device to tell a joke or something! :)

After introducing himself and his background, he spoke about why he wanted to do a talk on bots, showing some stats and estimates highlighting the growing popularity of chatbots within businesses. For example, one slide stated "£3.5 Billion is expected to be invested in enterprise intelligent assistants by 2021". So this certainly is a huge market!

Matt then introduced what he referred to as The Big Three... Microsoft Bot Framework; Amazon Lex; and Google Actions. He described each one, then moved onto some basic platform-independent terminology about working with bots ...

  • Utterance: Anything and everything that the user says
  • Intent: What is it the user is trying to do
  • Entity: Modifies the intent. Can be referred to as slots
  • NLU: Natural Language Understanding
  • Context: Ability to carry entities around between intents
  • Fulfilment: Who we link this to the real world

(the above list has been taken from Matt's slides)

From my understanding - the idea is that a sentence entered by the user (utterance), is broken down into verbs (intents) and nouns (entities), so that the relevant command or query can be performed.

Matt's then moved onto some demos, focusing on Google Actions, using the DialogFlow platform. Google Actions lets you extend Google Assistant using Actions, and DialogFlow is a platform that lets you design and build the Actions with an easy to use web-based user interface.

He started his DialogFlow demo using board games as an example. Creating entities in the UI like chess and tic tac toe, then creating some training phrases, eg. "How about a nice game of chess", as well as training responses, eg. "Nah, I don't want to play". Once entered, he saved the data, waiting a few seconds for DialogFlow to update the data (and presumably doing some form of training), then he demoed the results, asking it questions based on this data.

Next, he showed the concept of Fulfilment, which is where you set up the action to perform. One of the options is to set up a webhook, which can send the results of the query in JSON format. A point that Matt mentioned, was that you have to explicitly tell it what intents to send, something he said that he learnt the hard way! He also spoke about a checkbox called Allow automated expansion, which tells it to recognize entities that have not been explicitly listed. This is something that sounds like it can really bring home the power of this technology, taking advantage of a much larger dataset than you currently have.

Whilst that demo showed a very small example dataset using a couple of board games - Matt wanted to show some real data in his talk. Yo Sushi, a client of Ridgeway (who Matt's works for), very kindly said that he could use their data for this talk.

First he showed his demo without any data. He asked his Google Home device: "Yo Google - I want something with Chicken". The device responded saying that there were no results. Matt then showed the Kentico Cloud portal where the data was kept. Kentico is a CMS platform, and Kentico Cloud is their headless offering, allowing you to de-couple the content management from whatever "view" you want to use - eg. website, mobile app, custom APIs, etc.

Each time a new CMS document is published to Kentico Cloud, it fires off a web-hook to Azure Logic Apps. Bare in mind that this is Yo Sushi - so each document is a dish. This then parses the document, splitting out the dish description and each individual ingredient - then passes that on to DialogFlow - which then meant that he now had data in DialogFlow to process. The Logic App also passes the data of the dish to Azure Search for use later when a user speaks to the bot. Also, the Logic App sent Slack notifications to notify Matt about these events. I really love how Logic Apps allow this easy chaining of events and services!

Once the data had been imported, Matt then demoed it working by calling out to his Google Home device asking for something with Tuna, which Google replied back with the results.

Wrapping up, Matt spoke about some of his findings and thoughts after playing around with this technology - the main conclusion being that whilst it might be easy to use tools like DialogFlow and create intents, etc - the hard bit is creating the engaging conversation.

Links


"Pilot Decision Management" - Clifford Agius

clifford

The second talk of the night was by Clifford Agius. Clifford's primary job is as an airline pilot, but he's also a freelance .NET developer. A lot of our talks are very technical, and it was nice having a talk focusing more on soft-skills for a change. A lot of Clifford's training as a pilot focusses on how to deal with critical decisions required when the unexpected happens, and how to keep calm and deal with the situation in a rational and logical way.

His talk starts off introducing himself; his two careers as both a pilot and a developer; and also showing a rather impressive looking photo of his office in the front seat of a $250m Boeing 787-8 aircraft! He discussed some interesting facts about the Boeing, including talking about the sheer amount of computers on board this kind of craft.

He then showed a video of plane taking off a flock of birds hitting one of the engines, causing an engine failure, asking the audience what they would do as a pilot in this situation. I really enjoyed the way Clifford kept the audience involved in his talk by trying to get everyone to thing about various scenarios and come up with suggestions.

Coincidentally, a book I've read recently called The Chimp Paradox featured very heavily in Clifford's talk. The main point of the book is that your brain has two separate brains which developed independently - the frontal "Human" part, and limbic "Chimp". The Chimp is very emotional and very quick to react with that emotion without applying logical thought first. Whereas the "Human" is much more logical. Obviously this is just an analogy, and there's not really a chimp in your brain - but I can certainly see why the author choose this analogy. I'm sure we've all had situations where you've reacted to something emotionally, and if you'd stopped and calmed down, you'd have dealt with it completely differently. Whether the thing that caused the emotional response was another person who annoyed you, or whether it was the situation itself that caused stress or panic - the idea is that you learn to react with your human side, and not the emotional chimp.

A big focus in Clifford's talk was about how to calm the Chimp and deal with situations with your Human more logical brain. Whilst flying a plane and software development are fundamentally two completely different skillsets - there's a lot that we as developers can learn from this type of "keep calm and react logically" training.

Clifford then spoke about an acronym called 'TDODAR', which stands for Time, Diagnosis, Options, Decide, Assign, Review. Rather than me repeating Clifford's slides here, he had a breakdown of what each step in his slides. But basically, it's a process you can follow to rationally deal with a situation, and plan any outcomes accordingly.

For the last section of his talk, clifford did a short excersise involving the audience. I really liked this, as we've been trying to think of different ways we can get the audience more involved (hence why we started the dev tips section). He split everyone into smaller groups, and gave everyone an airline scenario / problem. He then started a 60 second timer for us in our groups to discuss a course of action. After the 60 seconds, he then added some additional information, then started the timer again. After a few timer runs where Clifford had added more information to the scenario, he then asked a representative from each group to stand up and talk about their decision. I won't detail the scenario here, in case you see his talk elsewhere. If you are due to see his talk elsewhere, then do try to avoid looking at the last few slides linked below if you don't want a spoiler!

exercise1 exercise2 exercise3

Links


Primary Sponsors - Corriculo Recruitment

I mentioned in last month's blog post about the .NET Oxford t-shirts that Corriculo Recruitment were wearing. I also said I regretting that I hadn't taken any pictures showing the t-shirts in that meetup. Well, this time I did! ...

corriulocombined

As you can see, the t-shirts look great! Very impressed with how good the ".NET purple" look on a shirts, and how well it goes with our logo.

Also, as you can see from the picture - Corriculo provided (as they always do!), plenty of food and drinks for our members. Not only this, but they also cover the venue costs, and help us out in plenty of other ways too. A massive thank you to Corriculo for all they've done for us!

Secondary Sponsor - Everstack

Our secondary sponsor is my own company, Everstack. Providing a lot of my own time for organising and managing .NET Oxford. Everstack provides software development and consultation services - specialising in .NET and the Cloud.


Prize Draws

After the news, we then moved onto the prize draws, using my usual WPF Prize Draw app. A massive congratulation to the winners, and a massive thank you to our awesome prize draw sponsors ...

Jetbrains

Congratulations to Mark Osborn for winning a year-long Jetbrains product licence! He wisely choose the combined Rider + Resharper pack!

Manning Books

Congratulations to Iulian Arcus for winning a Manning ebook of his choice! The winner has the choice of any of the awesome Manning ebooks from their website.

Remember that we have our special Manning coupon code (ug367) which gives all of our members a 36% discount on any of their e-books! They've also asked me to share a link to some of their new courses for their LiveVideo system.

Oz-Code

Congratulations to James World for (yet again!) winning the Oz-Code licence! As he already had a licence, he decided to do a little mini-competition at his workplace to give his licence to a colleague. The question he posed to his colleagues was "How large does a .NET object have to be before it gets located in a different logical memory location than a smaller object?", and the winner was Thomas King!

For those that don't know, Oz-Code is a Visual Studio extension that puts your debugger on steroids. Take a look at their website for videos of their features. If you haven't checked it out, then definitely download the trial and have a play. All our member get a free 3 month trial licence (see below) or 50% off a full licence! To claim, you can visit this link to pick up your licence!

prizesponsors


Upcoming Meetups

Below are our upcoming meetups for this year. Not all have been announced on Meetup.com yet, but if you subscribe to the meetup, you'll get email notifications as they are announced.

(Meetup.com event page)

October 9th: Jon Skeet - "C# 8: The story so far":

October's meetup is with Jon Skeet himself, talking all about the upcoming C#8. For this meetup, there'll be a slight change of venue - and it'll be in the St Aldates Conference Centre which is just a few doors down from our usual venue.

(Meetup.com event page)

November: Performance in the JavaScript Era:

November will be with Benjamin Howarth, talking about various different aspects of performance in an era where much more functionality has been pushed to the frontend. This isn't just a JavaScript talk though - it covers a lot of aspects that are important to us .NET developers too!

December: More Lightning Talks!

We thought that December would be a nice place to slot in another lightning talk event. It may be a long way off, but if you do want to do one, feel free to get in touch! First timers are most welcome too!


Please retweet if you enjoyed this post ...

Read the whole story
alvinashcraft
1 hour ago
reply
West Grove, PA
Share this story
Delete

Dart IO - Streaming Strings in a Nutshell

1 Share

Starting Point

Let's start with the example from the io-library-tour on Streaming file Contents:

import 'dart:async';
import 'dart:io';
import 'dart:convert';

Future main() async {
  var config = File('config.txt');
  Stream<List<int>> inputStream = config.openRead();

  var lines = inputStream
      .transform(utf8.decoder)
      .transform(LineSplitter());
  try {
    await for (var line in lines) {
      print('Got ${line.length} characters from stream');
    }
    print('file is now closed');
  } catch (e) {
    print(e);
  }
}

What you can see there is that a 'config.txt' file is processed in a streamed fashion. As part of the processing there are 2 transformations going on.

  1. utf8.decoder that converts a list of unsigned 8-bit integers to a string
  2. LineSplitter that splits the one string into single pieces line by line

The await for will then process the stream basically line by line, where as the EOL-String is part of the yielded list.

Let's dive in

So how is this transform working? For this we going to write a small transformator that will transform every string
to a UPPER CASED string.

Cool, how to start this?

Let's check the API for transform on Stream. There we find a StreamTransformer<T, S> that needs to be passed over. But after checking we figure out that there is higher level concept that implements this interface and simplifies a lot. It's called a Converter<S, T>. So our implementation could like this:

class UpperCase extends Converter<String, String> {
  @override
  String convert(String input) => input.toUpperCase();
}

Well, that was easy! Let's run the whole program and check how it looks:

import 'dart:async';
import 'dart:io';
import 'dart:convert';

class UpperCase extends Converter<String, String> {
  @override
  String convert(String input) => input.toUpperCase();
}

Future main() async {
  var config = File(Platform.script.toFilePath());
  Stream<List<int>> inputStream = config.openRead();

  var lines = inputStream
      .transform(utf8.decoder)
      .transform(LineSplitter())
      .transform(UpperCase());
  try {
    await for (var line in lines) {
      print('Got ${line.length} characters from stream');
      print(line);
    }
    print('file is now closed');
  } catch (e) {
    print(e);
  }
}
$ dart io_expedition_iter0.dart

Unsupported operation: This converter does not support chunked conversions: Instance of 'UpperCase'

Oooops!

What the hell are chunked conversions?

Let's find out where this exception is originated. That is Converter<S, T>:

  /**
   * Starts a chunked conversion.
   *
   * The returned sink serves as input for the long-running conversion. The
   * given [sink] serves as output.
   */
  Sink<S> startChunkedConversion(Sink<T> sink) {
    throw new UnsupportedError(
        "This converter does not support chunked conversions: $this");
  }

It shows us at least that for some reason a Converter seems to operate in 2 ways:

  • like normal where only the convert method is involved
  • like chunked

The doc block indicates that this is for long-running conversion used. Still unclear how or why this is the choosen path by the runtime.

Let's focus on how to solve that

As you can see from the signature a Sink<S> is expected to be returned. In our case a Sink<String> that is simply a destination for sending Strings to. So let's intercept the streaming with a small decorator class like below:

class UpperCaseConversionSink extends StringConversionSinkBase {
  EventSink<String> wrapped;

  UpperCaseConversionSink(this.wrapped);

  @override
  void addSlice(String str, int start, int end, bool isLast) {
    wrapped.add(str.toUpperCase());
  }

  @override
  void close() {
    wrapped.close();
  }
}

and let's implement the start of chunked conversion in the UpperCase Converter like this:

  @override
  Sink<String> startChunkedConversion(Sink<String> sink) {
    return UpperCaseConversionSink(sink);
  }
$ dart io_expedition_iter1.dart

Got 19 characters from stream
LIBRARY IO_TESTING;
Got 0 characters from stream

Got 20 characters from stream
IMPORT 'DART:ASYNC';
Got 17 characters from stream
IMPORT 'DART:IO';
Got 22 characters from stream

# [...]

Nice! That works.

Let's refactor a bit

As you can see the small decorator sink UpperCaseConversionSink has now also knowledge about the conversion technique as well as the UpperCase converter itself. That duplication can be cleaned by introducing a more generic sink that accepts a converter and delegates the concrete conversion back to the converter. Let's see how this might looks:

class StringEventConverterSink extends StringConversionSinkBase {
  EventSink<String> innerSink;
  Converter<String, String> converter;

  // [sink] is wrapped and [converter] knows about the concrete conversion algorithm
  StringEventConverterSink(Sink<String> sink, Converter<String, String> converter) {
    this.innerSink = sink;
    this.converter = converter;
  }

  @override
  void addSlice(String str, int start, int end, bool isLast) {
    innerSink.add(converter.convert(str));
  }

  @override
  void close() {
    innerSink.close();
  }
}

the usage of this looks then like:

class UpperCaseConverter extends Converter<String, String> {
  @override
  String convert(String input) => input.toUpperCase();

  @override
  Sink<String> startChunkedConversion(Sink<String> sink) {
    return StringEventConverterSink(sink, this);
  }
}

The full final code can be found on my github page.

What about closures

Sure, we can even simplify further and make the Converter itself more generic in a way that it only accepts a closure to do the job. So that our usage would look as simple as this

  .transform(StringConverter((String x) => x.toUpperCase()));

So we will introduce a generic StringConverter that accepts this closure:

class StringConverter extends Converter<String, String> {
  String Function(String x) convertFunction;

  StringConverter(this.convertFunction);

  @override
  String convert(String input) => 
      convertFunction(input);

  @override
  Sink<String> startChunkedConversion(Sink<String> sink) => 
      StringEventConverterSink(sink, this);
}

The full code is on my github page too

Round up

  • Dart streams come with build in support for transformators
  • Converter are used for those transformations
  • Long running transformations are processed in chunks
  • String chunk processing can be achieved by subclassing from StringConversionSinkBase
  • Decorator pattern can help to intercept with the source and destination sink
  • Converter can be passed over to the interceptors to keep the logic in one place
  • Even closures can be used to simplify things further

For me the only open question is: dow does Dart decide whether a conversion can happen direct or in a chunked fashion.

If you can clarify this, feel free to leave a comment or share resources that illustrate that further.

Thanks for reading

$ dart --version
Dart VM version: 2.0.0 (Fri Aug 3 10:53:23 2018 +0200) on "macos_x64"
Read the whole story
alvinashcraft
2 hours ago
reply
West Grove, PA
Share this story
Delete
Next Page of Stories