r/graphic_design - looking for feedback for my personal portfolio site
Strategy

looking for feedback for my personal portfolio site : graphi…


hey all !

i’m new to reddit and the ways of the site and am learning! pls be patient w me. I’m a freshly graduated graphic designer/illustrator and am looking for some fresh eyes to give me some recs/feedback on my portfolio website. i recently had a potential employer tell me they didn’t know they could click on the images??? wondering what could make this site more user-friendly.

here is the link for the site: https://gabriellestadulis.com/

some questions to consider::

– what additions could be made to the images to invite the viewer to click on them?

– does the sidebar do it for you? (edit: I know the sidebar only shows up when you view it on web, still figuring out how to make it show up on mobile! if you know cargo collective pls help???)

– what initial thoughts come to mind when you open the site?

thank you so much in advance for your feedback!

r/graphic_design - looking for feedback for my personal portfolio site



Source link

Figure/background work
Strategy

Figure/background work


Figure/background work

Hello, this is a composition I made for a work on figure – background. My idea is that the main balloon merges into a chef's hat.

I would like your feedback, as the examples I see are a bit more "compact".

https://preview.redd.it/gla8hyu624i61.jpg?width=597&format=pjpg&auto=webp&s=165d9157b2adc836bfea52e489fa828b225a3afa

submitted by /u/jeronimosd1
[comments]



Source link

Andy Bell
Strategy

Things You Can Do With CSS Today — Smashing Magazine


About The Author

An independent designer and front-end developer who’s trying to make everyone’s experience on the web better with a focus on progressive enhancement and …
More about
Andy

The present and future of CSS are very bright indeed and if you take a pragmatic, progressive approach to your CSS, then things will continue to get better and better on your projects, too. In this article, we’ll look into masonry layout, :is selector, clamp(), ch and ex units, updated text decoration, and a few other useful CSS properties.

CSS is great and getting better all the time. Over recent years, especially, it has evolved really fast, too. Understandably, some of the really handy powers CSS gives you might have slipped you by because of this, so in this article, I’m going to show you some really handy stuff you can do with modern CSS today, and also share some stuff that we can look forward to in the future.

Let’s dig in.

Masonry Layout

Masonry layouts became very popular with Pinterest, Tumblr and Unsplash, and up until recently, we tended to rely on JavaScript to assist with our layout, which is almost never a good idea.

Sure, you can use CSS multicol pretty darn effectively to achieve a masonry layout, but that approach can be problematic with tabbed-focus as it lays content out in columns. This creates a disconnect between the visual layout and the tabbing index.

Fast forward to today (well, very shortly in the future) and a masonry layout is pretty trivial, thanks to an update to CSS Grid. Here’s a complete masonry layout, with gutters, in 6 lines of CSS:

.masonry {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: masonry;
  grid-gap: 1rem;
}

The magic is in grid-template-rows set as masonry, which turns it into the “masonry axis”, thus providing the “filled in” layout we’ve all come accustomed to.

Let’s expand on this and explore a quick demo of creating a responsive masonry layout. Using a slightly modified version of the above CSS, we can replace the grid-template-columns line to use this auto grid method instead:

.masonry {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(16rem, 1fr));
  grid-template-rows: masonry;
  grid-gap: 1rem;
}

The minmax() function allows us to define what the smallest size is for our items, which for us, is 16rem. Then we tell minmax() what the maximum size should be for each item. We declare that as 1fr, which takes 1 portion of the remaining available space.

This definition of grid-template-columns allows our layout to break and stack if it runs out of horizontal space which the masonry axis then automatically sorts our remaining elements for us.

Note: Right now, masonry is only working in Firefox Nightly, or behind a flag, but the grid layout will still work perfectly in non-supporting browsers, making it a decent progressive enhancement target.

