diff --git a/.github/workflows/generate-related.yaml b/.github/workflows/generate-related.yaml new file mode 100644 index 0000000000..92b9999bd9 --- /dev/null +++ b/.github/workflows/generate-related.yaml @@ -0,0 +1,33 @@ +name: Generate Read More related + +on: + push: + branches: + - gh-pages + +jobs: + generate-read-more: + runs-on: "ubuntu-latest" + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Setup node + uses: actions/setup-node@v3 + with: + node-version: 16.13.x + cache: npm + - run: npm install + - run: npm run compute-embeddings --OPENAI_API_KEY=${{ secrets.OPENAI_API_KEY }} + - run: npm run generate-related + - name: Create Pull Request if Needed + uses: peter-evans/create-pull-request@v4 + with: + title: Auto Generated Read More Links + branch: auto-generated-read-more-links + commit-message: Auto Generated Read More Links + base: gh-pages + body: | + This PR was automatically generated by a GitHub Action. + It contains the auto generated related links for all posts. + add-paths: | + _data/related.yml \ No newline at end of file diff --git a/.gitignore b/.gitignore index 06d2dced0f..333e696e2d 100644 --- a/.gitignore +++ b/.gitignore @@ -13,4 +13,5 @@ Gemfile.lock .vscode/ /container_gem_cache/ -/dist/ \ No newline at end of file +/dist/ +/scripts/generate-related/data/ \ No newline at end of file diff --git a/_data/authors.yml b/_data/authors.yml index 65164131ed..b856dfebd2 100644 --- a/_data/authors.yml +++ b/_data/authors.yml @@ -28,6 +28,7 @@ active-authors: - dkerr - dmcnamee - dnicholas + - dscarborough - dogle - drees - dsmith @@ -327,6 +328,10 @@ authors: twitter-url: "https://twitter.com/darrenpsmithweb" twitter-handle: darrenpsmithweb picture: picture.jpg + dscarborough: + name: "Dan Scarborough" + author-summary: "
I am a Developer at Scott Logic.
" + picture: picture.png dtheasby: name: "Drew Theasby" author-summary: "Test Engineer at Scott Logic
" diff --git a/_drafts/ai-government-guide-data-literate-leaders.markdown b/_drafts/ai-government-guide-data-literate-leaders.markdown new file mode 100644 index 0000000000..d3ac0da158 --- /dev/null +++ b/_drafts/ai-government-guide-data-literate-leaders.markdown @@ -0,0 +1,84 @@ +--- +title: 'Getting ready for AI in government: a guide for data-literate leaders' +date: 2023-10-20 14:29:00 Z +categories: +- Artificial Intelligence +tags: +- digital government +- government +- '' +- Government +- Machine Learning +- ChatGPT +- data literacy +summary: While the latest AI technologies may be new, your best next steps in harnessing + them are tried and tested, and you already have many of the skills you need. I set + out in this blog your best next steps to get ready for AI in Government. +author: jmcevoy +--- + +There’s a lot of hype around the benefits and use cases of AI, especially since OpenAI’s ChatGPT was released at the end of last year. This hype is one of the things that makes it quite hard to predict the long-term versus short-term potential of AI to change key aspects of how the public sector operates. + +I’m deeply suspicious of the folk out there who are making absolute declarations about when these changes will take place, but one thing is true: with the proliferation of AI tools that give human-like responses, you no longer need to be an expert in AI to see what AI is capable of doing. + +In my view, some of the future-gazing is at least in part a distraction, and we should instead look at the AI work happening right now to understand how to be ready and how to manage the risks. AI is already being used in both central and local government. If you’re under pressure to be ahead of the curve but worried about the immaturity of the technology and unsure where to start, I’d suggest your first step is the same as it always was – start with a clear understanding of what your organisation aims to achieve and the challenges that need to be overcome. + +As I’ll go on to explain, while the technologies may be new, your best next steps in harnessing them are tried and tested, and you already have many of the skills you need – but first, here are some examples of real uses in government that help to illustrate the points I’ll go on to make. + +## AI use in Government + +The UK Government has already begun to make careful use of these technologies over the last few years. When I worked at Government Digital Service (GDS) there was a [great example](https://www.gov.uk/government/case-studies/how-gds-used-machine-learning-to-make-govuk-more-accessible) on [GOV.UK](https://www.gov.uk/) which supported one of the core goals at the time – making content more accessible to users. At the time there were thousands of untagged pages of content that we estimated would take years for civil servants across government to review and tag. The project team built a supervised machine learning model that could recognise patterns in the pages, read the content, and suggest suitable tags. The final model was able to tag 96% of the content in about six months, making huge amounts of content more accessible to citizens. + +A machine learning example from local government is that of [Swindon Council](https://digileaders.substack.com/p/how-one-council-used-machine-learning) which, with a tiny team of three people and seed funding of just £100K, successfully introduced AI to a number of internal business challenges – one notable example being the use of machine learning to cut their document translation costs by 99.6% and reduce the turnaround time from weeks to minutes. + +Since 2015, the US Citizenship and Immigration Services (USCIS) has been using [Emma](https://www.uscis.gov/tools/meet-emma-our-virtual-assistant), their virtual assistant, to reduce the burden on call centres which receive a large number of calls for general information on the immigration process. In 2020, Emma responded successfully to [35 million enquiries from more than 11 million users](https://www.acus.gov/sites/default/files/documents/Automated%20Legal%20Guidance%20%285.26.22%29%20-%20final-1_0.pdf). By 2021, Emma’s success rate was 93% in English and 90% in Spanish. As another example of supervised machine learning, Emma trains with adjudicators and case managers, as well as through interactions with the public. + +Since 2014, Singapore has had a similar concept called ‘[Ask Jamie](https://www.tech.gov.sg/products-and-services/ask-jamie/)’ which they have implemented across 70 government agency websites. It supports the Singapore government’s no-wrong-door approach by surfacing answers from across all of those websites, regardless of the site on which the user posed their question. + +I’ve spoken previously about the [galvanising effect the pandemic had on cross-government collaboration](https://blog.scottlogic.com/2023/01/24/why-rapid-collaboration-needs-careful-preparation.html), providing a single point of focus for the COVID response. AI can find patterns where humans can’t and can process increasing amounts of data, offering interesting opportunities in medicine, education and healthcare. A brilliant example of this is the [National COVID-19 Chest Imaging Database case study](https://transform.england.nhs.uk/key-tools-and-info/data-saves-lives/improving-care-through-research-and-innovation/national-covid-19-chest-imaging-database-case-study/) of work undertaken by teams from NHSX, the British Society of Thoracic Imaging (BSTI), and Royal Surrey County Hospital NHS Foundation Trust. This project used technology that BSTI had developed to collate imaging data from over 90 hospitals to help clinical researchers in medical imaging and artificial intelligence fields learn as much as possible about COVID-19 by analysing a comprehensive sampling of acute chest imaging. + +## Your best next steps + +All of these examples had their origin in a clear organisational challenge. Technology was just the means to an end. So, as we explore the best next steps you can take in harnessing AI’s potential, where should we start? + +### Start with organisational challenges + +Fund the problem, not the tech – and start small, focusing on value. As my excellent colleague, Pete Chamberlin [recently said](https://www.linkedin.com/feed/update/urn:li:activity:7112164418049687554/), one of the problems with innovation is that it distracts organisations from fixing the ‘plumbing’. All of the examples I mention above address a priority problem space of the government – important challenges that the organisations needed to address and, in many cases, which would have taken humans a long time and lots of effort to solve. New technologies made a big difference in these cases, but it’s vital that the technology is harnessed to the organisational need and not the other way around. + +Be wary of AI-centric project proposals and remember that most [AI projects aren’t predicted to deliver what is expected](https://www.gartner.com/en/documents/3894131). Projects shouldn’t be spun up just to make use of a new, hyped technology; new technologies should make your pre-existing organisational challenges easier to solve. Run a discovery to explore your riskiest assumptions: What are the users’ needs? Is there a more established technology that can solve your problem? Where is your data held, how much of it do you have and what condition is it in? Do you have a multidisciplinary team to do the work with specialist skills in place who can advise on the data and the business area? + +### Familiarise yourself with the technologies + +It’s important to gain a good understanding of the capabilities of different AI technologies so that you’re able to recognise real opportunities within your organisational challenges. This doesn’t require you to become expert in any of them. Focus on having enough understanding of the capabilities and risks inherent in different AI technologies to allow you to ask the right questions and make the right judgements in selecting and leading projects that use AI. At Scott Logic, we’ve been [busy blogging about AI](https://blog.scottlogic.com/category/ai.html) for a few years now – hopefully, you’ll find some useful material there to help build out your expertise. + +Within the public sector at least, it’s likely that most use cases at this stage will begin as trials and require some experimentation to test your hypotheses. This experimentation comes with a degree of failure and learning baked into it. The examples above show the benefits of having some success with using AI to solve issues, but experimenting in this way takes time and also comes with a cost and a high likelihood of at least some failure and/or rework. + +We need to encourage informed experimentation and give people the skills to do this well. Experimentation is not always encouraged in the public sector. The systems that underpin government aren’t designed to handle rapid learning as it can look very much like failure. However, [studies](https://www.mckinsey.com/capabilities/strategy-and-corporate-finance/our-insights/how-covid-19-has-pushed-companies-over-the-technology-tipping-point-and-transformed-business-forever) have shown that only organisations that encourage experimentation and innovation (through a balance of talent, technology, strategy and culture) achieve positive outcomes through digital transformation. A culture of curiosity (as my colleague Matt Phillips describes it [in his recent white paper](https://www.scottlogic.com/white-paper-value-generative-ai)) and experimentation is a big part of a data-literate culture. + +### Bring to bear your data literacy + +I wrote earlier this year about [how data literacy gives leaders the edge](https://blog.scottlogic.com/2023/01/12/how-data-literacy-gives-leaders-the-edge.html). Data-literate leaders know how to work with data, they know how to derive actionable insights from data, and they are data storytellers who are able to use data to shape and communicate a narrative about the overarching strategy of their organisation. Importantly, they are also able to see when the data doesn’t look right, and spot issues in the approaches their organisation is taking. These skills and qualities are technology-agnostic and just as relevant and important in the context of AI as they are in the face of any other new technology. + +As a data-literate leader, your understanding of the work involved in managing, interrogating and analysing data, as well as your skills in identifying and managing risks, are key to identifying opportunities for exploration. The examples I shared above of AI use in governments relied on people with precisely these skills. And as AI adoption beds in and grows in your organisation, your data literacy will be vital in helping to shape the governance surrounding its use, getting value from investment, and using data to tell the story to those around you. + +### Be adaptive + +One quality that will be critical in the next few years of transformation is adaptability, both personally and at a strategic level. Some of these technologies are being released and [adopted with unprecedented speed](https://en.wikipedia.org/wiki/ChatGPT#Reception). The underpinning governance, law and policy are following behind, and largely not yet in place, which leaves us with a lot of uncertainty. There are going to be some years of flux and change as the technologies continue to evolve, their societal impact becomes clearer, and the laws governing their use come into force both nationally and internationally. + +This doesn’t mean that you should do nothing. It’s another argument for informed experimentation, and retaining a ruthless focus on the problem space and the value delivered. Anchor these experiments in measurable data and take a pragmatic, incremental approach to applying the technologies to real, pre-existing challenges. + +### Foster data-literate cultures + +As pointed out recently by the [Ada Lovelace Institute](https://www.adalovelaceinstitute.org/policy-briefing/foundation-models-public-sector/), there is a heightened risk for the public sector when using nascent AI tools. This is due to the increased responsibility around the sensitivity of the data being handled, the expected standards of robustness, and the requirements of transparency or explainability around decision-making. + +These responsibilities affect the culture within the public sector, and managing or understanding these risks is partly why it takes time to do new things or change the old way of doing things. At the same time, the NHS example above shows that sometimes it is only the public sector that can solve certain problems, and that using these new technologies can rapidly deliver really astonishing results. + +Focusing on data literacy and building into an organisation’s culture the knowledge of how to work with data is key to managing these risks and making effective use of new technologies, including AI. As well as making informed decisions about when using AI is appropriate, teams will need the skills to collect, analyse and interpret data for AI models and also to understand and communicate the outcomes that models might generate. + +Initiatives like [One Big Thing](https://moderncivilservice.blog.gov.uk/2023/07/19/one-big-thing-data-upskilling-for-all-civil-servants/) have an important role to play in this, with its aim of improving services and helping citizens through better interpretation, use, presentation and communication of data. If we can improve the overall data quality and get data flowing across those organisational boundaries, organisations will be well placed to assess and take opportunities when they crop up. + +### Fix the plumbing + +So far I’ve focused a lot on the skills and qualities you can bring to bear in getting ready to harness AI. But if you’re looking for a hands-on, practical next step in order to get started and be ready, beginning with your data is a rock-solid idea. This is a hyped technology that makes an incredibly strong case for improving your data architecture, quality and stewardship. To quote Pete Chamberlin's post that I linked to earlier, “The more I use it and work on strategies for deploying it, the more I think: this requires data-plumbing-fixing activities!” + +I totally agree, Pete. \ No newline at end of file diff --git a/_posts/2014-12-05-2014-12-5-Foyer-Screen-continued.md b/_posts/2014-12-05-Foyer-Screen-continued.md similarity index 100% rename from _posts/2014-12-05-2014-12-5-Foyer-Screen-continued.md rename to _posts/2014-12-05-Foyer-Screen-continued.md diff --git a/_posts/2017-12-18-difficult-people.md b/_posts/2017-12-18-difficult-people.md index 8bda36c799..cf05f88a35 100644 --- a/_posts/2017-12-18-difficult-people.md +++ b/_posts/2017-12-18-difficult-people.md @@ -4,88 +4,116 @@ date: 2017-12-18 00:00:00 Z categories: - jmelon - Delivery -author: jmelon -layout: default_post summary: In our professional work life we regularly come across difficult people we’d love to avoid, ignore or get away from - this is especially true if you are a consultant or contractor and work with so many different people. In reality however, we have to collaborate also with difficult people. In this article I want to look at the situations, types of people and some techniques that can help. +author: jmelon image: jmelon/assets/going_bananas.jpeg +layout: default_post --- Some days are just bitter and grey. I need to finish this boring task that seems to take forever because of this bloke who is just so unhelpful that it borders on sabotage. Whenever I ask him to give me access to the right data he comes up with excuses, other priorities and such things. After I tried today for the nth time I have finally got the paperwork from him to fill in to get the right permissions - blimey, he could have given me it right the first time round (am I really happy about getting paperwork?). -![Going bananas]({{site.baseurl}}/jmelon/assets/going_bananas.jpeg) - In our professional work life we regularly come across difficult people we’d love to avoid, ignore or get away from - this is especially true if you are a consultant or contractor and work with so many different people. Usually however, we can’t do that: we need to work with them as productively as we can. Even if we don’t work with a difficult person everyday, we may need to convince them of something from time to time or get some output from them. Dealing with difficult people is obviously a challenge which everyone approaches in a different way. Being the structured (and enthusiastically chaotic) person I am I like to think about it analytically. Taking it step by step, I first want to talk about what kind of difficult people and types of situations are out there. Then, let’s think about strategies for dealing with them. ### Types of difficult -- There is the team mate who is just not doing things as the team agreed. -- The project manager interfering with the team, falling back into command and control mode and trying to force the team to do specific agile experiments. -- It’s the DB administration team not letting the project team deal with the dev environment database changes but instead wants lengthy documentation defining each single change. They are also a bottleneck with a 6 week waiting queue and they will only change their priorities with senior management intervention. -- It is the vendor test analyst that constantly argues that any bug raised is actually only minor because a workaround exists - no matter how intricate it is. -- The client project manager that always wants the team to cut the estimates because he expects them to be ‘experts in the field’. -- The project sponsor coming in with the whip of enforced velocity targets that have not even been derived by any meaningful technique - asking for constant overtime to meet them. All the while the quality needs to be top notch, of course. -- The travel department escalating travel costs to a small fortune without telling you beforehand and giving you the chance to tell them how to book it much more cheaply. -- Or the guy calling you asking you to identify yourself to him with lots of personal data without any willingness proving his own identity. + +* There is the team mate who is just not doing things as the team agreed. + +* The project manager interfering with the team, falling back into command and control mode and trying to force the team to do specific agile experiments. + +* It’s the DB administration team not letting the project team deal with the dev environment database changes but instead wants lengthy documentation defining each single change. They are also a bottleneck with a 6 week waiting queue and they will only change their priorities with senior management intervention. + +* It is the vendor test analyst that constantly argues that any bug raised is actually only minor because a workaround exists - no matter how intricate it is. + +* The client project manager that always wants the team to cut the estimates because he expects them to be ‘experts in the field’. + +* The project sponsor coming in with the whip of enforced velocity targets that have not even been derived by any meaningful technique - asking for constant overtime to meet them. All the while the quality needs to be top notch, of course. + +* The travel department escalating travel costs to a small fortune without telling you beforehand and giving you the chance to tell them how to book it much more cheaply. + +* Or the guy calling you asking you to identify yourself to him with lots of personal data without any willingness proving his own identity. The list could go on and wouldn’t even get boring by the tenth page. After the fact this all tends to be quite funny, we share impossible anecdotes and laugh about it together. However, in the moment these situations are never very funny but instead rather infuriating, mind-boggling, perplexing or just plain silly. -- It can add complexity to the situation dependent on how we relate to the difficult person: -- Team colleague of the same company -- Team colleague of a different company, e.g. a client/vendor consultant or a contractor -- Someone in a different team -- Someone in a different department -- Or even someone in a different organisation including for example a regulatory authority -- It could be a superior, your boss or just someone else up the corporate hierarchy -- Someone you are supposed to be leading or managing, i.e. you are responsible or accountable for their work -- Or an employee you are line-managing +* It can add complexity to the situation dependent on how we relate to the difficult person: + +* Team colleague of the same company + +* Team colleague of a different company, e.g. a client/vendor consultant or a contractor + +* Someone in a different team + +* Someone in a different department + +* Or even someone in a different organisation including for example a regulatory authority + +* It could be a superior, your boss or just someone else up the corporate hierarchy + +* Someone you are supposed to be leading or managing, i.e. you are responsible or accountable for their work + +* Or an employee you are line-managing ### Some simple observations + This is basically a tour around a typical organisational hierarchy - people in all places can be difficult. Interestingly enough from my own observations it usually doesn’t help if you are formally in a higher hierarchy position or even line-managing the person in question. I think it is really important for everybody to realise that -_anybody in a company can just say ‘no’ - and there is not much you can really do about it_ +*anybody in a company can just say ‘no’ - and there is not much you can really do about it* using any kind of authority. This is so because people saying ‘no’ (or being difficult in another way) have usually reasons why they are difficult. That is actually another interesting fact: -_Virtually nobody is difficult without a reason that makes their behaviour perfectly sensible from their own perspective._ +*Virtually nobody is difficult without a reason that makes their behaviour perfectly sensible from their own perspective.* There are certainly also personality traits that make collaboration more difficult but mostly it is not one trait but instead two that clash. For example the controlling personality working with a self-organising agile team, or the rule following person in the midst of an agile transformation clashing with the rule breaker. This leads us to the right kind of question to tackle the debacle: -_Why is that person acting difficult?_ +*Why is that person acting difficult?* We can try a lot of things when dealing with difficult people, try to convince, coerce, use another’s authority with an escalation or make some kind of a deal to name a few. These things can work but they rarely have great outcomes, at best we get a mild form of consent at worst the person says ‘yes’ but does not buy in or maybe doesn't even do what we need them to do maybe offering only some flimsy excuse later on. ### A way forward + So, what better way is there? Fundamentally, we are talking about a situation where two different needs exist and both needs are understood in two different ways. If we want our need to be fulfilled we have to communicate the need and our reasons for it properly. However, our explanation will always be filtered by the perspective of the other person. That means we should first try to understand that perspective so we can predict the filtering. This should be our starting point even before we talk about our needs. However, this is not a simple thing as we don’t know what exactly might affect the others opinion with regards to our specific need. Some things we should consider are: -- Are there specific ways of working that person needs to comply with? -- Is there a lot of pressure on the person? -- Which expectations do they have on their own duties? -- What impact does our need have on them? -- Are there important personal circumstances like a recent or ongoing illness? -- What culture is the person coming from and what impact does that have on the way they work and communicate? -- Is the person afraid of certain things, do they feel comfortable with their role? -- What is the person's current mood - is there a specific good and bad time to approach them? + +* Are there specific ways of working that person needs to comply with? + +* Is there a lot of pressure on the person? + +* Which expectations do they have on their own duties? + +* What impact does our need have on them? + +* Are there important personal circumstances like a recent or ongoing illness? + +* What culture is the person coming from and what impact does that have on the way they work and communicate? + +* Is the person afraid of certain things, do they feel comfortable with their role? + +* What is the person's current mood - is there a specific good and bad time to approach them? #### Relationships galore + This is just an example list of things to consider - there are many more to look out for. It is evident that we cannot just use a checklist and go through it in a conversation. Instead we need to build an ongoing professional relationship to enable us to understand the other person. That means we have meaningful conversations regularly and we treat the other person with respect even if we occasionally cringe inside or even need to agree to disagree. If we have a working relationship we only need to look for the specifics of one situation and approach the conversation with the right clarifying questions. An ongoing relationship also means that the other person understands us better over time and we gain trust. #### Why not just ask? + Sometimes we will still not get the reaction we are looking for. It is important then to check with powerful open questions why they are reacting in this way and to make sure the message you were intending to get across has arrived undamaged. If you need someone to do something to fulfil your need it is more powerful to explain your need and ask for their help instead of asking them to do something that fulfils our need. That way they can come up with a solution to our problem that suits them, we get much more buy-in because it is their idea and not us pushing something on them. Even if we try your best, friction can still occur. The other person might still not be helpful. Hopefully we will at least understand better why - enabling us in turn to look for other solutions or getting the right kind of help. Often it can help to ask how to get the person's support such that they are able to help. Maybe they feel not empowered to change their priorities or they don’t have the confidence to do the task. #### Escalation + If the person remains unhelpful despite all efforts we sometimes need help from a superior, e.g. to make a decision enabling the other person or to clarify if the difficult person should really just get on with it - to name just two possible reasons. If we are considering an escalation we should be well aware that this is going to add pressure on the person. It is important to check if that will actually be useful for your cause and if so you should let the person know that you need to take these steps - not to use it as a whip but just out of fairness. In the end we still need a respectful relationship with them at work - even if they are unhelpful for us. Revenge, open fighting and shouting, swearing at people are all unacceptable and will never help anybody. If our temper gets us we should apologise for any unacceptable behaviour or harsh words. That doesn’t mean we need to suddenly get all cosy with the person but professionalism is a necessity for all of us. ### Conclusion + The key to working together in a constructive and trusting way is to be genuinely interested in the other side: we need to understand our co-workers, their needs, opinions, preferred ways of working, mood, communication types and so forth. Respect, honesty, transparency, fairness are just a few key values we should always aim to follow for healthy and fruitful relationships. We always need to be careful about violent communication - it is very easy to unintentionally hurt someone with words. Whenever we communicate with someone - especially someone who we don’t know very well - we always need to keep in mind that they may misunderstand us in a bad way. -In the end we should always remember that sometimes we are the difficult person - maybe even without realising it. +In the end we should always remember that sometimes we are the difficult person - maybe even without realising it. \ No newline at end of file diff --git a/_posts/2018-12-05-a-developers-intro-to-android.md b/_posts/2018-12-05-a-developers-intro-to-android.md index 62215f718e..c97d871bda 100644 --- a/_posts/2018-12-05-a-developers-intro-to-android.md +++ b/_posts/2018-12-05-a-developers-intro-to-android.md @@ -33,8 +33,6 @@ The code examples given in this article are all written in [Kotlin](https://kotl You can design an Android app any way you like, however Google has published several guides on what they consider to be the optimal app design. This diagram shows my interpretation of these guides. -![Android Architecture Overview](%7B%7Bsite.baseurl%7D%7D/jporter/assets/ArchitectureOverview.png) - At the top there is an activity. Only one of these can be active at once, and they serve as entry points to the app. Next there are fragments, which are reusable layouts like activities, but differ in that they can be embedded within activities, or other fragments. As activities and fragments are very similar (they are both essentially a page), there is some discussion online about where a single-activity (and multiple fragment) or multi-activity (and single fragment) app is best. The conclusion I have come to is that you should have one activity for every entry point to the app that you need and use fragments for all other use cases. On my first Android project, my team and I designed our app to have two activities; a login activity and a main app activity. The latter contained fragments for various pages, and each of these in turn contained more fragments for smaller components of the UI. The next level down from a fragment is a view. Every component on the screen is a view, from text boxes to lists to buttons. These views are controlled from within an activity or fragment and receive their data from view models. Each fragment or activity that needs to display data in views has a corresponding view model to provide that data. The distinction between view and view model comes from the [Model-View-Controller (MVC)](https://www.tutorialspoint.com/design_pattern/mvc_pattern.htm) design pattern and is especially important in Android for effective testing. Unit testing cannot easily be done on Android views and components, so separating out view model code is essential. I will discuss this in more detail in a future article. @@ -43,9 +41,7 @@ While each activity or fragment corresponds to one view model, each view model c ### Lifecycle -A key concept when working with activities and fragments is [lifecycle](https://developer.android.com/guide/components/activities/activity-lifecycle). The lifecycle of an activity or fragment, or sometimes views (lifecycle owners) comprises 6 states, and a number of method calls that run at specific points after their creation or before their destruction. These states are; `CREATED`, `STARTED`, `RESUMED`, `PAUSED`, `STOPPED`, `DESTROYED`. The `onEvent(..)` methods run before their corresponding events and act as transitions between these states, as shown in the diagram below. - -![Android Lifecycle Overview](%7B%7Bsite.baseurl%7D%7D/jporter/assets/LifecycleOverview.png) +A key concept when working with activities and fragments is [lifecycle](https://developer.android.com/guide/components/activities/activity-lifecycle). The lifecycle of an activity or fragment, or sometimes views (lifecycle owners) comprises 6 states, and a number of method calls that run at specific points after their creation or before their destruction. These states are; `CREATED`, `STARTED`, `RESUMED`, `PAUSED`, `STOPPED`, `DESTROYED`. The `onEvent(..)` methods run before their corresponding events and act as transitions between these states. Lifecycle aware components (such as views) will behave differently in each state. For example, LiveData will be ACTIVE only when the lifecycle owner is in the `STARTED` or `RESUMED` states. This is discussed further below, along with an explanation of what LiveData is. @@ -91,8 +87,6 @@ The `data class` in this example is a [feature of the Kotlin language](https://k All the content for your app should be stored within [XML files in the resources package](https://developer.android.com/guide/topics/resources/providing-resources). This includes UI layouts, colours, fonts and strings, and other resources. Layout files can correspond to an activity, fragment or view, or can be included within other layout files. [Android Studio has a visual layout editor](https://developer.android.com/studio/write/layout-editor) that you can use to design these layouts, which is a lot easier than editing the XML directly. -![Layout Editor](%7B%7Bsite.baseurl%7D%7D/jporter/assets/ResourceLayoutFile.PNG) - One reason resources are abstracted out of the code into separate XML files is so that different resources can be provided for different builds of the app. For example, using this system it is easy to translate your app into French or to cater to different screen sizes. In the past, all these different variants would be installed on every user's phone, but now you can publish your app as a "bundle", which allows Google Play to install only the necessary resources on a device. This can significantly reduce the size of your published app. An issue I have found when designing these layouts is the vast number of possible layouts that can be used, all of which behave differently; positioning views on the screen can be difficult if you have no experience with Android. I found it useful spending a lot of time understanding these different layouts and views, and how they interact, so I recommend that if you are starting out with Android you do the same. diff --git a/_posts/2020-09-16-typescript-builders.md b/_posts/2020-09-16-typescript-builders.md index 81806f0d57..0ff0e2b752 100644 --- a/_posts/2020-09-16-typescript-builders.md +++ b/_posts/2020-09-16-typescript-builders.md @@ -8,13 +8,13 @@ tags: - typescript - types - featured -author: swaterman -layout: default_post summary: TypeScript's type system is amazing, but it can't do everything. In this post, I demonstrate how the builder pattern takes my types to the next level. We walk through an example in detail, so you can start using builders too. +author: swaterman summary-short: Using the builder pattern, we can take our types to the next level. image: swaterman/assets/ts-builders/Builders-Usage.svg +layout: default_post --- The builder pattern in TypeScript is amazing. @@ -38,16 +38,17 @@ Let's imagine a basic data processing task: 1. Take an integer string as input -1. Reverse it -1. Parse it back into an integer -1. Multiply it by 5 -~~~ts -const input = "524"; -const a = input.split("").reverse().join(""); -const b = parseInt(input, 10); -const c = b * 5; -~~~ +2. Reverse it + +3. Parse it back into an integer + +4. Multiply it by 5 + + const input = "524"; + const a = input.split("").reverse().join(""); + const b = parseInt(input, 10); + const c = b * 5; The rest of this blog post is dedicated to over-engineering that tiny bit of code. It's clearly overkill in this case, but that's inevitable when we use a simple example to demonstrate an advanced technique. @@ -59,29 +60,25 @@ We can define a function that takes a few config parameters: -~~~ts -function process(input: string, radix: number, multiplicand: number) { - const a = input.split("").reverse().join(""); - const b = parseInt(input, radix); - const c = b * multiplicand; - return c; -} -process("524", 10, 5); -~~~ + function process(input: string, radix: number, multiplicand: number) { + const a = input.split("").reverse().join(""); + const b = parseInt(input, radix); + const c = b * multiplicand; + return c; + } + process("524", 10, 5); Often, it's easier to take the config as a single object: -~~~ts -function process(input: string, config: {radix: number, multiplicand: number}) { - const a = input.split("").reverse().join(""); - const b = parseInt(input, config.radix); - const c = b * config.multiplicand; - return c; -} -process("524", {radix: 10, multiplicand: 5}); -~~~ + function process(input: string, config: {radix: number, multiplicand: number}) { + const a = input.split("").reverse().join(""); + const b = parseInt(input, config.radix); + const c = b * config.multiplicand; + return c; + } + process("524", {radix: 10, multiplicand: 5}); That's useful as it allows the config to be loaded from a JSON file. *Conveniently* it also makes our job easier later on. @@ -105,24 +102,20 @@ Their main benefit is the ability to *encapsulate* many functions, allowing them Since we create pipelines so often, a reusable function that creates pipelines sounds really useful. The JavaScript implementation is simple using higher-order functions: -~~~js -function createPipeline(functions) { - return function pipeline(initState, config) { - let state = initState; - for (function of functions) { - state = function(state, config), + function createPipeline(functions) { + return function pipeline(initState, config) { + let state = initState; + for (function of functions) { + state = function(state, config), + } + return state; + } } - return state; - } -} -~~~ It's even possible as a (long) one-liner: -~~~js -const createPipeline = initState => - functions.reduce((state, function) => function(state, config), initState); -~~~ + const createPipeline = initState => + functions.reduce((state, function) => function(state, config), initState); @@ -133,11 +126,9 @@ That's no fun though - why even use TypeScript if you're just gonna ignore type Let's try actually putting in some effort, and see how narrow we can make the types. As a first attempt, I get something like this: -~~~ts -function createPipeline