Skip to content

Commit

Permalink
Added Anton's articles from the DB and from https://web.archive.org/w…
Browse files Browse the repository at this point in the history
  • Loading branch information
granicz committed Sep 9, 2020
1 parent f2a7601 commit 0829478
Show file tree
Hide file tree
Showing 37 changed files with 1,485 additions and 5 deletions.
34 changes: 31 additions & 3 deletions user/20200101-writing-instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,43 @@ identity: "-1,-1"

## Editorial notes

* Mark **broken links/pictures** with a footnote, or a note block if they need further explanation and/or alternate links.
* Mark **broken links/pictures** with a footnote, or a note block if they need further explanation and/or alternate links. Example:

* **Link to other blog posts** using a relative link (to the blogs repo's root folder, starting with a `/`) to the `.md` file. Example:
````
> **Review note** <br />
> This resource needs to be re-added.
> ![](https://intellifactory.com/ShowDigitalAsset.aspx?DigitalAsset=140)
````
* **Link to other IntelliFactory blog posts** using a relative link (to the blogs repo's root folder, starting with a `/`) to the `.md` file. Example:
`/user/granicz/20061124-a-logo-interpreter-under-400-lines.md`
Such links are then browseable in the repository and are also converted to `.html` links in the website.
* ...
This means converting the following types of links to repo links:
* `https://forums.websharper.com/blog/*/*`
* `http://websharper.com/blog-entry/*/*`
* `http://fpish.net/blog/*/id/*/*`
* If a link has gone dead but a newer version exists, update to that with a footnote:
```
[^1]: This link has been updated to point to WebSharper reactive forms, which include further pointers on formlets.
```
* If a link is dead and has no direct substitute, give your best alternative in the footnote. Example:
```
[^1]: This link is dead and has been removed. You can find formlet examples on [Try WebSharper](https://try.websharper.com), filtering for snippets that use `UI.Formlets`. These formlets are an enhanced, reactive version of the original formlet library. You can find more information the [WebSharper.Forms README](https://github.com/dotnet-websharper/forms).
```
* If a link is dead and no alternatives exist, try locating an archived version of it, and mark it accordingly with a footnote. Example:
```
[^1]: This link is no longer available. A (broken) snapshot of the page from the Internet archives is available [here](https://web.archive.org/web/20101123072954/http://intellifactory.com/products/wsp/samples/ExtJs.aspx).
```
## Formatting
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---
title: ".NET Composite Formatting with Keyword Expansion"
categories: "websharper,f#"
abstract: ""
identity: "1458,74668"
---
<a href="http://msdn.microsoft.com/en-us/library/txafckwd%28VS.95%29.aspx">Composite Formatting</a> is a feature of .NET framework that comes handy even for F# programmers. Yes, <c>Printf</c>-style formatting generally is much nicer with F#, but there are situations where the format string is not available statically. It can, for instance, be coming from a configuration file.

One common issue with Composite Formatting is that it is not immediately obvious how to expand named arguments. Fortunately, all the pieces of the puzzle are there.

Just a little bit of F#:
<code lang=fsharp>
module Format =
open System
open System.Collections.Generic

let private Split (s: string) =
match s.IndexOf '|' with
| -1 -> (s, "")
| n -> (s.Substring(0, n), s.Substring(n + 1))

type Table<'T>(dict: IDictionary<string, 'T>) =
new (pairs: seq<string * 'T>) =
new Table<'T>(Map.ofSeq pairs)

interface IFormattable with
member this.ToString(format, _) =
let (key, def) = Split format
if dict.ContainsKey key then
dict.[key].ToString()
else
def
</code>
Now we can use string keys (and default values) to expand on keywords within the format strings. This is handy:
<code lang=fsharp>
let fmt = "{0:schema|http}://{0:domain}{0:path}"
System.String.Format(fmt, Format.Table ["domain", "example.com"])
System.String.Format(fmt, Format.Table ["domain", "example.com"; "path", "/products"])
System.String.Format(fmt, Format.Table ["schema", "https"; "domain", "example.com"])
</code>
You can also pass <c>Dictionary</c> and <c>Map</c> objects to the <c>Format.Table</c> constructor.

Even better, Composite Formatting is available not only in <c>String.Format</c> but also in other places such as <c>TextWriters</c>.

As a functional programmer working with F#, I keep discovering basic .NET framework features. Even though this use of Composite Formatting must be trivial, I hope some of you will find it useful.
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
---
title: ".NET Composite Formatting with Keyword Expansion"
categories: "f#,dotnet"
abstract: ""
identity: "1458,74668"
---
[Composite Formatting](https://msdn.microsoft.com/en-us/library/txafckwd%28VS.95%29.aspx) is a feature of .NET framework that comes handy even for F# programmers. Yes, `Printf`-style formatting generally is much nicer with F#, but there are situations where the format string is not available statically. It can, for instance, be coming from a configuration file.

One common issue with Composite Formatting is that it is not immediately obvious how to expand named arguments. Fortunately, all the pieces of the puzzle are there.

Just a little bit of F#:

```fsharp
module Format =
open System
open System.Collections.Generic
let private Split (s: string) =
match s.IndexOf '|' with
| -1 -> (s, "")
| n -> (s.Substring(0, n), s.Substring(n + 1))
type Table<'T>(dict: IDictionary<string, 'T>) =
new (pairs: seq<string * 'T>) =
new Table<'T>(Map.ofSeq pairs)
interface IFormattable with
member this.ToString(format, _) =
let (key, def) = Split format
if dict.ContainsKey key then
dict.[key].ToString()
else
def
```

Now we can use string keys (and default values) to expand on keywords within the format strings. This is handy:

```fsharp
let fmt = "{0:schema|http}://{0:domain}{0:path}"
System.String.Format(fmt, Format.Table ["domain", "example.com"])
System.String.Format(fmt, Format.Table ["domain", "example.com"; "path", "/products"])
System.String.Format(fmt, Format.Table ["schema", "https"; "domain", "example.com"])
```

You can also pass `Dictionary` and `Map` objects to the `Format.Table` constructor.

Even better, Composite Formatting is available not only in `String.Format` but also in other places such as `TextWriters`.

As a functional programmer working with F#, I keep discovering basic .NET framework features. Even though this use of Composite Formatting must be trivial, I hope some of you will find it useful.
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
title: "The Execution Speed of Early vs Late Binding in .NET"
categories: "websharper,f#"
abstract: ""
identity: "1456,74666"
---
This little post documents one of my little experiments with F#, as I am educating myself on the .NET Framework fundamentals.

The interesting issue is the execution speed of late vs early-bound code. Open the F# interactive and try this out.
<code lang=fsharp>
/// A dummy type.
type T =
/// This is the method we want to call.
static member F x = x + 1
</code>
Turn on timing in the Interactive:
<code lang=fsharp>
#time
</code>
First, let as assume we know the type and the method signature at compile time. This is early, static binding, and the result is fast:
<code lang=fsharp>
for i = 0 to 1000000 do
T.F 1
|> ignore
</code>
Now suppose we do not know type <c>T</c> at compile time, but rather have a <c>System.Type</c> object to represent it.

We could then use reflection to invoke the method, as below, but it is slow, several orders of magnitude slower in fact.
<code lang=fsharp>
let m = typeof<T>.GetMethod("F")
for i = 0 to 1000000 do
m.Invoke(null, [| box 1 |])
|> ignore
</code>
If we do not know the type T, but do know the method signature, we can do a lot better using delegates. This is fast:
<code lang=fsharp>
type F = delegate of int -> int
let f = System.Delegate.CreateDelegate(typeof<F>, typeof<T>, "F") :?> F
for i = 0 to 1000000 do
f.Invoke 1
|> ignore
</code>
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
---
title: "The Execution Speed of Early vs Late Binding in .NET"
categories: "f#,optimization,dotnet"
abstract: ""
identity: "1456,74666"
---
This little post documents one of my little experiments with F#, as I am educating myself on the .NET Framework fundamentals.

The interesting issue is the execution speed of late vs early-bound code. Open the F# interactive and try this out.

```fsharp
/// A dummy type.
type T =
/// This is the method we want to call.
static member F x = x + 1
```

Turn on timing in the Interactive:

```fsharp
#time
```

First, let as assume we know the type and the method signature at compile time. This is early, static binding, and the result is fast:

```fsharp
for i = 0 to 1000000 do
T.F 1
|> ignore
```

Now suppose we do not know type `T` at compile time, but rather have a `System.Type` object to represent it.

We could then use reflection to invoke the method, as below, but it is slow, several orders of magnitude slower in fact.

```fsharp
let m = typeof<T>.GetMethod("F")
for i = 0 to 1000000 do
m.Invoke(null, [| box 1 |])
|> ignore
```

If we do not know the type T, but do know the method signature, we can do a lot better using delegates. This is fast:

```fsharp
type F = delegate of int -> int
let f = System.Delegate.CreateDelegate(typeof<F>, typeof<T>, "F") :?> F
for i = 0 to 1000000 do
f.Invoke 1
|> ignore
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
---
title: "WebSharper - Write F# and Run JavaScript"
categories: "websharper,f#"
abstract: ""
identity: "1457,74667"
---
It is an exciting time to be working for IntelliFactory. After quite a bit of hard work, we finally have a public beta release of the <a href="http://intellifactory.com/products/wsp/">WebSharper™ platform</a>. As we continue to work on it, I encourage you to download and play with the current beta release.

WebSharper™ aims to change the way you think about web programming, no more and no less. The idea behind it is very simple. Instead of HTML + JavaScript + PHP/C#/Java code, you write F#, and let the compiler do its magic to get a working AJAX website. Alternatively, you develop a small component and expose it as an ASP.NET control, without having to rewrite your website from scratch.

Let me start with a simple, indeed primitive, example. Let us take the the first problem from <a href="http://projecteuler.net/">Project Euler</a> (a great source of profitable amusement for many of us), solve it in F#, and run it in the browser. To play with it, download and install the beta release of the <a href="http://intellifactory.com/products/wsp/">WebSharper™ platform</a>, start a new WebSharper solution, and change the project code to the following:
<code lang=fsharp>
namespace WebSharperProject

open IntelliFactory.WebSharper
open IntelliFactory.WebSharper.Html

[<assembly: WebSharperAssembly>]
do ()

[<JavaScriptType>]
module Math =

/// Find the sum of all the multiples of 3 or 5 below 1000.
[<JavaScript>]
let ProjectEuler0001 =
seq { 0 .. 999 }
|> Seq.filter (fun x -> x % 3 = 0 || x % 5 = 0)
|> Seq.sum

[<JavaScriptType>]
type Example() =
inherit Web.Control()

[<JavaScript>]
override this.Body =
let answer = Span []
Div [
Div [
Span ["The answer is: "]
answer
]
Input [Type "Button"; Value "Calculate"]
|> On Events.Click (fun _ ->
answer.Text <- string Math.ProjectEuler0001)
]
</code>
Then change the Default.aspx to reference the newly defined <c>Example</c> control:
<code lang=xml>
<%@ Page Language="C#" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<WebSharper:ScriptManager runat="server" />
</head>
<body>
<ws:Example runat="server" />
</body>
</html>
</code>
This is a small example, but there is a lot to get excited about already. Take powerful F# type-checking, functional abstractions, embedded HTML combinators, or ASP.NET integration...

Yes, Project Euler problems are not exactly representative of the tasks a typical web programmer faces. But I firmly believe that a platform that makes difficult things possible should make simlpe things simple.

I will be blogging with more posts on WebSharper™ in the coming days. In the meanwhile, the impatient should definitely check out the <a href="http://intellifactory.com/products/wsp/Tutorial.aspx">Demos</a>.
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
---
title: "WebSharper - Write F# and Run JavaScript"
categories: "f#,websharper,euler"
abstract: ""
identity: "1457,74667"
---
It is an exciting time to be working for IntelliFactory. After quite a bit of hard work, we finally have a public beta release of the [WebSharper platform](https://websharper.com)[^1]. As we continue to work on it, I encourage you to download and play with the current beta release.

WebSharper aims to change the way you think about web programming, no more and no less. The idea behind it is very simple. Instead of HTML + JavaScript + PHP/C#/Java code, you write F#, and let the compiler do its magic to get a working AJAX website. Alternatively, you develop a small component and expose it as an ASP.NET control, without having to rewrite your website from scratch.

Let me start with a simple, indeed primitive, example. Let us take the the first problem from [Project Euler](http://projecteuler.net/) (a great source of profitable amusement for many of us), solve it in F#, and run it in the browser. To play with it, download and install the beta release of the [WebSharper platform](https://websharper.com)[^2], start a new WebSharper solution, and change the project code to the following:

```fsharp
namespace WebSharperProject
open IntelliFactory.WebSharper
open IntelliFactory.WebSharper.Html
[<assembly: WebSharperAssembly>]
do ()
[<JavaScriptType>]
module Math =
/// Find the sum of all the multiples of 3 or 5 below 1000.
[<JavaScript>]
let ProjectEuler0001 =
seq { 0 .. 999 }
|> Seq.filter (fun x -> x % 3 = 0 || x % 5 = 0)
|> Seq.sum
[<JavaScriptType>]
type Example() =
inherit Web.Control()
[<JavaScript>]
override this.Body =
let answer = Span []
Div [
Div [
Span ["The answer is: "]
answer
]
Input [Type "Button"; Value "Calculate"]
|> On Events.Click (fun _ ->
answer.Text <- string Math.ProjectEuler0001)
]
```

Then change `Default.aspx` to reference the newly defined `Example` control:

```xml
<%@ Page Language="C#" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<WebSharper:ScriptManager runat="server" />
</head>
<body>
<ws:Example runat="server" />
</body>
</html>
```

This is a small example, but there is a lot to get excited about already. Take powerful F# type-checking, functional abstractions, embedded HTML combinators, or ASP.NET integration...

Yes, Project Euler problems are not exactly representative of the tasks a typical web programmer faces. But I firmly believe that a platform that makes difficult things possible should make simlpe things simple.

I will be blogging with more posts on WebSharper in the coming days. In the meanwhile, the impatient should definitely check out the [Demos](https://try.websharper.com)[^3].


[^1]: This link has been updated to point to the WebSharper home page.

[^2]: This link has been updated to point to the WebSharper home page.

[^3]: This link has been updated to point to the Try WebSharper home page.
Loading

0 comments on commit 0829478

Please sign in to comment.