See the Pen [Native Masonry Layout With CSS Grid](https://codepen.io/smashingmag/pen/OJbJzVB) by Andy Bell.

See the Pen Native Masonry Layout With CSS Grid by Andy Bell.

Rachel Andrew wrote a great article about CSS Grid Masonry and you can also read the CSS Grid Layout Module Level 3 editor’s draft here for technical details.

Masonry support is currently very low, but as anything on the web, working out what your minimum viable experience is, then building up with progressive enhancement is a resilient way to build things. If you must use a masonry layout, though: I would recommend sticking with the tried-and-tested Masonry.js for now, but stick a ticket in your backlog to replace with native CSS in the future!

Resources

The :is Selector

I imagine a lot of us have had to write some gnarly CSS like this in the past:

.post h1,
.post h2,
.post h3 {
    line-height: 1.2;
}

.post img,
.post video {
    width: 100%;
}

Thankfully, CSS has got our back again with the :is pseudo-class.

That CSS can now be hugely simplified into this instead:

.post :is(h1, h2, h3) {
    line-height: 1.2;
}

.post :is(img, video) {
    width: 100%;
}

When things get more complex, it gets even more useful, because you can chain other selectors, such as :not and :first-child, just like in the following demo:

See the Pen [:is selector demo](https://codepen.io/smashingmag/pen/rNMXYGx) by Andy Bell.

See the Pen :is selector demo by Andy Bell.

The :is() pseudo-class works by taking a passed selector list then translating it into an expanded selector list for us. This allows us to write more compact code and for the browser to do what it does already.

If you have a complex project where specificity is crucial, then the :where() pseudo-class could be useful. The main difference between :is() and :where() is that :where() has zero specificity, whereas the :is() pseudo-class uses the most specific selector in the passed selectors collection. This becomes useful if you think that rules set in your :is() block might need to be overridden out-of-context. This MDN article shows a great example of that.

This :is() pseudo-class has fantastic browser support — aside from IE11 and Opera Mini — so I would absolutely recommend that you start using it today. I would suggest caution with the :where() pseudo-class, though, because right now, only Firefox and Safari support it.

Resources

Logical CSS Functions For Sizing

Responsive design has evolved into intrinsic design over the years as designers rightly push the boundaries of design on the web. There have been lots of hacks in the past — especially with fluid typography — that have been rather fragile, to put it lightly.

We do have some really useful CSS functions that help with sizing: min(), max() and clamp(). The min() function gets the smallest value from two passed parameters and max() does the opposite: grabs the largest value.

The clamp() function is even handier as it allows you to pass a minimum, a maximum and an ideal value. Because of this “locking”, ideal value, clamp() is being used more and more in fluid typography, like Dave Rupert’s legendary FitText because you get a guaranteed baseline, which prevents unpredictable outcomes. It’s the basis of all of these functions because if you set a good baseline as the minimum for min() and a good baseline as the maximum in max(), you’re getting that needed flexibility, insured by a sensible level of control.

These logical functions are way more useful than that though. Here’s a demo where I’m using them not just for a bit of fluid typography sizing, but also to size an avatar image effectively.

See the Pen [Min and Clamp demo](https://codepen.io/smashingmag/pen/YzGmEee) by Andy Bell.

See the Pen Min and Clamp demo by Andy Bell.

In the demo, I’m using min() to size the image and also, calculate the border-radius in the same way. It’s incredibly subtle, but really helps to achieve high design detail on the web, which is great!

Una Kravets has written a fantastically useful article on the use cases of these functions. I also use it to create a flexible wrapper.

Resources

Specific Responsive Units For Typography

There are so many units in CSS that all cater to specific use cases. Did you know that there are units specifically for typography? Of course em and rem are font-size related, but ch and ex are based on the size of the letters themselves.

The ch unit is equal to the width of the 0 character of your rendered font in its size. This scales with the font too, so it’s a really handy way to limit the width of your text, which helps with readability. Also, keep in mind that in proportional typefaces, 1ch is usually wider than the average character width, often by around 20-30%.

The ex unit is equal to the height of the lowercase x character — also known as the “x-height” in more traditional typography. This is really useful for working accurately and responsively with the vertical axis of your typography. One really handy use case for this is making an SVG icon the same height as your text.

In the following demo, I’ve solved two problems with these units. First, I’ve limited the text length with ch and then used the ex unit to position a <sup> and <sub> element, more effectively. This has long been a pain in web design!

See the Pen [CH and EX units demo](https://codepen.io/smashingmag/pen/YzGmELa) by Andy Bell.

See the Pen CH and EX units demo by Andy Bell.

Resources

Updated Text Decoration Control

Text decoration is no longer boring. You can do loads now, thanks to some updates in Text Decoration Level 4. My favourite trick with this is creating a highlight style with text-decoration-thickness, text-decoration-skip-ink and text-decoration-color.

See the Pen [Text decoration demo](https://codepen.io/smashingmag/pen/WNGVXKV) by Andy Bell.

See the Pen Text decoration demo by Andy Bell.

I also like using these new properties to better control underline thickness for heading elements, as they can get pretty heavy in certain fonts.

I strongly recommend you watch this video by Jen Simmons where, as always, she explains CSS properties in a friendly easy-to-understand manner.

Resources

Scroll Margin

This snippet of CSS will vastly improve your websites:

[id] {
  scroll-margin-top: 2ex;
}

When a browser skips to an element with an id — often a heading in a long article like this one — the targeted element would sit flush to the top of the viewport. Not only did this not look great, but it caused issues for fixed headers too.

This property — scroll-margin-top — is the antidote to all of that and is incredibly useful. Check out this demo where I combine it with smooth scrolling:

See the Pen [Scroll margin demo](https://codepen.io/smashingmag/pen/XWjvzop) by Andy Bell.

See the Pen Scroll margin demo by Andy Bell.

Resources

Aspect Ratio

If there was ever something we needed desperately in responsive design, it was native aspect ratio. This is especially needed for embedded media, such as YouTube videos. There’s long been the ol’ padding hack for these containers, but a hack should only be a temporary thing.

Thankfully, we will have aspect-ratio support in major browsers soon.

If you enable layout.css.aspect-ratio.enabled in a Chromium browser, the following demos will be a perfect square and a perfectly responsive YouTube video, respectively:

Square (1:1)

Below is a square that’s always going to keep the same aspect ratio, 1:1 — achieve by defining aspect-ratio: 1 / 1.

See the Pen [Perfect square with aspect ratio](https://codepen.io/smashingmag/pen/zYKgPbw) by Andy Bell.

See the Pen Perfect square with aspect ratio by Andy Bell.

Video (16:9)

For videos, a square would be a quite uncommon format. Instead, we can use 16:9 be defining aspect-ratio: 16 / 9 on the box.

See the Pen [Perfect video embed with aspect ratio](https://codepen.io/smashingmag/pen/oNzKoOq) by Andy Bell.

See the Pen Perfect video embed with aspect ratio by Andy Bell.

Even though aspect-ratio isn’t quite here yet, you should definitely start thinking about it — especially with images, as the following is likely to appear in all browsers as default styles, and is already in Firefox (69 onwards):

img, input[type="image"], video, embed, iframe, marquee, object, table {
  aspect-ratio: attr(width) / attr(height);
}

This is going to be really helpful in reducing page load jank because elements like <img /> will generate a correctly sized box for themselves before they load. My advice is to start adding width and height attributes to elements in the above code sample to give your users a better loading experience. You can find more details about this particular issue on MDN.

Also, speaking about useful articles: take a look at a handy article about the aspect-ratio unit here on Smashing Magazine, written by Rachel Andrew — I highly recommend you to read it.

Resources

Content-Visibility And Contains-Intrinsic-Size

The last one on our tour is content visibility and how it can give us a huge performance boost. Because CSS lets you pretty much do anything, a browser has to calculate everything to render one single element. If you have a huge, complex page, it can result in some reasonably sluggish render and paint times.

The new content-visibility and contains-intrinsic-size properties have arrived to help this and they are great.

With content-visibility: auto, you can tell the browser not to worry about rendering the elements in there while they are outside of the viewport, which can have a massive impact on initial loading speeds. The only problem is that the element with content-visibility: auto set on it loses its height, so we set contains-intrinsic-size to something like 0 400px to hint at what sort of size the element will be when it’s loaded.

These properties allow the browser to skip the initial rendering and instead, as the elements with content-visibility: auto set on them scroll near the viewport, the browser will start to render them. Proper progressive loading!

This video by Jake Archibald demos it really well:

Jake Archibald gives a whirlwind tour in a video presenting the new features and proposals to help users improve the performance of their pages
A talk by Jake Archibald explaining some of the useful CSS features that were released in Chrome recently. Notably, content-visibility.

You can also read this great article, too.

Resources

Wrapping Up And What’s Coming Up

That’s a pretty cool new CSS, right? There’s loads more arriving soon and loads in the long-term pipeline too. We can look forward to Media Queries Level 5 which let us target the current ambient light level and whether or not the user prefers reduced data.

We’ve also got CSS Nesting in draft, which will give us Sass-like nesting capabilities like this:

.my-element {
    background: red;

    & p {
        background: yellow;
    }
}

We’re getting even more control too, with font metrics override descriptors and Cascade Level 5, which introduces layers to the cascade. Prototyping is happening with container queries too!

Lastly, there are some cool new tricks on the horizon, like scroll-linked animations, which will open the door wide-open to a new generation of creative work on the web.

In conclusion, the present and future of CSS are very bright indeed and if you take a pragmatic, progressive approach to your CSS: things will continue to get better and better on your projects too.

Smashing Editorial
(vf, yk, il)





Source link

r/webdev - Peppermint ( Ticket Management ) Alpha is here! 🍵 - A full stack app built in React & Node
Strategy

Peppermint ( Ticket Management ) Alpha is here! 🍵


Hello everyone!

I’d just like to announce the alpha version of my ticket management solution called peppermint. Its a self hostable web app with plans to have native windows and mobile apps in the future.

This is early on and was made by myself so it isn’t anywhere near complete yet.

There is a demo availablehttps://demo.pmint.dev/

Login – admin@admin.com
password – 1234

r/webdev - Peppermint ( Ticket Management ) Alpha is here! 🍵 - A full stack app built in React & Node

Home Dashboard

Features

– Clean modern UI

– To-do lists

– Newsletters / announcements for teams

– Notes creation & time logging

– Ticket creation with links to clients

– Admin dash board

You can see more info herehttps://github.com/Peppermint-Lab/Peppermint

If you run into any issues please open a discord issue with any feature requests or bugs that you may face

Current known bugs

– New ticket modal takes two clicks to launch on initial load.

Technology Used

Thank you for taking the time to look at my project 🙂 If you have any questions please ask



Source link

Angular Live Development Server up
Strategy

Angular Routing Between Components (Angular 9)


Introduction

Angular Routing allows for navigation between components and enables the changing of part of a page, hence the reasoning for developing single page applications. Routing uses the URL in the address bar to change components.

In this article, we are going to create a new Angular application and add components to implement Routing between the components.

Prerequisites

Create a New Application/Add Routing To Existing Application

Create a new Application using Angular CLI:

ng new routing-example 

When prompted, select Yes for angular routing. Or use the following command:

ng new routing-example --routing=true

To add routing to an existing application use the following command:

ng generate module app-routing --flat --module=app

 For more information on setup, follow the steps mentioned here.

Adding New Components:

Add a new component using the following command:

ng generate component <component name>

For this demo, we need two components:

Adding new components will add the default classes in the component as well. In each component, we at least need the file types of the following: .html, .ts, .css, etc.

Adding Information and Routing:

Once components are added we need to add the route path and components to the app-routing.module.ts:

app.component.html:

Add components on the main html page and map them using routerLink. To learn more about RouterLink and ActivatedRoute, click here.

Languages Component

In the languages.component.ts file:

We have created a list of Languages for the drop down. Actual Routing will happen when the getInfo() method is called with the selected language. Once router.navigate is called, the info route will be invoked and the language will be passed along the route.

languages.component.html:

Info Component

info.component.ts:

In init, as the component loads, the value passed in router.navigate is assigned to a variable and the information for the selected language is displayed on the screen.

info.component.html:

Running the Application

  • To run any Angular application, open the terminal on the IDE or Git Bash command prompt.
  • [Optional]Run command— npm install
  • After the application dependences are up to date, run the application using the command ng serve

Angular Live Development Server up

  • Once the application starts on the default port 4200, run the address from any browser:

Angular Router App

Angular Router App Select Language

Angular Router App Languages and Info component

And you have successfully routed two different angular components! Add and customize the application to build on the model. The code for the above demo is available here.

The browser used for this tutorial is FireFox.



Source link

An article where the content is very tight to each side of the viewport
Strategy

Use CSS Clamp to create a more flexible wrapper utility – Qu…


You can use clamp() to set three values: a minimum, an ideal and a maximum.

This is really handy in the context of a wrapper, because it’s a mostly fluid element, often limited with a max-width. This becomes a slight issue in mid-sized viewports, such as tablets in portrait mode, in long-form content, such as this article because contextually, the line-lengths feel very long.

An article where the content is very tight to each side of the viewport

Even though the line lengths are set to a sensible width in CSS, contextually, they still look very long in medium viewports.

If we use clamp() to use a viewport unit as the ideal and use what we would previously use as the max-width as the clamp’s maximum value, we get a much more flexible setup.

/**
 * WRAPPER
 * Sets a max width, adds a consistent gutter and horizontally
 * centers the contents
 */
.wrapper {
  width: 90vw;
  width: clamp(16rem, 90vw, 70rem);
  margin-left: auto;
  margin-right: auto;
  padding-left: 1.5rem;
  padding-right: 1.5rem;
  position: relative;
}

We can set two instances of width so browsers that don’t support clamp() can get a sensible default. Browsers that do support clamp() will override that first value. Good ol’ progressive CSS, right?

You could also use logical properties to set margin and padding. I choose not to in this context because we’re setting both horizontal values anyway.

Here’s how it looks after setting our new wrapper:

An article where the content has much more room horizontally

This is much better now and the content looks like it has much more breathing room, making it easier to read.

The app I’m using for this responsive design testing is called Sizzy and it’s absolutely fantastic. You should get it!

This is a very small tweak, but these design details are what makes the user-experience that little bit better. Check out this handy write-up by Una Kravets.





Source link

r/webdev - How to prevent invalid hrefs from being displayed in the template in Outlook ?
Strategy

How to prevent invalid hrefs from being displayed in the tem…


I have links to emails, in my email template :

<a href="email@email.email">email</a>

Even though my email are valid, because that’s what I have been asked to do, those links don’t display well on Outlook, instead of having a label “email” clickable”, I am having something like this on outlook web application : ( it would be the case even in web versions & mobile too guess )

[email@email.email]Email

Real example :

<a href="email@email.email"
style="text-decoration: none;"><span
style="font-size: 16px; color: #055151; font-weight: 600; font-family: Helvetica, sans-serif !important; text-decoration: underline; text-decoration-color: #055151;">Email</span>
</a>

r/webdev - How to prevent invalid hrefs from being displayed in the template in Outlook ?

Why is this ?



Source link

r/web_design - Font awesome breaks layout
Strategy

Font awesome breaks layout : web_design


I have the following code

    <div class="container login-container">
            <h3>Your current friends</h3>
            <a href="/"class="waves-effect waves-light btn"><i class="material-icons">home</i>Home</a>
            <a href="/friends/add"class="waves-effect waves-light btn"><i class="material-icons">plus</i>Add more friends</a>
    </div>

But for some reason, the icon in the second button breaks the design as the following:

r/web_design - Font awesome breaks layout

But if I set the second icon to also be “home” it works fine

r/web_design - Font awesome breaks layout

Any idea what could be the problem?

Also – why isn’t the icon and the text aligned in heigth?

The CSS

.login-container {
  width: 500px;
  margin-top: 50px;
  text-align: center;
}

The container class comes from materialize



Source link

Should We Initialize an Out Parameter Before a Method Return...
Strategy

Should We Initialize an Out Parameter Before a Method Return…


Surely every C# developer has used out-parameters. It seems that everything is extremely simple and clear with them. But is it really so? For a kickoff, let’s start with a self-test task.

Let me remind you that out parameters must be initialized by the called method before exiting it.

Now look at the following code snippet and see if it compiles.

MyStruct – a value type:

If you confidently answered “yes” or “no” – I invite you to keep reading, since everything is not so clear…

Backstory

Let’s start with a quick flash back. How did we even dive into the study of out parameters?

It all started with the development of another diagnostic rule for PVS-Studio. The idea of the diagnostic is as follows – one of the method parameters is of the CancellationToken type. This parameter is not used in the method body. As a result, the program may not respond (or react untimely) to some cancellation actions, such as canceling an operation by the user’s request. When viewing warnings of the diagnostic, we found code that looks something like this:

Obviously, this was a false positive, so I asked a colleague to add another unit test “with out parameters”. He added tests, including a test of this type:

First of all, I was interested in tests with parameter initializations, but I took a closer look at this… And then it hit me! How does this code actually compile? Does it compile at all? The code was compiling. Then I realized I got an article coming up. 🙂

For the sake of experiment, we decided to change the CancellationToken to some other value type. For example, TimeSpan:

It does not compile. Well, that’s to be expected. But why did the example with CancellationToken compile?

The Out Parameter Modifier

Let’s recall again what is a parameter’s out modifier. Here are the main theses taken from docs.microsoft.com (out parameter modifier):

  • The out keyword causes arguments to be passed by reference;
  • Variables passed as out arguments do not have to be initialized before being passed in a method call. However, the called method is required to assign a value before the method returns.

Please pay attention to the highlighted sentence.

Here is the question. What is the difference between the following three methods, and why does the last one compile, while the first and second do not?

So far, the pattern is not obvious. Maybe there are some exceptions that are described in the docks? For the CancellationToken type, for example. Although that would be a bit strange – what’s so special about it? In the above documentation, I did not find any information about this. Here’s what the documentation suggests: For more information, see the C# Language Specification. The language specification is the definitive source for C# syntax and usage.

Well, let’s see the specification. We are interested in the “Output parameters” section. Nothing new – it is all the same: Every output parameter of a method must be definitively assigned before the method returns.

Well, since the official documentation and specification of the language did not give us answers, we will have to dig into the compiler. 🙂

Exploring Roslyn

You can download the Roslyn source code from the project page on GitHub. For experiments, I took the master branch. We will work with the Compilers.sln solution. As a starting project for experiments, we use csc.csproj. You can even run it on a file with our tests to make sure that the problem is reproducible.

For the experiments we will use the following code:

To check that the error really takes place, we will build and run the compiler on the file with this code. And indeed – the error is right there: error CS0177: The out parameter ‘obj’ must be assigned to before control leaves the current method

By the way, this message can be a good starting point for diving into the code. The error code itself (CS0177) is probably generated dynamically, whereas the format string for the message is most likely somewhere in the resources. And this is true – we find the ERR_ParamUnassigned resource:

By the same name, we find the error code – ERR_ParamUnassigned = 177, as well as several places of use in the code. We are interested in the place where the error is added (the DefiniteAssignmentPass.ReportUnassignedOutParameter method):

Well, that seems like the place we’re interested in! We set a breakpoint and make sure that this fragment is what we need. According to the results, Diagnostics will record exactly the message that we saw:

Well, that’s great. And now let’s change MyStruct to CancellationToken, aaand… We still enter this code execution branch, and the error is recorded in Diagnostics. This means it’s still there! That’s a twist!

Therefore, it is not enough to track the place where the compilation error is added – we have to explore it further.

After some digging in the code, we go to the DefiniteAssignmentPass.Analyze method that initiated the analysis run. The method checks, among other things, that the out parameters get initialized. In it, we find that the corresponding analysis runs 2 times:

There is an interesting condition below:

The case is gradually becoming clearer. We are trying to compile our code with MyStruct. After strict and compat analysis we still get the same number of diagnostics that will be issued.

If we change MyStruct to CancellationToken in our example, strictDiagnostics will contain 1 error (as we have already seen), and compatDiagnostics will have nothing.

As a result, the above condition is not met and the method execution is not interrupted. Where does the compilation error go? It turns out to be a simple warning:

What happens in our case when using CancellationToken? The loop traverses strictDiagnostics. Let me quickly remind you that it contains an error – an uninitialized out parameter. Then branch of the if statement is not executed. It is because diagnostic.Severity is of DiagnosticSeverity.Error value, and the compatDiagnosticSet collection is empty. Then compilation error code is mapped with a new code – a warning’s one. After, the warning is formed and written to the resulting collection. This is how the compilation error turned into a warning. 🙂

By the way, it has a fairly low level. So when you run the compiler, this warning may not be visible if you do not set the flag for issuing warnings of the appropriate level.

Let’s run the compiler and specify an additional flag: csc.exe %pathToFile% -w:5

And we see the expected warning:

Now we have figured out where the compilation error disappears – it is replaced with a low-priority warning. However, we still do not have an answer to the question, what is the distinctiveness of CancellationToken and its difference from MyStruct? When analyzing the method with a MyStruct out parameter, compat analysis finds an error. Whereas when the parameter type is CancellationToken, the error can’t be detected. Why is it so?

Here I suggest grabbing a cup of tea or coffee, because we are about to get down to a painstaking investigation.

I hope you took the advice and got ready. So let’s move on. 🙂

Remember the ReportUnassignedParameter method in which the compilation error was written? Let’s look at the calling method above:

The difference when executing these methods from strict and compat analysis is that in the first case, the slot variable has the value 1, and in the second – -1. Therefore, in the second case, the then branch of the if statement is not executed. Now we need to find out why slot has the value -1 in the second case.

Look at the method LocalDataFlowPass.VariableSlot:

In our case, _variableSlot does not contain a slot for the out parameter. Therefore, _variableSlot.TryGetValue(….) returns false. The code execution follows the alternative branch of the ?:, operator, and the method returns -1. Now we need to understand why _variableSlot does not contain an out parameter.

After digging around, we find the LocalDataFlowPass.GetOrCreateSlot method. It looks like this:

The method shows that there is a number of conditions when the method returns -1, and the slot will not be added to _variableSlot. If there is no slot for a variable yet, and all checks are successful, then an entry is made in _variableSlot: _variableSlot.Add(identifier, slot). We debug the code and see that when performing strict analysis, all checks pass successfully. Whereas when performing compat analysis, we finish executing the method in the following if statement:

The value of the forceSlotEvenIfEmpty variable is false in both cases. The difference is in the value of the IsEmptyStructType method: for strict analysis it is false, for compat analysis – true.

At this point I already have new questions and the desire to do some experiments. So it turns out that if the type of the out parameter is an “empty structure” (later we will get what this means), the compiler considers such code valid and does not generate an error, right? In our example, we remove the field from MyStruct and compile it.

And this code compiles successfully! Interesting… I can’t recall any mention of such features in the documentation and specification. 🙂

Here comes another question: how does the code work when the type of the out parameter is CancellationToken? After all, this is clearly not an “empty structure”. If you check out the code at referencesource.microsoft.com (link to CancellationToken), it becomes clear that this type contains methods, properties, and fields… Still not clear, let’s keep digging.

Let’s go back to the LocalDataFlowPass.IsEmptyStructType method:

Let’s go deep (EmptyStructTypeCache.IsEmptyStructType):

And even deeper:

The code is executed by calling the EmptyStructTypeCache.CheckStruct method:

Here, the execution goes into then branch of the if statement, as the typesWithMembersOfThisType collection is empty. Check out the EmptyStructTypeCache.IsEmptyStructType method, where it is passed as an argument.

We’re getting some clarity here – now we understand what is an “empty structure”. Judging by the methods’ names, this is a structure that does not contain instance fields. But let me remind you that there are instance fields in CancellationToken. So, we go the extra mile and check out the EmptyStructTypeCache.CheckStructInstanceFields method.

The method iterates over instance members. We get ‘actualField’ for each of them. We managed to get this value (field – not null) and next we check if the type of this field is an “empty structure”. This means if we find at least one “non-empty structure”, we also consider the original type to be a “non-empty structure”. If all the instance fields are “empty structures”, then the original type is also considered an “empty structure”.

We’ll have to go a little deeper. Don’t worry, our dive will be over soon, and we’ll put the dots on the ‘i’. 🙂

Look at the method EmptyStructTypeCache.GetActualField:

Accordingly, for the CancellationToken type, we are interested in the SymbolKind.Field case-branch. We can only get into it when analyzing the m_source member of this type. It is because the CancellationToken type contains only one instance field – m_source).

Let’s look at calculations in this case (branch in our case).

field.IsVirtualTupleFieldfalse. We move on to the conditional operator and parse the conditional expression field.IsFixedSizeBuffer || ShouldIgnoreStructField(field, field.Type). field.IsFixedSizeBuffer is not our case. As expected the value is false. As for the value returned by calling the ShouldIgnoreStructField(field, field.Type) method, it differs for strict and compat analysis. A quick reminder – we analyze the same field of the same type.

Here is the body of the EmptyStructTypeCache.ShouldIgnoreStructField method:

Let’s see what is different for strict and compat analysis. Well, you may have already guessed on your own. 🙂

Strict analysis:_dev12CompilerCompatibilityfalse, hence the result of the entire expression is false. Compat analysis: the values of all subexpressions are true; the result of the entire expression is true.

And now we follow the chain of conclusions, rising to the top from the very end. 🙂

In compat analysis, we think that we should ignore a single instance field of the CancellationSource type, which is m_source. Thus, we decided that CancellationToken is an “empty structure”, hence no slot is created for it, and no “empty structures” are written to the cache. Since there is no slot, we do not process the out parameter and do not record a compilation error when performing compat analysis. As a result, strict and compat analysis give different results, which is why the compilation error is downgraded to a low-priority warning.

That is, this is not some special processing of the CancellationToken type. There is a number of types for which the lack of out parameter’s initialization will not lead to compilation errors.

Let’s try to see in practice which types will be successfully compiled. As usual, we take our typical method:

And try to substitute different types instead of MyType. We’ve already figured out that this code compiles successfully for CancellationToken and for an empty structure. What else?

If we use MyStruct2 instead of MyType, the code also compiles successfully.

When using this type, the code will compile successfully if MyExternalStruct is declared in an external assembly. If MyExternalStruct is declared in the same assembly with the CheckYourself method, it does not compile.

When using this type from an external assembly, the code no longer compiles, as we changed the access modifier of the _field field from private to public:

With this kind of change, the code will not compile either, since we changed the field type from String to int:

As you may have guessed, there is a certain scope for experimentation.

Let’s Recap

Generally speaking, out parameters must be initialized before the called method returns control to the caller. However, as practice shows, the compiler can make its own adjustments to this requirement. In some cases, a low-level warning will be issued instead of a compilation error. Why exactly this happens, we discussed in detail in the previous section.

But what about the types for which you can skip initializing out parameters? For example, parameter initialization is not required if the type is a structure with no fields. Or if all fields are structures with no fields. Here is the case with CancellationToken. This type is in the external library. Its only m_source field is of a reference type. The field itself is not available from external code. By these reasons the compilation is successful. Well, you can come up with other similar types – you’ll be able to not initialize out parameters and successfully compile your code.

Going back to the question from the beginning of the article:

Does this code compile? As you have already understood, neither ‘Yes’ nor ‘No’ is the correct answer. Depending on what MyStruct is, what fields are there, where the type is declared, etc. – this code can either compile or not compile.

Conclusion

What we went through today is diving into the compiler’s source code to answer a seemingly simple question. I think we will repeat this experience soon, as the topic for the next similar article is already there. Stay in touch. 

By the way, subscribe to my Twitter account, where I also post articles and other interesting findings. This way you won’t miss anything exciting.





Source link

Front-of-the-front-end and back-of-the-front-end web develop...
Strategy

Front-of-the-front-end and back-of-the-front-end web develop…


The Great Divide is real, and I’m pleased that the terms “front-of-the-front-end” and “back-of-the-front-end” have gained traction ever since I quipped about them on the Shop Talk Show. A few of my clients have actually moved away from a culture of “we only hire full-stack developers” and have instead adopted the labels “front-of-the-front-end” and “back-of-the-front-end” to help them better organize their teams and refine their hiring practices. This makes me incredibly happy as these labels provide a much-needed distinction between the types of web development that need to occur in order to build successful web things.

A succinct way I’ve framed the split is that a front-of-the-front-end developer determines the look and feel of a button, while a back-of-the-front-end developer determines what happens when that button is clicked.

I’ve written about my experience as a front-of-the-front-end developer, but I thought it would be helpful to create a standalone post that spells out the roles and responsibilities of both front-of-the-front-end and back-of-the-front-end developers.

Front-of-the-front-end developer

A definition: A front-of-the-front-end developer is a web developer who specializes in writing HTML, CSS, and presentational JavaScript code.

Their responsibilities may include:

  • Crafting semantic HTML markup with a strong focus on accessibility, in order to make experiences that are friendly to browsers, assistive technologies, search engines, and other environments that can consume HTML.
  • Creating CSS code that control the look and feel of the web experience, tackling colors, typography, responsive layout, animation, and any other visual aspect of the UI. Front-end designers architect resilient CSS code with a focus on modularity, flexibility, compatibility, and extensibility.
  • Authoring JavaScript that primarily manipulates objects in the DOM, such as making an accordion panel open or close when you click the accordion title, or closing a modal window.
  • Testing across browsers and devices to ensure the UI is functional and good-looking on a never-ending stream of desktops, mobile phones, tablets, and all manner of other web-enabled devices (and even anticipating ones that haven’t been invented yet!)
  • Optimizing the performance of front-end code in order to create lightweight, fast-loading, snappy, jank-free experiences.
  • Working with designers to ensure the brand, design vision, and UX best practices are properly translated into the browser, which, to remind you, is the actual place actual people will go to use the actual product.
  • Working with back-of-the-front-end developers to ensure the front-end code is compatible with back-end code, services, APIs, and other technology architecture.
  • Creating a library of presentational UI components authored in a templating language are packaged up to be consumed by other developers.
  • Authoring and documenting a robust, intuitive component API for each presentational component so developers consuming the component can easily plug whatever they need into to it.
  • Writing unit tests for the presentational UI component library code to ensure the components look and function properly.
  • Architecting the flexibility/composibility of the component library, working with developers to understand how open/composable or rigid/locked down each component should be.
  • Maintaining the presentational components as a product, meaning handling versioning, deploying, governance, release notes and all the operational stuff goes into maintaining a software product.

Historically, the split between “front-end” and “back-end” was clear: front-end developers wrote HTML, CSS, and JavaScript, and back-end developers wrote PHP, Python, ASP.NET, or some other back-end language. But now that “JavaScript dun got big” , much of that code that would have historically been written in another language is now written in JavaScript, blurring lines between both front-of-the-front-end and back-of-the-front-end developers but also back-of-the-front-end and traditional back-end developers. So it’s worth defining what exactly a back-of-the-front-end developer does.


Back-of-the-front-end developers

A definition: A back-of-the-front-end developer is a web developer who specializes in writing JavaScript code necessary to make a web application function properly.

Their responsibilities can include:

  • Writing application business logic to handle things like CRUD functionality and to control application state, routing, cache, authentication, and so on. In short, back-of-the-front-end developers write the code necessary for the application to function properly.
  • Wiring up, integrating with, and even authoring data sources, services, and APIs. This can include things like retrieving, manipulating, and displaying content from a CMS, or posting data to the appropriate service when a user submits a form.
  • Consuming the UI code authored by the front-of-the-front-end developers in order to compose screens and connect real functionality data, and services.
  • Optimizing the performance of JavaScript code in order to create a snappy, responsive application that fetches and fetches/posts data quickly.
  • Writing end-to-end, integration, and other tests to ensure the application works as intended.
  • Architecting and managing JavaScript-based infrastructure, such as Node frameworks, tools, and services.
  • Managing devops stuff, such as JavaScript bundlers, deployment tooling, CI/CD stuff, and so on
  • Working with front-of-the-front-end developers to ensure the UI component library contains all the components, variants, and API hooks necessary in order to build the application and all its states.
  • Working with the product team to ensure all product states are accurately represented in the living, breathing application
  • Working with other backend developers and IT to ensure the right technical infrastructure is in place and that the application is able to properly integrate/communicate with non-JavaScript backend code.

Note: I’m not a back-of-the-front-end developer, so these bullets may not be comprehensive or entirely accurate. Feel free to suggest and correct!

Some considerations

  • The line between front-of-the-front-end and back-of-the-front-end can be fuzzy and varies greatly from developer to developer. It’s totally possible that one developer might be able to perform many tasks across the front-end spectrum. But it’s also worth pointing out that’s not super common.
  • These roles and responsibilities are constantly changing, but the general split between “look and feel” and “functionality” continues to be a decent delineation.
  • A directly-consumable UI component library can serve as a healthy handshake between front-of-the-front-end developers and back-of-the-front-end developers as it creates a clear separation between different kinds of code.

So that’s that! This is an area I’ve been passionate about for a long while, so I’d love to hear about your experience navigating these waters. Are you a frustrated “full-stack” dev? Has your organization shifted toward a “front-of-the-front-end/back-of-the-front-end” split? Feel free to get in touch.



Source link