<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:georss="http://www.georss.org/georss" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" version="2.0">
  <channel>
    <title>Nesterovsky bros</title>
    <link>http://www.nesterovsky-bros.com/weblog/</link>
    <description />
    <language>en-us</language>
    <copyright>Nesterovsky bros</copyright>
    <lastBuildDate>Mon, 26 Oct 2026 07:01:03 GMT</lastBuildDate>
    <generator>newtelligence dasBlog 2.3.12105.0</generator>
    <managingEditor>contact@nesterovsky-bros.com</managingEditor>
    <webMaster>contact@nesterovsky-bros.com</webMaster>
    <item>
      <trackback:ping>http://www.nesterovsky-bros.com/weblog/Trackback.aspx?guid=62d188d2-69d5-4b11-9182-ff291448d3f6</trackback:ping>
      <pingback:server>http://www.nesterovsky-bros.com/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,62d188d2-69d5-4b11-9182-ff291448d3f6.aspx</pingback:target>
      <dc:creator>Vladimir Nesterovsky</dc:creator>
      <georss:point>0 0</georss:point>
      <wfw:comment>http://www.nesterovsky-bros.com/weblog/CommentView,guid,62d188d2-69d5-4b11-9182-ff291448d3f6.aspx</wfw:comment>
      <wfw:commentRss>http://www.nesterovsky-bros.com/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=62d188d2-69d5-4b11-9182-ff291448d3f6</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
AI agents are good at connecting steps. But some steps need more than a local shell:
a particular runtime, more CPU or memory, or a place to keep working files between
runs. We wanted flexible compute environments that can be selected to fit each task,
while still being callable through the same MCP workflow.
</p>
        <p>
Azure, AWS, and Google Cloud all have ways to run this kind of workload. As IBMers,
though, IBM Cloud was our first choice; we also like its comparatively close-to-the-metal
feel. Within IBM Cloud, Code Engine fits the execution model: each request can run
in an isolated container, with its own image and CPU/memory profile. Its jobrun lifecycle
gives us the operations we need: submit work, check its state, read logs, and request
deletion.
</p>
        <p>
MCP v2 protocol version <code>2025-07-28</code> that transitions the core architecture
to be completely stateless made it possible to host implementation in Code Engine
Application. A client submits a script and may choose an image and resource profile;
a job can also use persistent data from a mapped COS store. The Application starts
the job and returns its terminal ID to the client. That ID identifies the job in later
requests to check its status, retrieve logs, or request deletion. Code Engine runs
the work independently of the Application.
</p>
        <h2 id="tools-and-options">Tools and options
</h2>
        <ul>
          <li>
            <code>shell</code> starts a job from inline Bash or a script path, with an optional
image (<code>shell</code>, <code>java</code>, <code>node</code>, <code>python</code>, <code>dotnet</code>, <code>all</code>,
or a full image reference) and supported CPU/memory profile.</li>
          <li>
            <code>status</code> checks the job state using its terminal ID.</li>
          <li>
            <code>output</code> retrieves logs by terminal ID, optionally selecting range or tail
lines.</li>
          <li>
            <code>stop</code> requests job deletion; use it only when you need to abort a long-running
job.</li>
        </ul>
        <p>
The bundled images include common tools and dependencies so many tasks can run without
additional setup. Resource profiles must be supported by Code Engine and fit the project's
quotas.
</p>
        <p>
For larger scripts or data that should persist across jobruns, configure a Code Engine
persistent data store backed by Cloud Object Storage (COS). It is mounted read/write
at <code>/mnt/data</code>, so jobs can share persistent files and callers can pass
a script path there instead of sending a large script inline.
</p>
        <h2 id="security">Security
</h2>
        <p>
The terminal service must run behind an API Gateway that authenticates callers. The
service can start jobs that execute arbitrary shell scripts, so exposing it without
authentication would let unauthenticated users consume compute, run untrusted commands,
and access any persistent storage available to those jobs.
</p>
        <p>
The gateway must forward the authenticated user's name and email as trusted identity
headers, and must remove client-supplied versions of those headers before setting
its own. The service uses these values to populate job identity and resolve storage
paths; accepting caller-supplied identity would allow one user to impersonate another.
</p>
        <p>
If persistent storage is configured, its bucket prefix must include <code>$USER</code>,
for example <code>terminal-store:users/$USER</code>. The service expands that placeholder
from the gateway-verified username, keeping each user's files in a separate path.
Without a user-specific prefix, concurrent callers can share or overwrite files, and
one user's job may read data written by another user's job.
</p>
        <p>
Forwarding the email also gives jobs a verified contact identity for auditing and
user-aware workflows. Only gateway-verified identity should be used for these purposes;
other request headers are not a substitute for authentication.
</p>
        <p>
Secrets needed by a job can be supplied as MCP HTTP headers instead of script text
or tool arguments. For example, with the default <code>x-terminal-</code> header prefix, <code>x-terminal-api-key</code> becomes
the job's <code>API_KEY</code> environment variable. In VS Code, define the header
using a password-protected input:
</p>
        <pre style="white-space: pre-wrap;">
          <code class="lang-json">{ <span class="hljs-attr">"servers"</span>:
{ <span class="hljs-attr">"code-engine-terminal"</span>: { <span class="hljs-attr">"url"</span>: <span class="hljs-string">"https://api.&lt;project-id&gt;.&lt;region&gt;.codeengine.appdomain.cloud/terminal/mcp"</span>, <span class="hljs-attr">"type"</span>: <span class="hljs-string">"http"</span>, <span class="hljs-attr">"headers"</span>:
{ <span class="hljs-attr">"Authorization"</span>: <span class="hljs-string">"Bearer
${input:terminal-token}"</span>, <span class="hljs-attr">"x-terminal-api-key"</span>: <span class="hljs-string">"${input:job-api-key}"</span> }
} }, <span class="hljs-attr">"inputs"</span>: [ { <span class="hljs-attr">"id"</span>: <span class="hljs-string">"terminal-token"</span>, <span class="hljs-attr">"type"</span>: <span class="hljs-string">"promptString"</span>, <span class="hljs-attr">"description"</span>: <span class="hljs-string">"Authentication
token for the terminal MCP gateway"</span>, <span class="hljs-attr">"password"</span>: <span class="hljs-literal">true</span> },
{ <span class="hljs-attr">"id"</span>: <span class="hljs-string">"job-api-key"</span>, <span class="hljs-attr">"type"</span>: <span class="hljs-string">"promptString"</span>, <span class="hljs-attr">"description"</span>: <span class="hljs-string">"API
key to expose to the job as API_KEY"</span>, <span class="hljs-attr">"password"</span>: <span class="hljs-literal">true</span> }
] } </code>
        </pre>
        <p>
The MCP client adds these values to the HTTP request; they are not part of the agent's
shell-tool arguments or prompt. The gateway must still authenticate the caller, remove
untrusted copies of privileged headers, and forward only explicitly approved secret
headers. Secrets become available to the job process as environment variables, so
scripts should not print them and logs or child processes must be handled accordingly.
Prefer short-lived, least-privilege credentials.
</p>
        <h2 id="example-analyze-a-dataset">Example: Analyze a dataset
</h2>
        <p>
This conversation shows an agent analyzing <code>/mnt/data/sales.csv</code> with the
Python image: it starts a job, checks its status, and retrieves the result using the
returned terminal ID.
</p>
        <p>
          <strong>User:</strong> I uploaded <code>/sales.csv</code> to the mounted COS store.
Can you report the row count, total revenue, and revenue by region?
</p>
        <p>
          <strong>AI:</strong> I’ll run a short Python analysis against the mounted file, then
check the job output.
</p>
        <pre style="white-space: pre-wrap;">
          <code class="lang-json">{ <span class="hljs-attr">"tool"</span>: <span class="hljs-string">"shell"</span>, <span class="hljs-attr">"arguments"</span>:
{ <span class="hljs-attr">"script"</span>: <span class="hljs-string">"python - &lt;&lt;'PY'\nimport
pandas as pd\ndf = pd.read_csv('/mnt/data/sales.csv')\nprint(f'Rows: {len(df)}')\nprint(f'Total
revenue: {df[\"revenue\"].sum():.2f}')\nprint('Revenue by region:')\nprint(df.groupby('region')['revenue'].sum().to_string())\nPY"</span>, <span class="hljs-attr">"image"</span>: <span class="hljs-string">"python"</span>, <span class="hljs-attr">"resourceProfile"</span>: <span class="hljs-string">"cpu-1-mem-4g"</span> }
} </code>
        </pre>
        <p>
          <strong>AI:</strong> The job is running. Its terminal ID is <code>k4m2...</code></p>
        <pre style="white-space: pre-wrap;">
          <code class="lang-json">{ <span class="hljs-attr">"tool"</span>: <span class="hljs-string">"status"</span>, <span class="hljs-attr">"arguments"</span>:
{ <span class="hljs-attr">"terminalId"</span>: <span class="hljs-string">"k4m2..."</span> }
} </code>
        </pre>
        <p>
          <strong>AI:</strong> The job completed. I’ll fetch the report.
</p>
        <pre style="white-space: pre-wrap;">
          <code class="lang-json">{ <span class="hljs-attr">"tool"</span>: <span class="hljs-string">"output"</span>, <span class="hljs-attr">"arguments"</span>:
{ <span class="hljs-attr">"terminalId"</span>: <span class="hljs-string">"k4m2..."</span> }
} </code>
        </pre>
        <p>
          <strong>AI:</strong> The file contains 1,248 rows with total revenue of 84,392.50.
The largest regional total is West at 29,410.00.
</p>
        <h2 id="run-it-in-your-account">Run it in your account
</h2>
        <p>
Deploy the MCP service as a Code Engine Application with its own container image,
and register the job images (<code>shell</code>, <code>java</code>, <code>node</code>, <code>python</code>, <code>dotnet</code>,
and <code>all</code>) in a container registry the project can access.
</p>
        <p>
The service does not authenticate or authorize callers, so place it behind an API
Gateway that does.
</p>
        <p>
For example, the Application might be reachable inside the project at <code>http://terminal.&lt;project-id&gt;.svc.cluster.local/mcp</code>.
Clients would connect through a public gateway URL such as <code>https://api.&lt;project-id&gt;.&lt;region&gt;.codeengine.appdomain.cloud/terminal/mcp</code>.
</p>
        <p>
In VS Code, add the gateway endpoint to the project's <code>.vscode/mcp.json</code> and
prompt for the gateway token:
</p>
        <pre style="white-space: pre-wrap;">
          <code class="lang-json">{ <span class="hljs-attr">"servers"</span>:
{ <span class="hljs-attr">"code-engine-terminal"</span>: { <span class="hljs-attr">"url"</span>: <span class="hljs-string">"https://api.&lt;project-id&gt;.&lt;region&gt;.codeengine.appdomain.cloud/terminal/mcp"</span>, <span class="hljs-attr">"type"</span>: <span class="hljs-string">"http"</span>, <span class="hljs-attr">"headers"</span>:
{ <span class="hljs-attr">"Authorization"</span>: <span class="hljs-string">"Bearer
${input:terminal-token}"</span> } } }, <span class="hljs-attr">"inputs"</span>: [
{ <span class="hljs-attr">"id"</span>: <span class="hljs-string">"terminal-token"</span>, <span class="hljs-attr">"type"</span>: <span class="hljs-string">"promptString"</span>, <span class="hljs-attr">"description"</span>: <span class="hljs-string">"Authentication
token for the terminal MCP gateway"</span>, <span class="hljs-attr">"password"</span>: <span class="hljs-literal">true</span> }
] } </code>
        </pre>
        <h2 id="a-terminal-shaped-around-the-task">A terminal shaped around the task
</h2>
        <p>
Different jobs need different tools, compute, and working data. By combining selectable
execution images and resource profiles with a simple MCP interface, the terminal lets
an agent run each task in an environment suited to the work.
</p>
        <p>
See implementation at <a href="https://github.com/nesterovsky-bros/code-engine-terminal">GitHub</a></p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=62d188d2-69d5-4b11-9182-ff291448d3f6" />
      </body>
      <title>IBM Code Engine Terminal</title>
      <guid isPermaLink="false">http://www.nesterovsky-bros.com/weblog/PermaLink,guid,62d188d2-69d5-4b11-9182-ff291448d3f6.aspx</guid>
      <link>http://www.nesterovsky-bros.com/weblog/2026/10/26/IBMCodeEngineTerminal.aspx</link>
      <pubDate>Mon, 26 Oct 2026 07:01:03 GMT</pubDate>
      <description>&lt;p&gt;
AI agents are good at connecting steps. But some steps need more than a local shell:
a particular runtime, more CPU or memory, or a place to keep working files between
runs. We wanted flexible compute environments that can be selected to fit each task,
while still being callable through the same MCP workflow.
&lt;/p&gt;
&lt;p&gt;
Azure, AWS, and Google Cloud all have ways to run this kind of workload. As IBMers,
though, IBM Cloud was our first choice; we also like its comparatively close-to-the-metal
feel. Within IBM Cloud, Code Engine fits the execution model: each request can run
in an isolated container, with its own image and CPU/memory profile. Its jobrun lifecycle
gives us the operations we need: submit work, check its state, read logs, and request
deletion.
&lt;/p&gt;
&lt;p&gt;
MCP v2 protocol version &lt;code&gt;2025-07-28&lt;/code&gt; that transitions the core architecture
to be completely stateless made it possible to host implementation in Code Engine
Application. A client submits a script and may choose an image and resource profile;
a job can also use persistent data from a mapped COS store. The Application starts
the job and returns its terminal ID to the client. That ID identifies the job in later
requests to check its status, retrieve logs, or request deletion. Code Engine runs
the work independently of the Application.
&lt;/p&gt;
&lt;h2 id="tools-and-options"&gt;Tools and options
&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;shell&lt;/code&gt; starts a job from inline Bash or a script path, with an optional
image (&lt;code&gt;shell&lt;/code&gt;, &lt;code&gt;java&lt;/code&gt;, &lt;code&gt;node&lt;/code&gt;, &lt;code&gt;python&lt;/code&gt;, &lt;code&gt;dotnet&lt;/code&gt;, &lt;code&gt;all&lt;/code&gt;,
or a full image reference) and supported CPU/memory profile.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;status&lt;/code&gt; checks the job state using its terminal ID.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;output&lt;/code&gt; retrieves logs by terminal ID, optionally selecting range or tail
lines.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;stop&lt;/code&gt; requests job deletion; use it only when you need to abort a long-running
job.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
The bundled images include common tools and dependencies so many tasks can run without
additional setup. Resource profiles must be supported by Code Engine and fit the project&amp;#39;s
quotas.
&lt;/p&gt;
&lt;p&gt;
For larger scripts or data that should persist across jobruns, configure a Code Engine
persistent data store backed by Cloud Object Storage (COS). It is mounted read/write
at &lt;code&gt;/mnt/data&lt;/code&gt;, so jobs can share persistent files and callers can pass
a script path there instead of sending a large script inline.
&lt;/p&gt;
&lt;h2 id="security"&gt;Security
&lt;/h2&gt;
&lt;p&gt;
The terminal service must run behind an API Gateway that authenticates callers. The
service can start jobs that execute arbitrary shell scripts, so exposing it without
authentication would let unauthenticated users consume compute, run untrusted commands,
and access any persistent storage available to those jobs.
&lt;/p&gt;
&lt;p&gt;
The gateway must forward the authenticated user&amp;#39;s name and email as trusted identity
headers, and must remove client-supplied versions of those headers before setting
its own. The service uses these values to populate job identity and resolve storage
paths; accepting caller-supplied identity would allow one user to impersonate another.
&lt;/p&gt;
&lt;p&gt;
If persistent storage is configured, its bucket prefix must include &lt;code&gt;$USER&lt;/code&gt;,
for example &lt;code&gt;terminal-store:users/$USER&lt;/code&gt;. The service expands that placeholder
from the gateway-verified username, keeping each user&amp;#39;s files in a separate path.
Without a user-specific prefix, concurrent callers can share or overwrite files, and
one user&amp;#39;s job may read data written by another user&amp;#39;s job.
&lt;/p&gt;
&lt;p&gt;
Forwarding the email also gives jobs a verified contact identity for auditing and
user-aware workflows. Only gateway-verified identity should be used for these purposes;
other request headers are not a substitute for authentication.
&lt;/p&gt;
&lt;p&gt;
Secrets needed by a job can be supplied as MCP HTTP headers instead of script text
or tool arguments. For example, with the default &lt;code&gt;x-terminal-&lt;/code&gt; header prefix, &lt;code&gt;x-terminal-api-key&lt;/code&gt; becomes
the job&amp;#39;s &lt;code&gt;API_KEY&lt;/code&gt; environment variable. In VS Code, define the header
using a password-protected input:
&lt;/p&gt;
&lt;pre style="white-space: pre-wrap;"&gt;&lt;code class="lang-json"&gt;{ &lt;span class="hljs-attr"&gt;"servers"&lt;/span&gt;:
{ &lt;span class="hljs-attr"&gt;"code-engine-terminal"&lt;/span&gt;: { &lt;span class="hljs-attr"&gt;"url"&lt;/span&gt;: &lt;span class="hljs-string"&gt;"https://api.&amp;lt;project-id&amp;gt;.&amp;lt;region&amp;gt;.codeengine.appdomain.cloud/terminal/mcp"&lt;/span&gt;, &lt;span class="hljs-attr"&gt;"type"&lt;/span&gt;: &lt;span class="hljs-string"&gt;"http"&lt;/span&gt;, &lt;span class="hljs-attr"&gt;"headers"&lt;/span&gt;:
{ &lt;span class="hljs-attr"&gt;"Authorization"&lt;/span&gt;: &lt;span class="hljs-string"&gt;"Bearer
${input:terminal-token}"&lt;/span&gt;, &lt;span class="hljs-attr"&gt;"x-terminal-api-key"&lt;/span&gt;: &lt;span class="hljs-string"&gt;"${input:job-api-key}"&lt;/span&gt; }
} }, &lt;span class="hljs-attr"&gt;"inputs"&lt;/span&gt;: [ { &lt;span class="hljs-attr"&gt;"id"&lt;/span&gt;: &lt;span class="hljs-string"&gt;"terminal-token"&lt;/span&gt;, &lt;span class="hljs-attr"&gt;"type"&lt;/span&gt;: &lt;span class="hljs-string"&gt;"promptString"&lt;/span&gt;, &lt;span class="hljs-attr"&gt;"description"&lt;/span&gt;: &lt;span class="hljs-string"&gt;"Authentication
token for the terminal MCP gateway"&lt;/span&gt;, &lt;span class="hljs-attr"&gt;"password"&lt;/span&gt;: &lt;span class="hljs-literal"&gt;true&lt;/span&gt; },
{ &lt;span class="hljs-attr"&gt;"id"&lt;/span&gt;: &lt;span class="hljs-string"&gt;"job-api-key"&lt;/span&gt;, &lt;span class="hljs-attr"&gt;"type"&lt;/span&gt;: &lt;span class="hljs-string"&gt;"promptString"&lt;/span&gt;, &lt;span class="hljs-attr"&gt;"description"&lt;/span&gt;: &lt;span class="hljs-string"&gt;"API
key to expose to the job as API_KEY"&lt;/span&gt;, &lt;span class="hljs-attr"&gt;"password"&lt;/span&gt;: &lt;span class="hljs-literal"&gt;true&lt;/span&gt; }
] } &lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;
The MCP client adds these values to the HTTP request; they are not part of the agent&amp;#39;s
shell-tool arguments or prompt. The gateway must still authenticate the caller, remove
untrusted copies of privileged headers, and forward only explicitly approved secret
headers. Secrets become available to the job process as environment variables, so
scripts should not print them and logs or child processes must be handled accordingly.
Prefer short-lived, least-privilege credentials.
&lt;/p&gt;
&lt;h2 id="example-analyze-a-dataset"&gt;Example: Analyze a dataset
&lt;/h2&gt;
&lt;p&gt;
This conversation shows an agent analyzing &lt;code&gt;/mnt/data/sales.csv&lt;/code&gt; with the
Python image: it starts a job, checks its status, and retrieves the result using the
returned terminal ID.
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;User:&lt;/strong&gt; I uploaded &lt;code&gt;/sales.csv&lt;/code&gt; to the mounted COS store.
Can you report the row count, total revenue, and revenue by region?
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;AI:&lt;/strong&gt; I’ll run a short Python analysis against the mounted file, then
check the job output.
&lt;/p&gt;
&lt;pre style="white-space: pre-wrap;"&gt;&lt;code class="lang-json"&gt;{ &lt;span class="hljs-attr"&gt;"tool"&lt;/span&gt;: &lt;span class="hljs-string"&gt;"shell"&lt;/span&gt;, &lt;span class="hljs-attr"&gt;"arguments"&lt;/span&gt;:
{ &lt;span class="hljs-attr"&gt;"script"&lt;/span&gt;: &lt;span class="hljs-string"&gt;"python - &amp;lt;&amp;lt;'PY'\nimport
pandas as pd\ndf = pd.read_csv('/mnt/data/sales.csv')\nprint(f'Rows: {len(df)}')\nprint(f'Total
revenue: {df[\"revenue\"].sum():.2f}')\nprint('Revenue by region:')\nprint(df.groupby('region')['revenue'].sum().to_string())\nPY"&lt;/span&gt;, &lt;span class="hljs-attr"&gt;"image"&lt;/span&gt;: &lt;span class="hljs-string"&gt;"python"&lt;/span&gt;, &lt;span class="hljs-attr"&gt;"resourceProfile"&lt;/span&gt;: &lt;span class="hljs-string"&gt;"cpu-1-mem-4g"&lt;/span&gt; }
} &lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;
&lt;strong&gt;AI:&lt;/strong&gt; The job is running. Its terminal ID is &lt;code&gt;k4m2...&lt;/code&gt;
&lt;/p&gt;
&lt;pre style="white-space: pre-wrap;"&gt;&lt;code class="lang-json"&gt;{ &lt;span class="hljs-attr"&gt;"tool"&lt;/span&gt;: &lt;span class="hljs-string"&gt;"status"&lt;/span&gt;, &lt;span class="hljs-attr"&gt;"arguments"&lt;/span&gt;:
{ &lt;span class="hljs-attr"&gt;"terminalId"&lt;/span&gt;: &lt;span class="hljs-string"&gt;"k4m2..."&lt;/span&gt; }
} &lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;
&lt;strong&gt;AI:&lt;/strong&gt; The job completed. I’ll fetch the report.
&lt;/p&gt;
&lt;pre style="white-space: pre-wrap;"&gt;&lt;code class="lang-json"&gt;{ &lt;span class="hljs-attr"&gt;"tool"&lt;/span&gt;: &lt;span class="hljs-string"&gt;"output"&lt;/span&gt;, &lt;span class="hljs-attr"&gt;"arguments"&lt;/span&gt;:
{ &lt;span class="hljs-attr"&gt;"terminalId"&lt;/span&gt;: &lt;span class="hljs-string"&gt;"k4m2..."&lt;/span&gt; }
} &lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;
&lt;strong&gt;AI:&lt;/strong&gt; The file contains 1,248 rows with total revenue of 84,392.50.
The largest regional total is West at 29,410.00.
&lt;/p&gt;
&lt;h2 id="run-it-in-your-account"&gt;Run it in your account
&lt;/h2&gt;
&lt;p&gt;
Deploy the MCP service as a Code Engine Application with its own container image,
and register the job images (&lt;code&gt;shell&lt;/code&gt;, &lt;code&gt;java&lt;/code&gt;, &lt;code&gt;node&lt;/code&gt;, &lt;code&gt;python&lt;/code&gt;, &lt;code&gt;dotnet&lt;/code&gt;,
and &lt;code&gt;all&lt;/code&gt;) in a container registry the project can access.
&lt;/p&gt;
&lt;p&gt;
The service does not authenticate or authorize callers, so place it behind an API
Gateway that does.
&lt;/p&gt;
&lt;p&gt;
For example, the Application might be reachable inside the project at &lt;code&gt;http://terminal.&amp;lt;project-id&amp;gt;.svc.cluster.local/mcp&lt;/code&gt;.
Clients would connect through a public gateway URL such as &lt;code&gt;https://api.&amp;lt;project-id&amp;gt;.&amp;lt;region&amp;gt;.codeengine.appdomain.cloud/terminal/mcp&lt;/code&gt;.
&lt;/p&gt;
&lt;p&gt;
In VS Code, add the gateway endpoint to the project&amp;#39;s &lt;code&gt;.vscode/mcp.json&lt;/code&gt; and
prompt for the gateway token:
&lt;/p&gt;
&lt;pre style="white-space: pre-wrap;"&gt;&lt;code class="lang-json"&gt;{ &lt;span class="hljs-attr"&gt;"servers"&lt;/span&gt;:
{ &lt;span class="hljs-attr"&gt;"code-engine-terminal"&lt;/span&gt;: { &lt;span class="hljs-attr"&gt;"url"&lt;/span&gt;: &lt;span class="hljs-string"&gt;"https://api.&amp;lt;project-id&amp;gt;.&amp;lt;region&amp;gt;.codeengine.appdomain.cloud/terminal/mcp"&lt;/span&gt;, &lt;span class="hljs-attr"&gt;"type"&lt;/span&gt;: &lt;span class="hljs-string"&gt;"http"&lt;/span&gt;, &lt;span class="hljs-attr"&gt;"headers"&lt;/span&gt;:
{ &lt;span class="hljs-attr"&gt;"Authorization"&lt;/span&gt;: &lt;span class="hljs-string"&gt;"Bearer
${input:terminal-token}"&lt;/span&gt; } } }, &lt;span class="hljs-attr"&gt;"inputs"&lt;/span&gt;: [
{ &lt;span class="hljs-attr"&gt;"id"&lt;/span&gt;: &lt;span class="hljs-string"&gt;"terminal-token"&lt;/span&gt;, &lt;span class="hljs-attr"&gt;"type"&lt;/span&gt;: &lt;span class="hljs-string"&gt;"promptString"&lt;/span&gt;, &lt;span class="hljs-attr"&gt;"description"&lt;/span&gt;: &lt;span class="hljs-string"&gt;"Authentication
token for the terminal MCP gateway"&lt;/span&gt;, &lt;span class="hljs-attr"&gt;"password"&lt;/span&gt;: &lt;span class="hljs-literal"&gt;true&lt;/span&gt; }
] } &lt;/code&gt;&lt;/pre&gt;
&lt;h2 id="a-terminal-shaped-around-the-task"&gt;A terminal shaped around the task
&lt;/h2&gt;
&lt;p&gt;
Different jobs need different tools, compute, and working data. By combining selectable
execution images and resource profiles with a simple MCP interface, the terminal lets
an agent run each task in an environment suited to the work.
&lt;/p&gt;
&lt;p&gt;
See implementation at &lt;a href="https://github.com/nesterovsky-bros/code-engine-terminal"&gt;GitHub&lt;/a&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=62d188d2-69d5-4b11-9182-ff291448d3f6" /&gt;</description>
      <comments>http://www.nesterovsky-bros.com/weblog/CommentView,guid,62d188d2-69d5-4b11-9182-ff291448d3f6.aspx</comments>
      <category>AI</category>
      <category>Announce</category>
      <category>Thinking aloud</category>
    </item>
    <item>
      <trackback:ping>http://www.nesterovsky-bros.com/weblog/Trackback.aspx?guid=5b130a26-4879-4fe3-aefa-a9162b75ea23</trackback:ping>
      <pingback:server>http://www.nesterovsky-bros.com/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,5b130a26-4879-4fe3-aefa-a9162b75ea23.aspx</pingback:target>
      <dc:creator>Vladimir Nesterovsky</dc:creator>
      <georss:point>0 0</georss:point>
      <wfw:comment>http://www.nesterovsky-bros.com/weblog/CommentView,guid,5b130a26-4879-4fe3-aefa-a9162b75ea23.aspx</wfw:comment>
      <wfw:commentRss>http://www.nesterovsky-bros.com/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=5b130a26-4879-4fe3-aefa-a9162b75ea23</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Continuing the tradition, we reported the bug in Saxon 13.1
</p>
        <p>
See <a href="https://saxonica.plan.io/issues/7282">Compilation error in Saxon 13.1</a><img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=5b130a26-4879-4fe3-aefa-a9162b75ea23" /></p>
      </body>
      <title>Saxon 13.1 Bug</title>
      <guid isPermaLink="false">http://www.nesterovsky-bros.com/weblog/PermaLink,guid,5b130a26-4879-4fe3-aefa-a9162b75ea23.aspx</guid>
      <link>http://www.nesterovsky-bros.com/weblog/2026/10/26/Saxon131Bug.aspx</link>
      <pubDate>Mon, 26 Oct 2026 06:58:39 GMT</pubDate>
      <description>&lt;p&gt;
Continuing the tradition, we reported the bug in Saxon 13.1
&lt;/p&gt;
&lt;p&gt;
See &lt;a href="https://saxonica.plan.io/issues/7282"&gt;Compilation error in Saxon 13.1&lt;/a&gt;&lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=5b130a26-4879-4fe3-aefa-a9162b75ea23" /&gt;</description>
      <comments>http://www.nesterovsky-bros.com/weblog/CommentView,guid,5b130a26-4879-4fe3-aefa-a9162b75ea23.aspx</comments>
      <category>xslt</category>
    </item>
    <item>
      <trackback:ping>http://www.nesterovsky-bros.com/weblog/Trackback.aspx?guid=65eadcab-c7fa-4ad3-8941-14522f019db1</trackback:ping>
      <pingback:server>http://www.nesterovsky-bros.com/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,65eadcab-c7fa-4ad3-8941-14522f019db1.aspx</pingback:target>
      <dc:creator>Vladimir Nesterovsky</dc:creator>
      <georss:point>0 0</georss:point>
      <wfw:comment>http://www.nesterovsky-bros.com/weblog/CommentView,guid,65eadcab-c7fa-4ad3-8941-14522f019db1.aspx</wfw:comment>
      <wfw:commentRss>http://www.nesterovsky-bros.com/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=65eadcab-c7fa-4ad3-8941-14522f019db1</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
It's almost established tradition - Saxonica issues new version of Saxon XSLT processor,
we update our code base to newest version, and it crashes.
</p>
        <p>
Next step is a long discussion in their forum and attempt to figure our who is guilty,
and what to do about it.
</p>
        <p>
In most cases the problem is eventually found, we rollback to stable Saxon version,
and wait for the update.
</p>
        <p>
Same is true for newest major Saxon 13 update.
</p>
        <p>
See <a href="https://saxonica.plan.io/issues/7097">ClassCastException in Saxon 13</a></p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=65eadcab-c7fa-4ad3-8941-14522f019db1" />
      </body>
      <title>Saxon 13</title>
      <guid isPermaLink="false">http://www.nesterovsky-bros.com/weblog/PermaLink,guid,65eadcab-c7fa-4ad3-8941-14522f019db1.aspx</guid>
      <link>http://www.nesterovsky-bros.com/weblog/2026/06/01/Saxon13.aspx</link>
      <pubDate>Mon, 01 Jun 2026 06:40:29 GMT</pubDate>
      <description>&lt;p&gt;
It's almost established tradition - Saxonica issues new version of Saxon XSLT processor,
we update our code base to newest version, and it crashes.
&lt;/p&gt;
&lt;p&gt;
Next step is a long discussion in their forum and attempt to figure our who is guilty,
and what to do about it.
&lt;/p&gt;
&lt;p&gt;
In most cases the problem is eventually found, we rollback to stable Saxon version,
and wait for the update.
&lt;/p&gt;
&lt;p&gt;
Same is true for newest major Saxon 13 update.
&lt;/p&gt;
&lt;p&gt;
See &lt;a href="https://saxonica.plan.io/issues/7097"&gt;ClassCastException in Saxon 13&lt;/a&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=65eadcab-c7fa-4ad3-8941-14522f019db1" /&gt;</description>
      <comments>http://www.nesterovsky-bros.com/weblog/CommentView,guid,65eadcab-c7fa-4ad3-8941-14522f019db1.aspx</comments>
      <category>Thinking aloud</category>
      <category>xslt</category>
    </item>
    <item>
      <trackback:ping>http://www.nesterovsky-bros.com/weblog/Trackback.aspx?guid=ca777d18-5f91-4c7a-bb5c-52a1719af9be</trackback:ping>
      <pingback:server>http://www.nesterovsky-bros.com/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,ca777d18-5f91-4c7a-bb5c-52a1719af9be.aspx</pingback:target>
      <dc:creator>Vladimir Nesterovsky</dc:creator>
      <georss:point>0 0</georss:point>
      <wfw:comment>http://www.nesterovsky-bros.com/weblog/CommentView,guid,ca777d18-5f91-4c7a-bb5c-52a1719af9be.aspx</wfw:comment>
      <wfw:commentRss>http://www.nesterovsky-bros.com/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=ca777d18-5f91-4c7a-bb5c-52a1719af9be</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
It's not the first time we need massive use of AI in our code.
</p>
        <h2 id="summary">Summary
</h2>
        <p>
This post documents our exploration of agentic AI frameworks as an alternative to
our proven OpenAI Batch API approach. While pressure existed to adopt trendy agentic
solutions, we remained pragmatic: our existing Batch API solution is scalable, well-understood,
and well-maintained.
</p>
        <p>
We evaluated <strong>LangChain</strong> and <strong>LangGraph</strong> for implementing
complex AI workflows with state management and resumability. Our conclusion is nuanced:
</p>
        <ul>
          <li>
            <strong>LangChain</strong> excels at simplifying AI integration through declarative
service interfaces.</li>
          <li>
            <strong>LangGraph</strong> introduces unnecessary complexity for our use cases; pure
Java with explicit state management is cleaner and easier to debug.</li>
        </ul>
        <p>
By combining pure Java with <strong>LangChain</strong> for AI calls, we achieved cleaner,
more efficient code than our original Batch API implementation, while maintaining
the readability and maintainability Arthur and I both value.
</p>
        <h2 id="use-case">Use Case
</h2>
        <p>
Let's formulate a use case in simple form:
</p>
        <ul>
          <li>
There is a folder of input data that you need to process somehow.</li>
          <li>
One or multiple steps in such processing involve AI prompts.</li>
          <li>
The result is a folder of output data.</li>
        </ul>
        <h2 id="journey-so-far">Journey So Far
</h2>
        <p>
For a couple of years, we've used <strong>OpenAI Batch API</strong> to do such
processing. Originally we used Azure OpenAI, but when we became part of IBM, we switched
to <strong>watsonx.ai</strong>, and even re-implemented a lacking Batch API drop-in
replacement service using IBM Code Engine.
</p>
        <p>
Solution works, but... here the journey only begins.
</p>
        <h3 id="the-conversation">The Conversation
</h3>
        <blockquote>
          <p>
            <strong>IBM presses</strong> - you need to build agentic solutions.
</p>
          <p>
            <strong>Arthur tells</strong> - what we have can be called agentic use of AI. It just
works without buzz words.
</p>
          <p>
            <strong>I tell</strong> - yes, that's correct, but it's not easy to implement
non-trivial AI flow, including tool calls, while sticking to the Batch API.
</p>
          <p>
            <strong>Arthur</strong> - not trivial but possible. Our solution is scalable, we understand
it, and we easily support it. So, per the first rule of programming - don't fix
something that is working!
</p>
          <p>
            <strong>I</strong> - I want to explore what other solutions can give us.
</p>
          <p>
            <strong>Arthur, skeptically</strong> - go on, and I'll be looking at your efforts!
</p>
        </blockquote>
        <h3 id="exploring-the-landscape">Exploring the Landscape
</h3>
        <p>
So, I went on discovering today's landscape of agentic AI libraries.
</p>
        <p>
As you know, there are many of them - from Microsoft, from the community, and for
other providers. We have our constraints. Being part of IBM means <strong>Langchain</strong> is
the default choice. You would need to have good arguments to use something different.
</p>
        <p>
Okay, we agreed with Arthur that <strong>Langchain</strong> is what I'll continue
to explore.
</p>
        <p>
Then I went forward looking at how I could implement our sample task with massive
processing of folders of data.
</p>
        <p>
What came naturally is <strong>LangGraph</strong> - the framework to implement different
workflows, including cycles, parallel processing, AI calls, and checkpointing of execution.
</p>
        <p>
Checkpointing looked promising - I could run the flow, save intermediate results,
stop, restart, and do different things with state. This was encouraging for a long-running
flow.
</p>
        <p>
I've found that with some effort, you could even integrate the Batch API into
it. I was positive about the right direction. Arthur wisely listened and agreed that
this sounds promising.
</p>
        <h3 id="language-selection">Language Selection
</h3>
        <p>
Next step was to select the language.
</p>
        <p>
Several years ago I would say it's weird to select a framework and then language,
but these days the world has changed.
</p>
        <p>
We found that <strong>LangGraph</strong> has:
</p>
        <ul>
          <li>
Original implementation in <strong>Python</strong>, which is most advanced</li>
          <li>
            <strong>TypeScript</strong> port</li>
          <li>
            <strong>LangGraph4j</strong> - Java version inspired by Python</li>
        </ul>
        <p>
For us it was not immediately obvious what to use, as we don't start a new project
but continue ongoing development. Our preferences go with <strong>LangGraph4j</strong> -
there will be fewer moving parts, and it will integrate naturally.
</p>
        <h3 id="poc-sample">POC Sample
</h3>
        <p>
Now we needed hands-on experience with the technology to study it deeper and implement
a simplest flow.
</p>
        <p>
What I learned is that <strong>LangGraph</strong> is a library to define a logic flow
in a semi-declarative way as a graph of edges and vertices, where:
</p>
        <ul>
          <li>
            <strong>Edge</strong> - defines a unit of logic</li>
          <li>
            <strong>Vertices</strong> - define transitions between edges</li>
        </ul>
        <p>
In general, <strong>LangGraph</strong> has nothing to do with <strong>LangChain</strong>,
which is an AI wrapper. You can do whatever you want with <strong>LangGraph</strong>,
including calling AI through <strong>LangChain</strong>. <strong>LangGraph</strong> allows
you to stop execution, save state somewhere (e.g., in files or in a database), and
later resume.
</p>
        <p>
Arthur was satisfied and told me that the flow graph resembled his old favorite BizTalk,
which allowed you to define a high-level algorithm visually, and the final block could
be implemented by calling real code.
</p>
        <p>
All this looked promising and allowed us to implement some simple tasks:
</p>
        <ol>
          <li>
An agent to perform simple math: <code>Sum(a, b)</code></li>
          <li>
An agent to perform a simple cycle of sub-agents</li>
          <li>
An agent to perform a parallel cycle of sub-agents</li>
        </ol>
        <p>
I started with Task 1 - the Sum agent - and implemented it using a <strong>LangGraph</strong> sample.
It included a map-based immutable state, graph definitions, and node handlers.
</p>
        <p>
Arthur looked at it for a long time and told me that he barely understood what he
saw and barely understood where the business logic (<code>a + b</code>) was.
</p>
        <p>
          <strong>Verdict</strong> - this is an obscure, unmanageable pile of code. We need
something less clever if we want to understand it in half a year.
</p>
        <p>
I went back and introduced some helpers to simplify agent coding in <strong>LangGraph4j</strong>.
This allowed me to produce much smaller and concise code, which I want to quote here:
</p>
        <pre>
          <code class="lang-java">
            <span class="hljs-keyword">package</span> com.bphx.coolgen.agents; <span class="hljs-keyword">import</span> org.bsc.langgraph4j.CompileConfig; <span class="hljs-keyword">import</span> org.bsc.langgraph4j.CompiledGraph; <span class="hljs-keyword">import</span> org.bsc.langgraph4j.RunnableConfig; <span class="hljs-keyword">import</span> org.bsc.langgraph4j.StateGraph; <span class="hljs-keyword">import</span><span class="hljs-keyword">static</span> com.bphx.coolgen.agents.Agent.*; <span class="hljs-keyword">import</span> java.io.Serializable; <span class="hljs-comment">///
Sample agent demonstrating basic LangGraph4j usage. Receives two numbers and</span><span class="hljs-comment">///
computes their sum.</span><span class="hljs-comment">///</span><span class="hljs-comment">///
Uses state class [Data].</span><span class="hljs-comment">///</span><span class="hljs-comment">///
## Usage</span><span class="hljs-comment">///</span><span class="hljs-comment">///
var graph = Sum.build();</span><span class="hljs-comment">/// var data = Sum.of(10.0,
32.0);</span><span class="hljs-comment">/// var result = Agent.invoke(graph, data);</span><span class="hljs-comment">///
System.out.println("Sum: " + result.result); // prints: Sum: 42.0</span><span class="hljs-keyword">public</span><span class="hljs-keyword">final</span><span class="hljs-class"><span class="hljs-keyword">class</span><span class="hljs-title">Sum</span></span>{ <span class="hljs-comment">///
State class for the Sum agent. Contains input operands and the</span><span class="hljs-comment">///
computed result.</span><span class="hljs-keyword">public</span><span class="hljs-keyword">static</span><span class="hljs-class"><span class="hljs-keyword">class</span><span class="hljs-title">Data</span><span class="hljs-keyword">implements</span><span class="hljs-title">Serializable</span></span>{ <span class="hljs-function"><span class="hljs-keyword">public</span><span class="hljs-title">Data</span><span class="hljs-params">(<span class="hljs-keyword">double</span> a, <span class="hljs-keyword">double</span> b)</span></span>{ <span class="hljs-keyword">this</span>.a
= a; <span class="hljs-keyword">this</span>.b = b; } <span class="hljs-keyword">public</span><span class="hljs-keyword">final</span><span class="hljs-keyword">double</span> a; <span class="hljs-keyword">public</span><span class="hljs-keyword">final</span><span class="hljs-keyword">double</span> b; <span class="hljs-keyword">public</span><span class="hljs-keyword">double</span> result;
} <span class="hljs-keyword">public</span><span class="hljs-keyword">static</span><span class="hljs-function">Data <span class="hljs-title">of</span><span class="hljs-params">(<span class="hljs-keyword">double</span> a, <span class="hljs-keyword">double</span> b)</span></span>{ <span class="hljs-keyword">return</span><span class="hljs-keyword">new</span> Data(a,
b); } <span class="hljs-comment">/// Builds and returns a compiled graph for the sum
agent.</span><span class="hljs-comment">/// </span><span class="hljs-comment">///
@return compiled graph ready to invoke</span><span class="hljs-comment">/// @throws
Exception if graph compilation fails</span><span class="hljs-keyword">public</span><span class="hljs-keyword">static</span> CompiledGraph&lt;State&lt;Data&gt;&gt;
build() <span class="hljs-keyword">throws</span> Exception { <span class="hljs-keyword">return</span> Agent.&lt;Data&gt;graph()
.addNode(<span class="hljs-string">"sum"</span>, node(Sum::sum)) .addEdge(StateGraph.START, <span class="hljs-string">"sum"</span>)
.addEdge(<span class="hljs-string">"sum"</span>, StateGraph.END) .compile(CompileConfig.builder().build());
} <span class="hljs-keyword">private</span><span class="hljs-keyword">static</span><span class="hljs-function">Data <span class="hljs-title">sum</span><span class="hljs-params">(Data
data, RunnableConfig config)</span></span>{ data.result = data.a + data.b; <span class="hljs-keyword">return</span> data;
} } </code>
        </pre>
        <p>
Arthur confirmed that he was able to understand that <code>sum()</code> defines the
business logic, the <code>Data</code> class defines the graph state, and <code>build()</code> defines
the graph itself, like this: <code>start -&gt; sum -&gt; end</code>.
</p>
        <p>
However, neither Arthur nor I were fully satisfied.
</p>
        <p>
At the next step, I implemented Task 2 - a cycle of Sum calls. This worked, but it
looked as if you were building assembly with a graph, as if you need to implement:
</p>
        <pre>
          <code>start: <span class="hljs-built_in">index</span> = <span class="hljs-number">0</span>; <span class="hljs-built_in">count</span> = <span class="hljs-number">1000</span>; <span class="hljs-keyword">cycle</span>: <span class="hljs-keyword">if</span> (<span class="hljs-built_in">index</span> &gt;= <span class="hljs-built_in">count</span>) <span class="hljs-keyword">goto</span><span class="hljs-keyword">end</span>;
iteration: result[<span class="hljs-built_in">index</span>] = a[<span class="hljs-built_in">index</span>]
+ b[<span class="hljs-built_in">index</span>]; <span class="hljs-built_in">index</span> = <span class="hljs-built_in">index</span> + <span class="hljs-number">1</span>; <span class="hljs-keyword">goto</span><span class="hljs-keyword">cycle</span>; <span class="hljs-keyword">end</span>: </code>
        </pre>
        <p>
This works but doesn't look nice. Besides, debugging <strong>LangGraph</strong> code
is an adventure.
</p>
        <p>
Finally, the 3rd task was the least trivial part to implement. It turned out there
is no built-in parallel cycles, and we needed to go to the basic fork-join building
block in <strong>LangGraph</strong> to generate a dynamic graph for parallel processing.
</p>
        <p>
This worked as well, but it became even more complex, involving merging states after
parallel branches and uncontrolled serialization and deserialization of all accumulated
states.
</p>
        <p>
It did not look like a good trade. We lost clean, readable Java code in exchange for
a resumable graph that is hard to understand and debug.
</p>
        <h2 id="next-steps">Next Steps
</h2>
        <p>
We implemented the original task of processing a folder in parallel, where we called <strong>LangChain</strong> and
were pleased with its AI services. You could define an interface and get its implementation
from <code>ChatModel</code> (which even supports tool calls), like this:
</p>
        <pre>
          <code class="lang-java">
            <span class="hljs-comment">/// AI service interface
for generating HTML documentation summaries.</span>
            <span class="hljs-comment">///</span>
            <span class="hljs-comment">///
LangChain4j creates an implementation that calls the chat model with</span>
            <span class="hljs-comment">///
a system prompt.</span>
            <span class="hljs-keyword">interface</span>
            <span class="hljs-type">Summarizer</span> {
@<span class="hljs-type">SystemMessage</span>(<span class="hljs-string">""" You are
a world class expert in programming... Create documentation for the provided code
to ... Use basic HTML markup, like &lt;h1&gt;, &lt;p&gt;, &lt;b&gt;, &lt;ol&gt;, &lt;ul&gt;,
&lt;li&gt;. Don't use &lt;html&gt; and &lt;body&gt;. - Documentation must be terse.
- No greetings and farewells must be used. - Provide a summary of the code's purpose
and functionality. ... """</span>) <span class="hljs-type">String</span> summarize(@<span class="hljs-type">UserMessage</span><span class="hljs-type">String</span> code);
} ... <span class="hljs-keyword">var</span> summarizer = <span class="hljs-type">AiServices</span>.create(<span class="hljs-type">Summarizer</span>.<span class="hljs-keyword">class</span>,
chatModel); ... <span class="hljs-keyword">var</span> summary = summarizer.summarize(code); </code>
        </pre>
        <p>
Notice the elegance: the entire AI integration is reduced to a single interface definition
and one line of instantiation. The business logic (<code>summarize()</code>) is immediately
visible. Compare this to the earlier <strong>LangGraph</strong> Sum agent with its
graph definitions, node handlers, and state management—this is why we prefer it.
</p>
        <h3 id="sharing-our-approach">Sharing Our Approach
</h3>
        <p>
We're planning to share this pattern with our team as the recommended path forward
for AI integration. Rather than pursuing the latest agentic frameworks, teams should:
</p>
        <ol>
          <li>
            <strong>Start with explicit state management</strong> in their language of choice</li>
          <li>
            <strong>Use focused AI libraries</strong> like <strong>LangChain4j</strong> for clean
abstraction</li>
          <li>
            <strong>Avoid graph frameworks unless truly needed</strong> for distributed resumability</li>
          <li>
            <strong>Prioritize code clarity</strong> over framework comprehensiveness</li>
        </ol>
        <h3 id="future-roadmap">Future Roadmap
</h3>
        <p>
The Java + <strong>LangChain</strong> pattern scales well for:
</p>
        <ul>
          <li>
            <strong>Batch processing</strong> of large folders with parallel <strong>LangChain</strong> calls</li>
          <li>
            <strong>Multi-step AI workflows</strong> (chain multiple AI services together)</li>
          <li>
            <strong>Tool-augmented AI</strong> (extending ChatModel with custom tools)</li>
          <li>
            <strong>Integration with existing systems</strong> where Java is already the lingua
franca</li>
        </ul>
        <p>
We're confident this approach will serve our organization better than chasing
trending frameworks.
</p>
        <h2 id="key-learnings">Key Learnings
</h2>
        <ol>
          <li>
            <p>
              <strong>Buzzwords ≠ Solutions</strong>: The pressure to "build agentic solutions"
made us evaluate tools strictly on merit, not hype. Sometimes "agentic"
is just marketing.
</p>
          </li>
          <li>
            <p>
              <strong>Abstraction Layers Matter</strong>: <strong>LangChain</strong>'s declarative
approach (<code>@SystemMessage</code>, <code>AiServices</code>) hides complexity elegantly. <strong>LangGraph</strong>'s
explicit node-edge model exposed too many low-level details for our domain.
</p>
          </li>
          <li>
            <p>
              <strong>Code Readability Wins Long-term</strong>: Arthur's visceral reaction to
the initial <strong>LangGraph</strong> code—"barely understand where the business
logic is"—reminded us that clever code is harder to maintain than straightforward
code (even with AI).
</p>
          </li>
          <li>
            <p>
              <strong>Pragmatism Over Features</strong>: Our Batch API solution already solved resumability
and scalability. Adopting a framework for features you don't need creates unnecessary
technical debt.
</p>
          </li>
          <li>
            <p>
              <strong>Pure Language + Focused Libraries</strong>: Combining plain Java + <strong>LangChain</strong> gave
us the best of both worlds: explicit control over algorithms and clean AI abstraction.
</p>
          </li>
        </ol>
        <h3 id="when-langgraph-makes-sense">When LangGraph Makes Sense
</h3>
        <p>
Before we dismiss <strong>LangGraph</strong> entirely, it's worth noting when
it might be the right choice:
</p>
        <ul>
          <li>
            <strong>Truly distributed systems</strong> where processes run on different machines
and need to resume</li>
          <li>
            <strong>Long-running, unattended workflows</strong> that span days or weeks and need
checkpointing (though native java implementation gave us flexibility on checkpoints)</li>
          <li>
            <strong>Complex branching logic</strong> with many conditional paths that benefit
from visual representation</li>
          <li>
            <strong>Systems requiring audit trails</strong> of every state transition</li>
        </ul>
        <p>
For our use case—batch processing with intermediate results we can manage explicitly—<strong>LangGraph</strong> was
overkill.
</p>
        <h2 id="conclusion">Conclusion
</h2>
        <p>
After working through these explorations, we reached a <strong>nuanced but clear conclusion</strong>:
</p>
        <ul>
          <li>
            <strong>LangChain</strong> - Excellent. Provides clean abstractions for AI integration
without forcing architectural decisions.</li>
          <li>
            <strong>LangGraph</strong> - Not a fit for our use cases. Its complexity and explicit
state serialization overhead outweigh the benefits for batch processing. For truly
distributed, long-running workflows, it might be appropriate, but we have simpler
solutions.</li>
        </ul>
        <h3 id="the-better-way-forward">The Better Way Forward
</h3>
        <p>
We re-implemented several processes that used the OpenAI Batch API in pure Java + <strong>LangChain</strong>,
and even extended the logic to multi-step AI calls. The results:
</p>
        <ul>
          <li>
            <strong>Cleaner code</strong> than the original Batch API implementation</li>
          <li>
            <strong>More powerful</strong> (support for complex multi-turn conversations)</li>
          <li>
            <strong>Faster execution</strong> (parallel processing without batching delays)</li>
          <li>
            <strong>Easier to maintain</strong> (straightforward Java instead of graph abstractions)</li>
        </ul>
        <p>
Thus, we believe our decision to explore and eventually adopt the Java + <strong>LangChain</strong> pattern
was the right one. We gained the benefits of modern AI frameworks without sacrificing
the simplicity and maintainability that Arthur and I both prioritize.
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=ca777d18-5f91-4c7a-bb5c-52a1719af9be" />
      </body>
      <title>Agent Era</title>
      <guid isPermaLink="false">http://www.nesterovsky-bros.com/weblog/PermaLink,guid,ca777d18-5f91-4c7a-bb5c-52a1719af9be.aspx</guid>
      <link>http://www.nesterovsky-bros.com/weblog/2026/05/24/AgentEra.aspx</link>
      <pubDate>Sun, 24 May 2026 13:17:03 GMT</pubDate>
      <description>&lt;p&gt;
It&amp;#39;s not the first time we need massive use of AI in our code.
&lt;/p&gt;
&lt;h2 id="summary"&gt;Summary
&lt;/h2&gt;
&lt;p&gt;
This post documents our exploration of agentic AI frameworks as an alternative to
our proven OpenAI Batch API approach. While pressure existed to adopt trendy agentic
solutions, we remained pragmatic: our existing Batch API solution is scalable, well-understood,
and well-maintained.
&lt;/p&gt;
&lt;p&gt;
We evaluated &lt;strong&gt;LangChain&lt;/strong&gt; and &lt;strong&gt;LangGraph&lt;/strong&gt; for implementing
complex AI workflows with state management and resumability. Our conclusion is nuanced:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;LangChain&lt;/strong&gt; excels at simplifying AI integration through declarative
service interfaces.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;LangGraph&lt;/strong&gt; introduces unnecessary complexity for our use cases; pure
Java with explicit state management is cleaner and easier to debug.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
By combining pure Java with &lt;strong&gt;LangChain&lt;/strong&gt; for AI calls, we achieved cleaner,
more efficient code than our original Batch API implementation, while maintaining
the readability and maintainability Arthur and I both value.
&lt;/p&gt;
&lt;h2 id="use-case"&gt;Use Case
&lt;/h2&gt;
&lt;p&gt;
Let&amp;#39;s formulate a use case in simple form:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
There is a folder of input data that you need to process somehow.&lt;/li&gt;
&lt;li&gt;
One or multiple steps in such processing involve AI prompts.&lt;/li&gt;
&lt;li&gt;
The result is a folder of output data.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="journey-so-far"&gt;Journey So Far
&lt;/h2&gt;
&lt;p&gt;
For a couple of years, we&amp;#39;ve used &lt;strong&gt;OpenAI Batch API&lt;/strong&gt; to do such
processing. Originally we used Azure OpenAI, but when we became part of IBM, we switched
to &lt;strong&gt;watsonx.ai&lt;/strong&gt;, and even re-implemented a lacking Batch API drop-in
replacement service using IBM Code Engine.
&lt;/p&gt;
&lt;p&gt;
Solution works, but... here the journey only begins.
&lt;/p&gt;
&lt;h3 id="the-conversation"&gt;The Conversation
&lt;/h3&gt;
&lt;blockquote&gt; 
&lt;p&gt;
&lt;strong&gt;IBM presses&lt;/strong&gt; - you need to build agentic solutions.
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Arthur tells&lt;/strong&gt; - what we have can be called agentic use of AI. It just
works without buzz words.
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;I tell&lt;/strong&gt; - yes, that&amp;#39;s correct, but it&amp;#39;s not easy to implement
non-trivial AI flow, including tool calls, while sticking to the Batch API.
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Arthur&lt;/strong&gt; - not trivial but possible. Our solution is scalable, we understand
it, and we easily support it. So, per the first rule of programming - don&amp;#39;t fix
something that is working!
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;I&lt;/strong&gt; - I want to explore what other solutions can give us.
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Arthur, skeptically&lt;/strong&gt; - go on, and I&amp;#39;ll be looking at your efforts!
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;h3 id="exploring-the-landscape"&gt;Exploring the Landscape
&lt;/h3&gt;
&lt;p&gt;
So, I went on discovering today&amp;#39;s landscape of agentic AI libraries.
&lt;/p&gt;
&lt;p&gt;
As you know, there are many of them - from Microsoft, from the community, and for
other providers. We have our constraints. Being part of IBM means &lt;strong&gt;Langchain&lt;/strong&gt; is
the default choice. You would need to have good arguments to use something different.
&lt;/p&gt;
&lt;p&gt;
Okay, we agreed with Arthur that &lt;strong&gt;Langchain&lt;/strong&gt; is what I&amp;#39;ll continue
to explore.
&lt;/p&gt;
&lt;p&gt;
Then I went forward looking at how I could implement our sample task with massive
processing of folders of data.
&lt;/p&gt;
&lt;p&gt;
What came naturally is &lt;strong&gt;LangGraph&lt;/strong&gt; - the framework to implement different
workflows, including cycles, parallel processing, AI calls, and checkpointing of execution.
&lt;/p&gt;
&lt;p&gt;
Checkpointing looked promising - I could run the flow, save intermediate results,
stop, restart, and do different things with state. This was encouraging for a long-running
flow.
&lt;/p&gt;
&lt;p&gt;
I&amp;#39;ve found that with some effort, you could even integrate the Batch API into
it. I was positive about the right direction. Arthur wisely listened and agreed that
this sounds promising.
&lt;/p&gt;
&lt;h3 id="language-selection"&gt;Language Selection
&lt;/h3&gt;
&lt;p&gt;
Next step was to select the language.
&lt;/p&gt;
&lt;p&gt;
Several years ago I would say it&amp;#39;s weird to select a framework and then language,
but these days the world has changed.
&lt;/p&gt;
&lt;p&gt;
We found that &lt;strong&gt;LangGraph&lt;/strong&gt; has:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
Original implementation in &lt;strong&gt;Python&lt;/strong&gt;, which is most advanced&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;TypeScript&lt;/strong&gt; port&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;LangGraph4j&lt;/strong&gt; - Java version inspired by Python&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
For us it was not immediately obvious what to use, as we don&amp;#39;t start a new project
but continue ongoing development. Our preferences go with &lt;strong&gt;LangGraph4j&lt;/strong&gt; -
there will be fewer moving parts, and it will integrate naturally.
&lt;/p&gt;
&lt;h3 id="poc-sample"&gt;POC Sample
&lt;/h3&gt;
&lt;p&gt;
Now we needed hands-on experience with the technology to study it deeper and implement
a simplest flow.
&lt;/p&gt;
&lt;p&gt;
What I learned is that &lt;strong&gt;LangGraph&lt;/strong&gt; is a library to define a logic flow
in a semi-declarative way as a graph of edges and vertices, where:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Edge&lt;/strong&gt; - defines a unit of logic&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Vertices&lt;/strong&gt; - define transitions between edges&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
In general, &lt;strong&gt;LangGraph&lt;/strong&gt; has nothing to do with &lt;strong&gt;LangChain&lt;/strong&gt;,
which is an AI wrapper. You can do whatever you want with &lt;strong&gt;LangGraph&lt;/strong&gt;,
including calling AI through &lt;strong&gt;LangChain&lt;/strong&gt;. &lt;strong&gt;LangGraph&lt;/strong&gt; allows
you to stop execution, save state somewhere (e.g., in files or in a database), and
later resume.
&lt;/p&gt;
&lt;p&gt;
Arthur was satisfied and told me that the flow graph resembled his old favorite BizTalk,
which allowed you to define a high-level algorithm visually, and the final block could
be implemented by calling real code.
&lt;/p&gt;
&lt;p&gt;
All this looked promising and allowed us to implement some simple tasks:
&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
An agent to perform simple math: &lt;code&gt;Sum(a, b)&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
An agent to perform a simple cycle of sub-agents&lt;/li&gt;
&lt;li&gt;
An agent to perform a parallel cycle of sub-agents&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;
I started with Task 1 - the Sum agent - and implemented it using a &lt;strong&gt;LangGraph&lt;/strong&gt; sample.
It included a map-based immutable state, graph definitions, and node handlers.
&lt;/p&gt;
&lt;p&gt;
Arthur looked at it for a long time and told me that he barely understood what he
saw and barely understood where the business logic (&lt;code&gt;a + b&lt;/code&gt;) was.
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Verdict&lt;/strong&gt; - this is an obscure, unmanageable pile of code. We need
something less clever if we want to understand it in half a year.
&lt;/p&gt;
&lt;p&gt;
I went back and introduced some helpers to simplify agent coding in &lt;strong&gt;LangGraph4j&lt;/strong&gt;.
This allowed me to produce much smaller and concise code, which I want to quote here:
&lt;/p&gt;
&lt;pre&gt;&lt;code class="lang-java"&gt;&lt;span class="hljs-keyword"&gt;package&lt;/span&gt; com.bphx.coolgen.agents; &lt;span class="hljs-keyword"&gt;import&lt;/span&gt; org.bsc.langgraph4j.CompileConfig; &lt;span class="hljs-keyword"&gt;import&lt;/span&gt; org.bsc.langgraph4j.CompiledGraph; &lt;span class="hljs-keyword"&gt;import&lt;/span&gt; org.bsc.langgraph4j.RunnableConfig; &lt;span class="hljs-keyword"&gt;import&lt;/span&gt; org.bsc.langgraph4j.StateGraph; &lt;span class="hljs-keyword"&gt;import&lt;/span&gt; &lt;span class="hljs-keyword"&gt;static&lt;/span&gt; com.bphx.coolgen.agents.Agent.*; &lt;span class="hljs-keyword"&gt;import&lt;/span&gt; java.io.Serializable; &lt;span class="hljs-comment"&gt;///
Sample agent demonstrating basic LangGraph4j usage. Receives two numbers and&lt;/span&gt; &lt;span class="hljs-comment"&gt;///
computes their sum.&lt;/span&gt; &lt;span class="hljs-comment"&gt;///&lt;/span&gt; &lt;span class="hljs-comment"&gt;///
Uses state class [Data].&lt;/span&gt; &lt;span class="hljs-comment"&gt;///&lt;/span&gt; &lt;span class="hljs-comment"&gt;///
## Usage&lt;/span&gt; &lt;span class="hljs-comment"&gt;///&lt;/span&gt; &lt;span class="hljs-comment"&gt;///
var graph = Sum.build();&lt;/span&gt; &lt;span class="hljs-comment"&gt;/// var data = Sum.of(10.0,
32.0);&lt;/span&gt; &lt;span class="hljs-comment"&gt;/// var result = Agent.invoke(graph, data);&lt;/span&gt; &lt;span class="hljs-comment"&gt;///
System.out.println("Sum: " + result.result); // prints: Sum: 42.0&lt;/span&gt; &lt;span class="hljs-keyword"&gt;public&lt;/span&gt; &lt;span class="hljs-keyword"&gt;final&lt;/span&gt; &lt;span class="hljs-class"&gt;&lt;span class="hljs-keyword"&gt;class&lt;/span&gt; &lt;span class="hljs-title"&gt;Sum&lt;/span&gt; &lt;/span&gt;{ &lt;span class="hljs-comment"&gt;///
State class for the Sum agent. Contains input operands and the&lt;/span&gt; &lt;span class="hljs-comment"&gt;///
computed result.&lt;/span&gt; &lt;span class="hljs-keyword"&gt;public&lt;/span&gt; &lt;span class="hljs-keyword"&gt;static&lt;/span&gt; &lt;span class="hljs-class"&gt;&lt;span class="hljs-keyword"&gt;class&lt;/span&gt; &lt;span class="hljs-title"&gt;Data&lt;/span&gt; &lt;span class="hljs-keyword"&gt;implements&lt;/span&gt; &lt;span class="hljs-title"&gt;Serializable&lt;/span&gt; &lt;/span&gt;{ &lt;span class="hljs-function"&gt;&lt;span class="hljs-keyword"&gt;public&lt;/span&gt; &lt;span class="hljs-title"&gt;Data&lt;/span&gt;&lt;span class="hljs-params"&gt;(&lt;span class="hljs-keyword"&gt;double&lt;/span&gt; a, &lt;span class="hljs-keyword"&gt;double&lt;/span&gt; b)&lt;/span&gt; &lt;/span&gt;{ &lt;span class="hljs-keyword"&gt;this&lt;/span&gt;.a
= a; &lt;span class="hljs-keyword"&gt;this&lt;/span&gt;.b = b; } &lt;span class="hljs-keyword"&gt;public&lt;/span&gt; &lt;span class="hljs-keyword"&gt;final&lt;/span&gt; &lt;span class="hljs-keyword"&gt;double&lt;/span&gt; a; &lt;span class="hljs-keyword"&gt;public&lt;/span&gt; &lt;span class="hljs-keyword"&gt;final&lt;/span&gt; &lt;span class="hljs-keyword"&gt;double&lt;/span&gt; b; &lt;span class="hljs-keyword"&gt;public&lt;/span&gt; &lt;span class="hljs-keyword"&gt;double&lt;/span&gt; result;
} &lt;span class="hljs-keyword"&gt;public&lt;/span&gt; &lt;span class="hljs-keyword"&gt;static&lt;/span&gt; &lt;span class="hljs-function"&gt;Data &lt;span class="hljs-title"&gt;of&lt;/span&gt;&lt;span class="hljs-params"&gt;(&lt;span class="hljs-keyword"&gt;double&lt;/span&gt; a, &lt;span class="hljs-keyword"&gt;double&lt;/span&gt; b)&lt;/span&gt; &lt;/span&gt;{ &lt;span class="hljs-keyword"&gt;return&lt;/span&gt; &lt;span class="hljs-keyword"&gt;new&lt;/span&gt; Data(a,
b); } &lt;span class="hljs-comment"&gt;/// Builds and returns a compiled graph for the sum
agent.&lt;/span&gt; &lt;span class="hljs-comment"&gt;/// &lt;/span&gt; &lt;span class="hljs-comment"&gt;///
@return compiled graph ready to invoke&lt;/span&gt; &lt;span class="hljs-comment"&gt;/// @throws
Exception if graph compilation fails&lt;/span&gt; &lt;span class="hljs-keyword"&gt;public&lt;/span&gt; &lt;span class="hljs-keyword"&gt;static&lt;/span&gt; CompiledGraph&amp;lt;State&amp;lt;Data&amp;gt;&amp;gt;
build() &lt;span class="hljs-keyword"&gt;throws&lt;/span&gt; Exception { &lt;span class="hljs-keyword"&gt;return&lt;/span&gt; Agent.&amp;lt;Data&amp;gt;graph()
.addNode(&lt;span class="hljs-string"&gt;"sum"&lt;/span&gt;, node(Sum::sum)) .addEdge(StateGraph.START, &lt;span class="hljs-string"&gt;"sum"&lt;/span&gt;)
.addEdge(&lt;span class="hljs-string"&gt;"sum"&lt;/span&gt;, StateGraph.END) .compile(CompileConfig.builder().build());
} &lt;span class="hljs-keyword"&gt;private&lt;/span&gt; &lt;span class="hljs-keyword"&gt;static&lt;/span&gt; &lt;span class="hljs-function"&gt;Data &lt;span class="hljs-title"&gt;sum&lt;/span&gt;&lt;span class="hljs-params"&gt;(Data
data, RunnableConfig config)&lt;/span&gt; &lt;/span&gt;{ data.result = data.a + data.b; &lt;span class="hljs-keyword"&gt;return&lt;/span&gt; data;
} } &lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;
Arthur confirmed that he was able to understand that &lt;code&gt;sum()&lt;/code&gt; defines the
business logic, the &lt;code&gt;Data&lt;/code&gt; class defines the graph state, and &lt;code&gt;build()&lt;/code&gt; defines
the graph itself, like this: &lt;code&gt;start -&amp;gt; sum -&amp;gt; end&lt;/code&gt;.
&lt;/p&gt;
&lt;p&gt;
However, neither Arthur nor I were fully satisfied.
&lt;/p&gt;
&lt;p&gt;
At the next step, I implemented Task 2 - a cycle of Sum calls. This worked, but it
looked as if you were building assembly with a graph, as if you need to implement:
&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;start: &lt;span class="hljs-built_in"&gt;index&lt;/span&gt; = &lt;span class="hljs-number"&gt;0&lt;/span&gt;; &lt;span class="hljs-built_in"&gt;count&lt;/span&gt; = &lt;span class="hljs-number"&gt;1000&lt;/span&gt;; &lt;span class="hljs-keyword"&gt;cycle&lt;/span&gt;: &lt;span class="hljs-keyword"&gt;if&lt;/span&gt; (&lt;span class="hljs-built_in"&gt;index&lt;/span&gt; &amp;gt;= &lt;span class="hljs-built_in"&gt;count&lt;/span&gt;) &lt;span class="hljs-keyword"&gt;goto&lt;/span&gt; &lt;span class="hljs-keyword"&gt;end&lt;/span&gt;;
iteration: result[&lt;span class="hljs-built_in"&gt;index&lt;/span&gt;] = a[&lt;span class="hljs-built_in"&gt;index&lt;/span&gt;]
+ b[&lt;span class="hljs-built_in"&gt;index&lt;/span&gt;]; &lt;span class="hljs-built_in"&gt;index&lt;/span&gt; = &lt;span class="hljs-built_in"&gt;index&lt;/span&gt; + &lt;span class="hljs-number"&gt;1&lt;/span&gt;; &lt;span class="hljs-keyword"&gt;goto&lt;/span&gt; &lt;span class="hljs-keyword"&gt;cycle&lt;/span&gt;; &lt;span class="hljs-keyword"&gt;end&lt;/span&gt;: &lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;
This works but doesn&amp;#39;t look nice. Besides, debugging &lt;strong&gt;LangGraph&lt;/strong&gt; code
is an adventure.
&lt;/p&gt;
&lt;p&gt;
Finally, the 3rd task was the least trivial part to implement. It turned out there
is no built-in parallel cycles, and we needed to go to the basic fork-join building
block in &lt;strong&gt;LangGraph&lt;/strong&gt; to generate a dynamic graph for parallel processing.
&lt;/p&gt;
&lt;p&gt;
This worked as well, but it became even more complex, involving merging states after
parallel branches and uncontrolled serialization and deserialization of all accumulated
states.
&lt;/p&gt;
&lt;p&gt;
It did not look like a good trade. We lost clean, readable Java code in exchange for
a resumable graph that is hard to understand and debug.
&lt;/p&gt;
&lt;h2 id="next-steps"&gt;Next Steps
&lt;/h2&gt;
&lt;p&gt;
We implemented the original task of processing a folder in parallel, where we called &lt;strong&gt;LangChain&lt;/strong&gt; and
were pleased with its AI services. You could define an interface and get its implementation
from &lt;code&gt;ChatModel&lt;/code&gt; (which even supports tool calls), like this:
&lt;/p&gt;
&lt;pre&gt;&lt;code class="lang-java"&gt; &lt;span class="hljs-comment"&gt;/// AI service interface
for generating HTML documentation summaries.&lt;/span&gt; &lt;span class="hljs-comment"&gt;///&lt;/span&gt; &lt;span class="hljs-comment"&gt;///
LangChain4j creates an implementation that calls the chat model with&lt;/span&gt; &lt;span class="hljs-comment"&gt;///
a system prompt.&lt;/span&gt; &lt;span class="hljs-keyword"&gt;interface&lt;/span&gt; &lt;span class="hljs-type"&gt;Summarizer&lt;/span&gt; {
@&lt;span class="hljs-type"&gt;SystemMessage&lt;/span&gt;(&lt;span class="hljs-string"&gt;""" You are
a world class expert in programming... Create documentation for the provided code
to ... Use basic HTML markup, like &amp;lt;h1&amp;gt;, &amp;lt;p&amp;gt;, &amp;lt;b&amp;gt;, &amp;lt;ol&amp;gt;, &amp;lt;ul&amp;gt;,
&amp;lt;li&amp;gt;. Don't use &amp;lt;html&amp;gt; and &amp;lt;body&amp;gt;. - Documentation must be terse.
- No greetings and farewells must be used. - Provide a summary of the code's purpose
and functionality. ... """&lt;/span&gt;) &lt;span class="hljs-type"&gt;String&lt;/span&gt; summarize(@&lt;span class="hljs-type"&gt;UserMessage&lt;/span&gt; &lt;span class="hljs-type"&gt;String&lt;/span&gt; code);
} ... &lt;span class="hljs-keyword"&gt;var&lt;/span&gt; summarizer = &lt;span class="hljs-type"&gt;AiServices&lt;/span&gt;.create(&lt;span class="hljs-type"&gt;Summarizer&lt;/span&gt;.&lt;span class="hljs-keyword"&gt;class&lt;/span&gt;,
chatModel); ... &lt;span class="hljs-keyword"&gt;var&lt;/span&gt; summary = summarizer.summarize(code); &lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;
Notice the elegance: the entire AI integration is reduced to a single interface definition
and one line of instantiation. The business logic (&lt;code&gt;summarize()&lt;/code&gt;) is immediately
visible. Compare this to the earlier &lt;strong&gt;LangGraph&lt;/strong&gt; Sum agent with its
graph definitions, node handlers, and state management—this is why we prefer it.
&lt;/p&gt;
&lt;h3 id="sharing-our-approach"&gt;Sharing Our Approach
&lt;/h3&gt;
&lt;p&gt;
We&amp;#39;re planning to share this pattern with our team as the recommended path forward
for AI integration. Rather than pursuing the latest agentic frameworks, teams should:
&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Start with explicit state management&lt;/strong&gt; in their language of choice&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Use focused AI libraries&lt;/strong&gt; like &lt;strong&gt;LangChain4j&lt;/strong&gt; for clean
abstraction&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Avoid graph frameworks unless truly needed&lt;/strong&gt; for distributed resumability&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Prioritize code clarity&lt;/strong&gt; over framework comprehensiveness&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id="future-roadmap"&gt;Future Roadmap
&lt;/h3&gt;
&lt;p&gt;
The Java + &lt;strong&gt;LangChain&lt;/strong&gt; pattern scales well for:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Batch processing&lt;/strong&gt; of large folders with parallel &lt;strong&gt;LangChain&lt;/strong&gt; calls&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Multi-step AI workflows&lt;/strong&gt; (chain multiple AI services together)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Tool-augmented AI&lt;/strong&gt; (extending ChatModel with custom tools)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Integration with existing systems&lt;/strong&gt; where Java is already the lingua
franca&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
We&amp;#39;re confident this approach will serve our organization better than chasing
trending frameworks.
&lt;/p&gt;
&lt;h2 id="key-learnings"&gt;Key Learnings
&lt;/h2&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;
&lt;strong&gt;Buzzwords ≠ Solutions&lt;/strong&gt;: The pressure to &amp;quot;build agentic solutions&amp;quot;
made us evaluate tools strictly on merit, not hype. Sometimes &amp;quot;agentic&amp;quot;
is just marketing.
&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;
&lt;strong&gt;Abstraction Layers Matter&lt;/strong&gt;: &lt;strong&gt;LangChain&lt;/strong&gt;&amp;#39;s declarative
approach (&lt;code&gt;@SystemMessage&lt;/code&gt;, &lt;code&gt;AiServices&lt;/code&gt;) hides complexity elegantly. &lt;strong&gt;LangGraph&lt;/strong&gt;&amp;#39;s
explicit node-edge model exposed too many low-level details for our domain.
&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;
&lt;strong&gt;Code Readability Wins Long-term&lt;/strong&gt;: Arthur&amp;#39;s visceral reaction to
the initial &lt;strong&gt;LangGraph&lt;/strong&gt; code—&amp;quot;barely understand where the business
logic is&amp;quot;—reminded us that clever code is harder to maintain than straightforward
code (even with AI).
&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;
&lt;strong&gt;Pragmatism Over Features&lt;/strong&gt;: Our Batch API solution already solved resumability
and scalability. Adopting a framework for features you don&amp;#39;t need creates unnecessary
technical debt.
&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;
&lt;strong&gt;Pure Language + Focused Libraries&lt;/strong&gt;: Combining plain Java + &lt;strong&gt;LangChain&lt;/strong&gt; gave
us the best of both worlds: explicit control over algorithms and clean AI abstraction.
&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id="when-langgraph-makes-sense"&gt;When LangGraph Makes Sense
&lt;/h3&gt;
&lt;p&gt;
Before we dismiss &lt;strong&gt;LangGraph&lt;/strong&gt; entirely, it&amp;#39;s worth noting when
it might be the right choice:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Truly distributed systems&lt;/strong&gt; where processes run on different machines
and need to resume&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Long-running, unattended workflows&lt;/strong&gt; that span days or weeks and need
checkpointing (though native java implementation gave us flexibility on checkpoints)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Complex branching logic&lt;/strong&gt; with many conditional paths that benefit
from visual representation&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Systems requiring audit trails&lt;/strong&gt; of every state transition&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
For our use case—batch processing with intermediate results we can manage explicitly—&lt;strong&gt;LangGraph&lt;/strong&gt; was
overkill.
&lt;/p&gt;
&lt;h2 id="conclusion"&gt;Conclusion
&lt;/h2&gt;
&lt;p&gt;
After working through these explorations, we reached a &lt;strong&gt;nuanced but clear conclusion&lt;/strong&gt;:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;LangChain&lt;/strong&gt; - Excellent. Provides clean abstractions for AI integration
without forcing architectural decisions.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;LangGraph&lt;/strong&gt; - Not a fit for our use cases. Its complexity and explicit
state serialization overhead outweigh the benefits for batch processing. For truly
distributed, long-running workflows, it might be appropriate, but we have simpler
solutions.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="the-better-way-forward"&gt;The Better Way Forward
&lt;/h3&gt;
&lt;p&gt;
We re-implemented several processes that used the OpenAI Batch API in pure Java + &lt;strong&gt;LangChain&lt;/strong&gt;,
and even extended the logic to multi-step AI calls. The results:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Cleaner code&lt;/strong&gt; than the original Batch API implementation&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;More powerful&lt;/strong&gt; (support for complex multi-turn conversations)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Faster execution&lt;/strong&gt; (parallel processing without batching delays)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Easier to maintain&lt;/strong&gt; (straightforward Java instead of graph abstractions)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
Thus, we believe our decision to explore and eventually adopt the Java + &lt;strong&gt;LangChain&lt;/strong&gt; pattern
was the right one. We gained the benefits of modern AI frameworks without sacrificing
the simplicity and maintainability that Arthur and I both prioritize.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=ca777d18-5f91-4c7a-bb5c-52a1719af9be" /&gt;</description>
      <comments>http://www.nesterovsky-bros.com/weblog/CommentView,guid,ca777d18-5f91-4c7a-bb5c-52a1719af9be.aspx</comments>
      <category>AI</category>
      <category>Thinking aloud</category>
      <category>Tips and tricks</category>
    </item>
    <item>
      <trackback:ping>http://www.nesterovsky-bros.com/weblog/Trackback.aspx?guid=8219bbc1-5817-493d-b7fe-58ca60dc48d5</trackback:ping>
      <pingback:server>http://www.nesterovsky-bros.com/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,8219bbc1-5817-493d-b7fe-58ca60dc48d5.aspx</pingback:target>
      <dc:creator>Arthur Nesterovsky</dc:creator>
      <georss:point>0 0</georss:point>
      <wfw:comment>http://www.nesterovsky-bros.com/weblog/CommentView,guid,8219bbc1-5817-493d-b7fe-58ca60dc48d5.aspx</wfw:comment>
      <wfw:commentRss>http://www.nesterovsky-bros.com/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=8219bbc1-5817-493d-b7fe-58ca60dc48d5</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Would you like to smile a little? Then read this dialog that occured today, April
10, 2024: 
</p>
        <img src="http://www.nesterovsky-bros.com/images/ai_joke.png" style="width: 1024px" alt="dialog" />
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=8219bbc1-5817-493d-b7fe-58ca60dc48d5" />
      </body>
      <title>AI joke...</title>
      <guid isPermaLink="false">http://www.nesterovsky-bros.com/weblog/PermaLink,guid,8219bbc1-5817-493d-b7fe-58ca60dc48d5.aspx</guid>
      <link>http://www.nesterovsky-bros.com/weblog/2024/04/10/AIJoke.aspx</link>
      <pubDate>Wed, 10 Apr 2024 09:56:26 GMT</pubDate>
      <description>&lt;p&gt;
Would you like to smile a little? Then read this dialog that occured today, April
10, 2024: 
&lt;/p&gt;
&lt;img src="http://www.nesterovsky-bros.com/images/ai_joke.png" style="width: 1024px" alt="dialog"&gt;&lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=8219bbc1-5817-493d-b7fe-58ca60dc48d5" /&gt;</description>
      <comments>http://www.nesterovsky-bros.com/weblog/CommentView,guid,8219bbc1-5817-493d-b7fe-58ca60dc48d5.aspx</comments>
    </item>
    <item>
      <trackback:ping>http://www.nesterovsky-bros.com/weblog/Trackback.aspx?guid=371a8329-d392-4d20-bcbc-db9503816f26</trackback:ping>
      <pingback:server>http://www.nesterovsky-bros.com/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,371a8329-d392-4d20-bcbc-db9503816f26.aspx</pingback:target>
      <dc:creator>Vladimir Nesterovsky</dc:creator>
      <georss:point>0 0</georss:point>
      <wfw:commentRss>http://www.nesterovsky-bros.com/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=371a8329-d392-4d20-bcbc-db9503816f26</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <h4>Introduction
</h4>
        <p>
We migrate code out of MF to Azure. Tool we use produces plain good functionally equivalent
C# code. But it turns it's not enough!
</p>
        <p>
So, what's the problem?
</p>
        <p>
Converted code is very slow, especially for batch processing, where MF completes job,
say in 30 minutes, while converted code finishes in 8 hours.
</p>
        <p>
At this point usually someone appears and whispers in the ear:
</p>
        <blockquote>
          <p>
Look, those old technologies are proven by the time. It worth to stick to old good
Cobol, or better to Assembler if you want to do the real thing.
</p>
        </blockquote>
        <p>
We're curious though: why is there a difference?
</p>
        <p>
Turns out the issue lies in differences of network topology between MF and Azure solutions.
On MF all programs, database and file storage virtually sit in a single box, thus
network latency is negligible. 
</p>
        <p>
It's rather usual to see chatty SQL programs on MF that are doing a lot of small
SQL queries.
</p>
        <p>
In Azure - programs, database, file storage are different services most certainly
sitting in different phisical boxes. You should be thankfull if they are co-located
in a single datacenter. So, network latency immediately becomes a factor. Even if
it just adds 1 millisecond per SQL roundtrip, it adds up in loops, and turns in the
showstopper.
</p>
        <p>
There is no easy workaround on the hardware level.
</p>
        <p>
People advice to write programs differently: "<a href="https://learn.microsoft.com/en-us/azure/azure-sql/database/performance-guidance">Tune
applications and databases for performance in Azure SQL Database</a>".
</p>
        <p>
That's a good advice for a new development but discouraging for migration done
by a tool.
</p>
        <p>
So, what is the way forward?
</p>
        <p>
Well, there is one. While accepting weak sides of Azure we can exploit its strong
sides.
</p>
        <h4>Parallel refactoring
</h4>
        <p>
Before continuing let's consider a <a href="https://github.com/nesterovsky-bros/parallel-refactoring/tree/master/Services/SerialProcessor.cs#L5-L29">code</a> demoing
the problem:
</p>
        <pre>
          <code class="lang-C#">
            <span class="hljs-keyword">public</span>
            <span class="hljs-literal">void</span> CreateReport(StringWriter
writer) { <span class="hljs-built_in">var</span> index = <span class="hljs-number">0</span>;
foreach(<span class="hljs-built_in">var</span> transaction <span class="hljs-keyword">in</span> dataService.
GetTransactions(). OrderBy(item =&gt; (item.At, item.SourceAccountId))) { <span class="hljs-built_in">var</span> sourceAccount
= dataService.GetAccount(transaction.SourceAccountId); <span class="hljs-built_in">var</span> targetAccount
= transaction.TargetAccountId != <span class="hljs-built_in">null</span> ? dataService.GetAccount(transaction.TargetAccountId)
: <span class="hljs-built_in">null</span>; ++index; <span class="hljs-keyword">if</span> (index
% <span class="hljs-number">100</span> == <span class="hljs-number">0</span>) { Console.WriteLine(index);
} writer.WriteLine($<span class="hljs-string">"{index},{transaction.Id},{ transaction.At},{transaction.Type},{transaction.Amount},{
transaction.SourceAccountId},{sourceAccount?.Name},{ transaction.TargetAccountId},{targetAccount?.Name}"</span>);
} } </code>
        </pre>
        <p>
This cycle queries transactions, along with two more small queries to get source and
target accounts for each transaction. Results are printed into a report.
</p>
        <p>
If we assume query latency just 1 millisecond, and try to run such code for 100K transactions
we easily come to 200+ seconds of execution. 
</p>
        <p>
Reality turns to be much worse. Program spends most of its lifecycle waiting for database
results, and iterations don't advance until all work of previous iterations is
complete.
</p>
        <p>
We could do better even without trying to rewrite all code! Let's articulate our
goals:
</p>
        <ol>
          <li>
To make code fast.</li>
          <li>
To leave code recognizable.</li>
        </ol>
        <p>
The idea is to form two processing pipelines:
</p>
        <ul>
          <li>
(a) one that processes data in parallel out of order;</li>
          <li>
(b) other that processes data serially, in original order;</li>
        </ul>
        <p>
Each pipeline may post sub-tasks to the other, so (a) runs its tasks in parallel unordered,
while (b) runs its tasks as if everything was running serially.
</p>
        <p>
So, parallel plan would be like this:
</p>
        <ol>
          <li>
Queue parallel sub-tasks (a) for each transaction.</li>
          <li>
Parallel sub-task in (a) reads source and target accounts, and queues serial sub-task
(b) passing transaction and accounts.</li>
          <li>
Serial sub-task (b) increments index, and writes report record.</li>
          <li>
Wait for all tasks to complete.</li>
        </ol>
        <p>
To reduce burden of task piplelines we use <a href="https://learn.microsoft.com/en-us/dotnet/standard/parallel-programming/dataflow-task-parallel-library">Dataflow
(Task Parallel Library)</a>, and encapsulate everything in a small wrapper.
</p>
        <p>
Consider refactored <a href="https://github.com/nesterovsky-bros/parallel-refactoring/tree/master/Services/ParallelProcessor.cs#L14-L48">code</a>:
</p>
        <pre>
          <code class="lang-C#">
            <span class="hljs-keyword">public</span>
            <span class="hljs-literal">void</span> CreateReport(StringWriter
writer) { using <span class="hljs-built_in">var</span> parallel = <span class="hljs-literal">new</span> Parallel(options.Value.Parallelism); <span class="hljs-comment">//
⬅️ 1</span><span class="hljs-built_in">var</span> index = <span class="hljs-number">0</span>;
parallel.ForEachAsync( <span class="hljs-comment">// ⬅️ 2</span> dataService. GetTransactions().
OrderBy(item =&gt; (item.At, item.SourceAccountId)), transaction =&gt; <span class="hljs-comment">//
⬅️ 3</span> { <span class="hljs-built_in">var</span> sourceAccount = dataService.GetAccount(transaction.SourceAccountId); <span class="hljs-built_in">var</span> targetAccount
= transaction.TargetAccountId != <span class="hljs-built_in">null</span> ? dataService.GetAccount(transaction.TargetAccountId)
: <span class="hljs-built_in">null</span>; parallel.PostSync( <span class="hljs-comment">//
⬅️ 4</span> (transaction, sourceAccount, targetAccount), <span class="hljs-comment">//
⬅️ 5</span><span class="hljs-built_in">data</span> =&gt; { <span class="hljs-built_in">var</span> (transaction,
sourceAccount, targetAccount) = <span class="hljs-built_in">data</span>; <span class="hljs-comment">//
⬅️ 6</span> ++index; <span class="hljs-keyword">if</span> (index % <span class="hljs-number">100</span> == <span class="hljs-number">0</span>)
{ Console.WriteLine(index); } writer.WriteLine($<span class="hljs-string">"{index},{transaction.Id},{
transaction.At},{transaction.Type},{transaction.Amount},{ transaction.SourceAccountId},{sourceAccount?.Name},{
transaction.TargetAccountId},{targetAccount?.Name}"</span>); }); }); } </code>
        </pre>
        <p>
Consider ⬅️ points:
</p>
        <ol>
          <li>
We create <code>Parallel</code> utility class passing degree of parallelism requested.</li>
          <li>
We iterate transactions using <code>parallel.ForEachAsync()</code> that queues parallel
sub-tasks for each transaction, and then waits until all tasks are complete.</li>
          <li>
Each parallel sub-task recieves a transaction. It may be called from a different thread.</li>
          <li>
Having recieved required accounts we queue a sub-task for synchronous execution using <code>parallel.PostSync()</code>,
and</li>
          <li>
Pass there data collected in parallel sub-task: transaction and accounts.</li>
          <li>
We deconstruct data passed into variables, and then proceed with serial logic.</li>
        </ol>
        <p>
What we achieve with this refactoring:
</p>
        <ol>
          <li>
Top level query that brings transactions is done and iterated serially.</li>
          <li>
But each iteration body is run in parallel. By default we set it up to allow up to
100 parallel executions. All those parallel sub-task do not wait on each other so
their waitings do not add up.</li>
          <li>
Sync sub-tasks are queued and executed in order of their serial appearance, so increments
and report records are not a subject of race conditions, nor a subject of reordering
of output records.</li>
        </ol>
        <p>
We think that such refactored code is still recognizible.
</p>
        <p>
As for performance this is what log shows:
</p>
        <pre>
          <code class="lang-log">
            <span class="hljs-selector-tag">Serial</span>
            <span class="hljs-selector-tag">test</span> 100
... <span class="hljs-selector-tag">Execution</span><span class="hljs-selector-tag">time</span>:
00<span class="hljs-selector-pseudo">:01</span><span class="hljs-selector-pseudo">:33.8152540</span><span class="hljs-selector-tag">Parallel</span><span class="hljs-selector-tag">test</span> 100
... <span class="hljs-selector-tag">Execution</span><span class="hljs-selector-tag">time</span>:
00<span class="hljs-selector-pseudo">:00</span><span class="hljs-selector-pseudo">:05.8705468</span></code>
        </pre>
        <h4>Reference
</h4>
        <p>
Please take a look at project to understand implementation details, and in particular <a href="https://github.com/nesterovsky-bros/parallel-refactoring/tree/master/Services/Parallel.cs"><code>Parallel</code></a> class
implementing API to post parallel and serial tasks, run cycles and some more.
</p>
        <p>
Please continue reading on <a href="https://github.com/nesterovsky-bros/parallel-refactoring/tree/master?tab=readme-ov-file#parallel-refactoring">GitHub</a>.
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=371a8329-d392-4d20-bcbc-db9503816f26" />
      </body>
      <title>Experience of parallel refactoring</title>
      <guid isPermaLink="false">http://www.nesterovsky-bros.com/weblog/PermaLink,guid,371a8329-d392-4d20-bcbc-db9503816f26.aspx</guid>
      <link>http://www.nesterovsky-bros.com/weblog/2024/01/26/ExperienceOfParallelRefactoring.aspx</link>
      <pubDate>Fri, 26 Jan 2024 13:27:16 GMT</pubDate>
      <description>&lt;h4&gt;Introduction
&lt;/h4&gt;
&lt;p&gt;
We migrate code out of MF to Azure. Tool we use produces plain good functionally equivalent
C# code. But it turns it&amp;#39;s not enough!
&lt;/p&gt;
&lt;p&gt;
So, what&amp;#39;s the problem?
&lt;/p&gt;
&lt;p&gt;
Converted code is very slow, especially for batch processing, where MF completes job,
say in 30 minutes, while converted code finishes in 8 hours.
&lt;/p&gt;
&lt;p&gt;
At this point usually someone appears and whispers in the ear:
&lt;/p&gt;
&lt;blockquote&gt; 
&lt;p&gt;
Look, those old technologies are proven by the time. It worth to stick to old good
Cobol, or better to Assembler if you want to do the real thing.
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
We&amp;#39;re curious though: why is there a difference?
&lt;/p&gt;
&lt;p&gt;
Turns out the issue lies in differences of network topology between MF and Azure solutions.
On MF all programs, database and file storage virtually sit in a single box, thus
network latency is negligible. 
&lt;/p&gt;
&lt;p&gt;
It&amp;#39;s rather usual to see chatty SQL programs on MF that are doing a lot of small
SQL queries.
&lt;/p&gt;
&lt;p&gt;
In Azure - programs, database, file storage are different services most certainly
sitting in different phisical boxes. You should be thankfull if they are co-located
in a single datacenter. So, network latency immediately becomes a factor. Even if
it just adds 1 millisecond per SQL roundtrip, it adds up in loops, and turns in the
showstopper.
&lt;/p&gt;
&lt;p&gt;
There is no easy workaround on the hardware level.
&lt;/p&gt;
&lt;p&gt;
People advice to write programs differently: &amp;quot;&lt;a href="https://learn.microsoft.com/en-us/azure/azure-sql/database/performance-guidance"&gt;Tune
applications and databases for performance in Azure SQL Database&lt;/a&gt;&amp;quot;.
&lt;/p&gt;
&lt;p&gt;
That&amp;#39;s a good advice for a new development but discouraging for migration done
by a tool.
&lt;/p&gt;
&lt;p&gt;
So, what is the way forward?
&lt;/p&gt;
&lt;p&gt;
Well, there is one. While accepting weak sides of Azure we can exploit its strong
sides.
&lt;/p&gt;
&lt;h4&gt;Parallel refactoring
&lt;/h4&gt;
&lt;p&gt;
Before continuing let&amp;#39;s consider a &lt;a href="https://github.com/nesterovsky-bros/parallel-refactoring/tree/master/Services/SerialProcessor.cs#L5-L29"&gt;code&lt;/a&gt; demoing
the problem:
&lt;/p&gt;
&lt;pre&gt;&lt;code class="lang-C#"&gt; &lt;span class="hljs-keyword"&gt;public&lt;/span&gt; &lt;span class="hljs-literal"&gt;void&lt;/span&gt; CreateReport(StringWriter
writer) { &lt;span class="hljs-built_in"&gt;var&lt;/span&gt; index = &lt;span class="hljs-number"&gt;0&lt;/span&gt;;
foreach(&lt;span class="hljs-built_in"&gt;var&lt;/span&gt; transaction &lt;span class="hljs-keyword"&gt;in&lt;/span&gt; dataService.
GetTransactions(). OrderBy(item =&amp;gt; (item.At, item.SourceAccountId))) { &lt;span class="hljs-built_in"&gt;var&lt;/span&gt; sourceAccount
= dataService.GetAccount(transaction.SourceAccountId); &lt;span class="hljs-built_in"&gt;var&lt;/span&gt; targetAccount
= transaction.TargetAccountId != &lt;span class="hljs-built_in"&gt;null&lt;/span&gt; ? dataService.GetAccount(transaction.TargetAccountId)
: &lt;span class="hljs-built_in"&gt;null&lt;/span&gt;; ++index; &lt;span class="hljs-keyword"&gt;if&lt;/span&gt; (index
% &lt;span class="hljs-number"&gt;100&lt;/span&gt; == &lt;span class="hljs-number"&gt;0&lt;/span&gt;) { Console.WriteLine(index);
} writer.WriteLine($&lt;span class="hljs-string"&gt;"{index},{transaction.Id},{ transaction.At},{transaction.Type},{transaction.Amount},{
transaction.SourceAccountId},{sourceAccount?.Name},{ transaction.TargetAccountId},{targetAccount?.Name}"&lt;/span&gt;);
} } &lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;
This cycle queries transactions, along with two more small queries to get source and
target accounts for each transaction. Results are printed into a report.
&lt;/p&gt;
&lt;p&gt;
If we assume query latency just 1 millisecond, and try to run such code for 100K transactions
we easily come to 200+ seconds of execution. 
&lt;/p&gt;
&lt;p&gt;
Reality turns to be much worse. Program spends most of its lifecycle waiting for database
results, and iterations don&amp;#39;t advance until all work of previous iterations is
complete.
&lt;/p&gt;
&lt;p&gt;
We could do better even without trying to rewrite all code! Let&amp;#39;s articulate our
goals:
&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
To make code fast.&lt;/li&gt;
&lt;li&gt;
To leave code recognizable.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;
The idea is to form two processing pipelines:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
(a) one that processes data in parallel out of order;&lt;/li&gt;
&lt;li&gt;
(b) other that processes data serially, in original order;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
Each pipeline may post sub-tasks to the other, so (a) runs its tasks in parallel unordered,
while (b) runs its tasks as if everything was running serially.
&lt;/p&gt;
&lt;p&gt;
So, parallel plan would be like this:
&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
Queue parallel sub-tasks (a) for each transaction.&lt;/li&gt;
&lt;li&gt;
Parallel sub-task in (a) reads source and target accounts, and queues serial sub-task
(b) passing transaction and accounts.&lt;/li&gt;
&lt;li&gt;
Serial sub-task (b) increments index, and writes report record.&lt;/li&gt;
&lt;li&gt;
Wait for all tasks to complete.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;
To reduce burden of task piplelines we use &lt;a href="https://learn.microsoft.com/en-us/dotnet/standard/parallel-programming/dataflow-task-parallel-library"&gt;Dataflow
(Task Parallel Library)&lt;/a&gt;, and encapsulate everything in a small wrapper.
&lt;/p&gt;
&lt;p&gt;
Consider refactored &lt;a href="https://github.com/nesterovsky-bros/parallel-refactoring/tree/master/Services/ParallelProcessor.cs#L14-L48"&gt;code&lt;/a&gt;:
&lt;/p&gt;
&lt;pre&gt;&lt;code class="lang-C#"&gt; &lt;span class="hljs-keyword"&gt;public&lt;/span&gt; &lt;span class="hljs-literal"&gt;void&lt;/span&gt; CreateReport(StringWriter
writer) { using &lt;span class="hljs-built_in"&gt;var&lt;/span&gt; parallel = &lt;span class="hljs-literal"&gt;new&lt;/span&gt; Parallel(options.Value.Parallelism); &lt;span class="hljs-comment"&gt;//
⬅️ 1&lt;/span&gt; &lt;span class="hljs-built_in"&gt;var&lt;/span&gt; index = &lt;span class="hljs-number"&gt;0&lt;/span&gt;;
parallel.ForEachAsync( &lt;span class="hljs-comment"&gt;// ⬅️ 2&lt;/span&gt; dataService. GetTransactions().
OrderBy(item =&amp;gt; (item.At, item.SourceAccountId)), transaction =&amp;gt; &lt;span class="hljs-comment"&gt;//
⬅️ 3&lt;/span&gt; { &lt;span class="hljs-built_in"&gt;var&lt;/span&gt; sourceAccount = dataService.GetAccount(transaction.SourceAccountId); &lt;span class="hljs-built_in"&gt;var&lt;/span&gt; targetAccount
= transaction.TargetAccountId != &lt;span class="hljs-built_in"&gt;null&lt;/span&gt; ? dataService.GetAccount(transaction.TargetAccountId)
: &lt;span class="hljs-built_in"&gt;null&lt;/span&gt;; parallel.PostSync( &lt;span class="hljs-comment"&gt;//
⬅️ 4&lt;/span&gt; (transaction, sourceAccount, targetAccount), &lt;span class="hljs-comment"&gt;//
⬅️ 5&lt;/span&gt; &lt;span class="hljs-built_in"&gt;data&lt;/span&gt; =&amp;gt; { &lt;span class="hljs-built_in"&gt;var&lt;/span&gt; (transaction,
sourceAccount, targetAccount) = &lt;span class="hljs-built_in"&gt;data&lt;/span&gt;; &lt;span class="hljs-comment"&gt;//
⬅️ 6&lt;/span&gt; ++index; &lt;span class="hljs-keyword"&gt;if&lt;/span&gt; (index % &lt;span class="hljs-number"&gt;100&lt;/span&gt; == &lt;span class="hljs-number"&gt;0&lt;/span&gt;)
{ Console.WriteLine(index); } writer.WriteLine($&lt;span class="hljs-string"&gt;"{index},{transaction.Id},{
transaction.At},{transaction.Type},{transaction.Amount},{ transaction.SourceAccountId},{sourceAccount?.Name},{
transaction.TargetAccountId},{targetAccount?.Name}"&lt;/span&gt;); }); }); } &lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;
Consider ⬅️ points:
&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
We create &lt;code&gt;Parallel&lt;/code&gt; utility class passing degree of parallelism requested.&lt;/li&gt;
&lt;li&gt;
We iterate transactions using &lt;code&gt;parallel.ForEachAsync()&lt;/code&gt; that queues parallel
sub-tasks for each transaction, and then waits until all tasks are complete.&lt;/li&gt;
&lt;li&gt;
Each parallel sub-task recieves a transaction. It may be called from a different thread.&lt;/li&gt;
&lt;li&gt;
Having recieved required accounts we queue a sub-task for synchronous execution using &lt;code&gt;parallel.PostSync()&lt;/code&gt;,
and&lt;/li&gt;
&lt;li&gt;
Pass there data collected in parallel sub-task: transaction and accounts.&lt;/li&gt;
&lt;li&gt;
We deconstruct data passed into variables, and then proceed with serial logic.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;
What we achieve with this refactoring:
&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
Top level query that brings transactions is done and iterated serially.&lt;/li&gt;
&lt;li&gt;
But each iteration body is run in parallel. By default we set it up to allow up to
100 parallel executions. All those parallel sub-task do not wait on each other so
their waitings do not add up.&lt;/li&gt;
&lt;li&gt;
Sync sub-tasks are queued and executed in order of their serial appearance, so increments
and report records are not a subject of race conditions, nor a subject of reordering
of output records.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;
We think that such refactored code is still recognizible.
&lt;/p&gt;
&lt;p&gt;
As for performance this is what log shows:
&lt;/p&gt;
&lt;pre&gt;&lt;code class="lang-log"&gt;&lt;span class="hljs-selector-tag"&gt;Serial&lt;/span&gt; &lt;span class="hljs-selector-tag"&gt;test&lt;/span&gt; 100
... &lt;span class="hljs-selector-tag"&gt;Execution&lt;/span&gt; &lt;span class="hljs-selector-tag"&gt;time&lt;/span&gt;:
00&lt;span class="hljs-selector-pseudo"&gt;:01&lt;/span&gt;&lt;span class="hljs-selector-pseudo"&gt;:33.8152540&lt;/span&gt; &lt;span class="hljs-selector-tag"&gt;Parallel&lt;/span&gt; &lt;span class="hljs-selector-tag"&gt;test&lt;/span&gt; 100
... &lt;span class="hljs-selector-tag"&gt;Execution&lt;/span&gt; &lt;span class="hljs-selector-tag"&gt;time&lt;/span&gt;:
00&lt;span class="hljs-selector-pseudo"&gt;:00&lt;/span&gt;&lt;span class="hljs-selector-pseudo"&gt;:05.8705468&lt;/span&gt; &lt;/code&gt;&lt;/pre&gt;
&lt;h4&gt;Reference
&lt;/h4&gt;
&lt;p&gt;
Please take a look at project to understand implementation details, and in particular &lt;a href="https://github.com/nesterovsky-bros/parallel-refactoring/tree/master/Services/Parallel.cs"&gt;&lt;code&gt;Parallel&lt;/code&gt;&lt;/a&gt; class
implementing API to post parallel and serial tasks, run cycles and some more.
&lt;/p&gt;
&lt;p&gt;
Please continue reading on &lt;a href="https://github.com/nesterovsky-bros/parallel-refactoring/tree/master?tab=readme-ov-file#parallel-refactoring"&gt;GitHub&lt;/a&gt;.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=371a8329-d392-4d20-bcbc-db9503816f26" /&gt;</description>
      <comments>http://www.nesterovsky-bros.com/weblog/CommentView,guid,371a8329-d392-4d20-bcbc-db9503816f26.aspx</comments>
      <category>.NET</category>
      <category>Thinking aloud</category>
      <category>Tips and tricks</category>
    </item>
    <item>
      <trackback:ping>http://www.nesterovsky-bros.com/weblog/Trackback.aspx?guid=0977bf46-abc6-41fe-9767-de673ef5de8b</trackback:ping>
      <pingback:server>http://www.nesterovsky-bros.com/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,0977bf46-abc6-41fe-9767-de673ef5de8b.aspx</pingback:target>
      <dc:creator>Vladimir Nesterovsky</dc:creator>
      <georss:point>0 0</georss:point>
      <wfw:commentRss>http://www.nesterovsky-bros.com/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=0977bf46-abc6-41fe-9767-de673ef5de8b</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
As we wrote some time ago, we started to use AI and ML APIs in our applications, but
this time we've tried to use Bing chat as a tool.
</p>
        <p>
The initial task was to collect sequences of integer numbers and return a list of
pairs integers where the first number is a range's start and the second one is a count
of values in the range. For example, for sequence 1, 2, 3, 5, 8, 9 we'd like to get
the following results: 1, 3 5, 1 8, 2 
</p>
        <p>
We both started to solve this issue. My brother started to play with SSMS using his
deep knowledges in SQL and analytic functions, whereas me started to play with Bing
chat. Looking ahead, I can state that we both solved the issue using almost the same
SQL statement almost in the same time.
</p>
        <p>
Here are my prompts and Bing's answers:
</p>
        <dl>
          <dt style="font-weight: bold;">Prompt:</dt>
          <dd>
Act as database analyst and software engineer. Given the table (T) with a numeric
field (N), which values are orderd ranges of integers. In a range each next value
is greater than previous one on 1. When value differs from the previous one more than
on 1 then in belongs to another range. Generate select statement that returns rows
with two fields. The first field (R) is a number from which a range starts and the
second field (C) is count elements of that range: 
</dd>
          <dt style="font-weight: bold;">Answer:</dt>
          <dd style="white-space: normal;">
Sure, I can help with that. Here's a SQL query that should do the trick. This query
uses a self-join to identify the start of each range, and then groups by the start
of the range to count the number of elements. <code style="white-space: pre; margin: 1em; font-family: monospace;"> ```sql
SELECT start_of_range AS R, COUNT(*) AS C FROM ( SELECT N, N - ROW_NUMBER() OVER (ORDER
BY N) AS start_of_range FROM T ) subquery GROUP BY start_of_range ORDER BY start_of_range;
``` </code> In this query, `start_of_range` is calculated as the difference between
the current value of `N` and its row number (when ordered by `N`). This difference
will be the same for all `N` in the same range. Then we group by `start_of_range`
to get the count of elements in each range. The outer query selects the start of each
range (`R`) and the count of elements in that range (`C`). 
</dd>
          <dt style="padding: 1em; font-weight: 400;"> Me, scratching the head, hmmm... </dt>
          <dt style="font-weight: bold;"> Question: </dt>
          <dd style="white-space: pre;">
This is a bit incorrect SQL select. For example for values 1, 2, 3, 5, 8, 9 I'd like
to get the following results: 1, 3 5, 1 8, 2 What a SQL select shall I use to get
such results? 
</dd>
          <dt style="font-weight: bold;">Answer:</dt>
          <dd>
I apologize for the confusion earlier. You're right, the previous query doesn't handle
the scenario you've described correctly. Here's a corrected SQL query that should
give you the desired output. This query uses a window function to compare each row
with the previous one and identify the start of a new range. Then it groups by the
start of the range to count the elements. <code style="white-space: pre;font-family: monospace;"> ```sql
WITH ranges AS ( SELECT N, CASE WHEN N - LAG(N, 1, N) OVER (ORDER BY N) &gt; 1 THEN 1
ELSE 0 END AS is_start_of_range FROM T ), range_groups AS ( SELECT N, SUM(is_start_of_range)
OVER (ORDER BY N) AS range_group FROM ranges ) SELECT MIN(N) AS R, COUNT(*) AS C FROM
range_groups GROUP BY range_group ORDER BY R; ``` </code> In this query, `is_start_of_range`
is a flag that indicates the start of a new range (when the difference between the
current and previous `N` is more than 1). `range_group` is a running total of `is_start_of_range`
that serves as a unique identifier for each range. The outer query then groups by
`range_group` to get the start (`R`) and count (`C`) of each range. I hope this helps!
Let me know if you have any other questions. 
</dd>
        </dl>
        <p>
That answer more satisfied me, and I've checked the following example:
</p>
        <code style="white-space: pre; font-family: monospace;"> with T as ( select 10 N union
all select 11 N union all select 30 N union all select 31 N union all select 32 N
union all select 50 N union all select 80 N union all select 81 N union all select
82 N union all select 83 N union all select 90 N ), ranges AS ( SELECT N, CASE WHEN
N - LAG(N, 1, N) OVER (ORDER BY N) &gt; 1 THEN 1 ELSE 0 END AS is_start_of_range FROM
T ), range_groups AS ( SELECT N, SUM(is_start_of_range) OVER (ORDER BY N) AS range_group
FROM ranges ) SELECT MIN(N) AS R, COUNT(*) AS C FROM range_groups GROUP BY range_group
ORDER BY R; </code>
        <p>
The result was:
</p>
        <code style="white-space: pre; font-family: monospace;"> R C ------------ 10 2 30
3 50 1 80 4 90 1 </code>
        <p>
          <b>Conclusion:</b>
          <br />
Nowdays, using AI as a tool, you may improve your performance to the expert level
and, may be, study something new... 
</p>
        <p>
          <b>P.S.</b> Don't fool youself that AI can replace a developer (see the first answer
of the chat), but together they can be much stornger than separatelly. 
</p>
        <p>
          <b>P.P.S.</b> Another interesting solution gave us our colleague. She used an additional
field to avoid using analytics function, and she reached the same result: 
</p>
        <code style="white-space: pre; font-family: monospace;"> with T as ( select 10 ID,
1 N union all select 11 ID, 1 N union all select 30 ID, 1 N union all select 31 ID,
1 N union all select 32 ID, 1 N union all select 50 ID, 1 N union all select 80 ID,
1 N union all select 81 ID, 1 N union all select 82 ID, 1 N union all select 83 ID,
1 N union all select 90 ID, 1 N ), Groups AS ( SELECT ID, N, ROW_NUMBER() OVER (ORDER
BY ID) - ID AS GroupNumber FROM T ) SELECT MIN(ID) AS R, SUM(N) AS C FROM Groups GROUP
BY GroupNumber ORDER BY StartID; </code>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=0977bf46-abc6-41fe-9767-de673ef5de8b" />
      </body>
      <title>Using Bing chat as a tool.</title>
      <guid isPermaLink="false">http://www.nesterovsky-bros.com/weblog/PermaLink,guid,0977bf46-abc6-41fe-9767-de673ef5de8b.aspx</guid>
      <link>http://www.nesterovsky-bros.com/weblog/2024/01/01/UsingBingChatAsATool.aspx</link>
      <pubDate>Mon, 01 Jan 2024 14:02:01 GMT</pubDate>
      <description>    &lt;p&gt;
As we wrote some time ago, we started to use AI and ML APIs in our applications, but
this time we've tried to use Bing chat as a tool.
&lt;/p&gt;
&lt;p&gt;
The initial task was to collect sequences of integer numbers and return a list of
pairs integers where the first number is a range's start and the second one is a count
of values in the range. For example, for sequence 1, 2, 3, 5, 8, 9 we'd like to get
the following results: 1, 3 5, 1 8, 2 
&lt;/p&gt;
&lt;p&gt;
We both started to solve this issue. My brother started to play with SSMS using his
deep knowledges in SQL and analytic functions, whereas me started to play with Bing
chat. Looking ahead, I can state that we both solved the issue using almost the same
SQL statement almost in the same time.
&lt;/p&gt;
&lt;p&gt;
Here are my prompts and Bing's answers:
&lt;/p&gt;
&lt;dl&gt;
&lt;dt style="font-weight: bold;"&gt;Prompt:&lt;/dt&gt; 
&lt;dd&gt;
Act as database analyst and software engineer. Given the table (T) with a numeric
field (N), which values are orderd ranges of integers. In a range each next value
is greater than previous one on 1. When value differs from the previous one more than
on 1 then in belongs to another range. Generate select statement that returns rows
with two fields. The first field (R) is a number from which a range starts and the
second field (C) is count elements of that range: 
&lt;/dd&gt;
&lt;dt style="font-weight: bold;"&gt;Answer:&lt;/dt&gt; 
&lt;dd style="white-space: normal;"&gt;
Sure, I can help with that. Here's a SQL query that should do the trick. This query
uses a self-join to identify the start of each range, and then groups by the start
of the range to count the number of elements. &lt;code style="white-space: pre; margin: 1em; font-family: monospace;"&gt; ```sql
SELECT start_of_range AS R, COUNT(*) AS C FROM ( SELECT N, N - ROW_NUMBER() OVER (ORDER
BY N) AS start_of_range FROM T ) subquery GROUP BY start_of_range ORDER BY start_of_range;
``` &lt;/code&gt; In this query, `start_of_range` is calculated as the difference between
the current value of `N` and its row number (when ordered by `N`). This difference
will be the same for all `N` in the same range. Then we group by `start_of_range`
to get the count of elements in each range. The outer query selects the start of each
range (`R`) and the count of elements in that range (`C`). 
&lt;/dd&gt;
&lt;dt style="padding: 1em; font-weight: 400;"&gt; Me, scratching the head, hmmm... &lt;/dt&gt; &lt;dt style="font-weight: bold;"&gt; Question: &lt;/dt&gt; 
&lt;dd style="white-space: pre;"&gt;
This is a bit incorrect SQL select. For example for values 1, 2, 3, 5, 8, 9 I'd like
to get the following results: 1, 3 5, 1 8, 2 What a SQL select shall I use to get
such results? 
&lt;/dd&gt;
&lt;dt style="font-weight: bold;"&gt;Answer:&lt;/dt&gt; 
&lt;dd&gt;
I apologize for the confusion earlier. You're right, the previous query doesn't handle
the scenario you've described correctly. Here's a corrected SQL query that should
give you the desired output. This query uses a window function to compare each row
with the previous one and identify the start of a new range. Then it groups by the
start of the range to count the elements. &lt;code style="white-space: pre;font-family: monospace;"&gt; ```sql
WITH ranges AS ( SELECT N, CASE WHEN N - LAG(N, 1, N) OVER (ORDER BY N) &gt; 1 THEN 1
ELSE 0 END AS is_start_of_range FROM T ), range_groups AS ( SELECT N, SUM(is_start_of_range)
OVER (ORDER BY N) AS range_group FROM ranges ) SELECT MIN(N) AS R, COUNT(*) AS C FROM
range_groups GROUP BY range_group ORDER BY R; ``` &lt;/code&gt; In this query, `is_start_of_range`
is a flag that indicates the start of a new range (when the difference between the
current and previous `N` is more than 1). `range_group` is a running total of `is_start_of_range`
that serves as a unique identifier for each range. The outer query then groups by
`range_group` to get the start (`R`) and count (`C`) of each range. I hope this helps!
Let me know if you have any other questions. 
&lt;/dd&gt;
&lt;/dl&gt;
&lt;p&gt;
That answer more satisfied me, and I've checked the following example:
&lt;/p&gt;
&lt;code style="white-space: pre; font-family: monospace;"&gt; with T as ( select 10 N union
all select 11 N union all select 30 N union all select 31 N union all select 32 N
union all select 50 N union all select 80 N union all select 81 N union all select
82 N union all select 83 N union all select 90 N ), ranges AS ( SELECT N, CASE WHEN
N - LAG(N, 1, N) OVER (ORDER BY N) &gt; 1 THEN 1 ELSE 0 END AS is_start_of_range FROM
T ), range_groups AS ( SELECT N, SUM(is_start_of_range) OVER (ORDER BY N) AS range_group
FROM ranges ) SELECT MIN(N) AS R, COUNT(*) AS C FROM range_groups GROUP BY range_group
ORDER BY R; &lt;/code&gt; 
&lt;p&gt;
The result was:
&lt;/p&gt;
&lt;code style="white-space: pre; font-family: monospace;"&gt; R C ------------ 10 2 30
3 50 1 80 4 90 1 &lt;/code&gt; 
&lt;p&gt;
&lt;b&gt;Conclusion:&lt;/b&gt;
&lt;br /&gt;
Nowdays, using AI as a tool, you may improve your performance to the expert level
and, may be, study something new... 
&lt;/p&gt;
&lt;p&gt;
&lt;b&gt;P.S.&lt;/b&gt; Don't fool youself that AI can replace a developer (see the first answer
of the chat), but together they can be much stornger than separatelly. 
&lt;/p&gt;
&lt;p&gt;
&lt;b&gt;P.P.S.&lt;/b&gt; Another interesting solution gave us our colleague. She used an additional
field to avoid using analytics function, and she reached the same result: 
&lt;/p&gt;
&lt;code style="white-space: pre; font-family: monospace;"&gt; with T as ( select 10 ID,
1 N union all select 11 ID, 1 N union all select 30 ID, 1 N union all select 31 ID,
1 N union all select 32 ID, 1 N union all select 50 ID, 1 N union all select 80 ID,
1 N union all select 81 ID, 1 N union all select 82 ID, 1 N union all select 83 ID,
1 N union all select 90 ID, 1 N ), Groups AS ( SELECT ID, N, ROW_NUMBER() OVER (ORDER
BY ID) - ID AS GroupNumber FROM T ) SELECT MIN(ID) AS R, SUM(N) AS C FROM Groups GROUP
BY GroupNumber ORDER BY StartID; &lt;/code&gt;&lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=0977bf46-abc6-41fe-9767-de673ef5de8b" /&gt;</description>
      <comments>http://www.nesterovsky-bros.com/weblog/CommentView,guid,0977bf46-abc6-41fe-9767-de673ef5de8b.aspx</comments>
      <category>AI</category>
      <category>SQL Server puzzle</category>
      <category>Thinking aloud</category>
      <category>Tips and tricks</category>
    </item>
    <item>
      <trackback:ping>http://www.nesterovsky-bros.com/weblog/Trackback.aspx?guid=591417c2-7649-4f5a-9355-0bd240853bd5</trackback:ping>
      <pingback:server>http://www.nesterovsky-bros.com/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,591417c2-7649-4f5a-9355-0bd240853bd5.aspx</pingback:target>
      <dc:creator>Vladimir Nesterovsky</dc:creator>
      <georss:point>0 0</georss:point>
      <wfw:comment>http://www.nesterovsky-bros.com/weblog/CommentView,guid,591417c2-7649-4f5a-9355-0bd240853bd5.aspx</wfw:comment>
      <wfw:commentRss>http://www.nesterovsky-bros.com/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=591417c2-7649-4f5a-9355-0bd240853bd5</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Many years ago we implemented <a href="/weblog/2015/12/16/AkinatorLikeEngine.aspx">Akinator
like engine</a> purely within SQL Server.
</p>
        <p>
Today we use exactly the same technique to implement vector database.
</p>
        <p>
Please see our GitHub repo: <a href="https://github.com/nesterovsky-bros/vector-database/tree/main">vector-database</a>.
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=591417c2-7649-4f5a-9355-0bd240853bd5" />
      </body>
      <title>Vector database</title>
      <guid isPermaLink="false">http://www.nesterovsky-bros.com/weblog/PermaLink,guid,591417c2-7649-4f5a-9355-0bd240853bd5.aspx</guid>
      <link>http://www.nesterovsky-bros.com/weblog/2023/06/22/VectorDatabase.aspx</link>
      <pubDate>Thu, 22 Jun 2023 22:01:45 GMT</pubDate>
      <description>&lt;p&gt;
Many years ago we implemented &lt;a href="/weblog/2015/12/16/AkinatorLikeEngine.aspx"&gt;Akinator
like engine&lt;/a&gt; purely within SQL Server.
&lt;/p&gt;
&lt;p&gt;
Today we use exactly the same technique to implement vector database.
&lt;/p&gt;
&lt;p&gt;
Please see our GitHub repo: &lt;a href="https://github.com/nesterovsky-bros/vector-database/tree/main"&gt;vector-database&lt;/a&gt;.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=591417c2-7649-4f5a-9355-0bd240853bd5" /&gt;</description>
      <comments>http://www.nesterovsky-bros.com/weblog/CommentView,guid,591417c2-7649-4f5a-9355-0bd240853bd5.aspx</comments>
      <category>Announce</category>
      <category>SQL Server puzzle</category>
      <category>Thinking aloud</category>
    </item>
    <item>
      <trackback:ping>http://www.nesterovsky-bros.com/weblog/Trackback.aspx?guid=8f1b7b65-e15e-459f-82bb-0f50058805cd</trackback:ping>
      <pingback:server>http://www.nesterovsky-bros.com/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,8f1b7b65-e15e-459f-82bb-0f50058805cd.aspx</pingback:target>
      <dc:creator>Arthur Nesterovsky</dc:creator>
      <georss:point>0 0</georss:point>
      <wfw:commentRss>http://www.nesterovsky-bros.com/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=8f1b7b65-e15e-459f-82bb-0f50058805cd</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Last few days we play with OpenAI API and out of pure interest have asked about few
slogans for our team. As an input we fed info from "About us" page. And as one of
the first slogans we've gotten the following slogan that catgh our eyes: 
</p>
        <h3 style="padding-left: 3em;">
          <i>Excellence Through Experience: Nesterovsky Bros.</i>
        </h3>
        <p>
ChatGPT is not a bad copywriter at all... 
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=8f1b7b65-e15e-459f-82bb-0f50058805cd" />
      </body>
      <title>ChatGPT</title>
      <guid isPermaLink="false">http://www.nesterovsky-bros.com/weblog/PermaLink,guid,8f1b7b65-e15e-459f-82bb-0f50058805cd.aspx</guid>
      <link>http://www.nesterovsky-bros.com/weblog/2023/03/23/ChatGPT.aspx</link>
      <pubDate>Thu, 23 Mar 2023 11:30:03 GMT</pubDate>
      <description>&lt;p&gt;
Last few days we play with OpenAI API and out of pure interest have asked about few
slogans for our team. As an input we fed info from "About us" page. And as one of
the first slogans we've gotten the following slogan that catgh our eyes: 
&lt;/p&gt;
&lt;h3 style="padding-left: 3em;"&gt;&lt;i&gt;Excellence Through Experience: Nesterovsky Bros.&lt;/i&gt;
&lt;/h3&gt;
&lt;p&gt;
ChatGPT is not a bad copywriter at all... 
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=8f1b7b65-e15e-459f-82bb-0f50058805cd" /&gt;</description>
      <comments>http://www.nesterovsky-bros.com/weblog/CommentView,guid,8f1b7b65-e15e-459f-82bb-0f50058805cd.aspx</comments>
      <category>Thinking aloud</category>
    </item>
    <item>
      <trackback:ping>http://www.nesterovsky-bros.com/weblog/Trackback.aspx?guid=486afbcd-3e16-4240-97c4-3c985d6c6754</trackback:ping>
      <pingback:server>http://www.nesterovsky-bros.com/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,486afbcd-3e16-4240-97c4-3c985d6c6754.aspx</pingback:target>
      <dc:creator>Arthur Nesterovsky</dc:creator>
      <georss:point>0 0</georss:point>
      <wfw:commentRss>http://www.nesterovsky-bros.com/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=486afbcd-3e16-4240-97c4-3c985d6c6754</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
While doing a migration of some big xslt 3 project into plain C# we run into a case
that was not obvious to resolve.
</p>
        <p>
Documents we process can be from a tiny to a moderate size. Being stored in xml they
might take from virtually zero to, say, 10-20 MB.
</p>
        <p>
In C# we may rewrite Xslt code virtually in one-to-one manner using standard features
like XDocument, LINQ, regular classes, built-in collections, and so on. Clearly C#
has a reacher repertoire, so task is easily solved unless you run into multiple opportunities
to solve it.
</p>
        <p>
The simplest solution is to use XDocument API to represent data at runtime, and use
LINQ to query it. All features like xslt keys, templates, functions, xpath sequences,
arrays and maps and primitive types are natuarally mapped into C# language and its
APIs.
</p>
        <p>
Taking several xslt transformations we could see that xslt to C# rewrite is rather
straightforward and produces recognizable functional programs that have close C# source
code size to their original Xslt. As a bonus C# lets you write code in asynchronous
way, so C# wins in a runtime scalability, and in a design-time support.
</p>
        <p>
But can you do it better in C#, especially when some data has well defined xml schemas?
</p>
        <p>
The natural step, in our opinion, would be to produce C# plain object model from xml
schema and use it for runtime processing. Fortunately .NET has xml serialization attributes
and tools to produce classes from xml schemas. With small efforts we have created
a relevant class hierarchy for a rather big xml schema. XmlSerializer is used to convert
object model to and from xml through XmlReader and XmlWriter. So, we get typed replacement
of generic XDocument that still supports the same LINQ API over collections of objects,
and takes less memory at runtime.
</p>
        <p>
The next step would be to commit a simple test like: 
</p>
        <ul>
          <li>
            <p>
read object model;
</p>
          </li>
          <li>
            <p>
transform it;
</p>
          </li>
          <li>
            <p>
write it back.
</p>
          </li>
        </ul>
        <p>
We have created such tests both for XDocument and for object model cases, and compared
results from different perspectives.
</p>
        <p>
Both solution produce very similar code, which is also similar to original xslt both
in style and size.
</p>
        <p>
Object model has static typing, which is much better to support.
</p>
        <p>
But the most unexpected outcome is that object model was up to 20% slower due to serialization
and deserialization even with pregenerated xmlserializer assemblies. Difference of
transformation performance and memory consumption was so unnoticable that it can be
neglected. These results were confirmed with multiple tests, with multiple cycles
including heating up cycles.
</p>
        <p>
Here we run into a case where static typing harms more than helps. Because of the
nature of our processing pipeline, which is offline batch, this difference can be
mapped into 10th of minutes or even more.
</p>
        <p>
Thus in this particular case we decided to stay with runtime typing as a more performant
way of processing in C#. 
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=486afbcd-3e16-4240-97c4-3c985d6c6754" />
      </body>
      <title>XDocument vs Plain Object Model</title>
      <guid isPermaLink="false">http://www.nesterovsky-bros.com/weblog/PermaLink,guid,486afbcd-3e16-4240-97c4-3c985d6c6754.aspx</guid>
      <link>http://www.nesterovsky-bros.com/weblog/2023/01/08/XDocumentVsPlainObjectModel.aspx</link>
      <pubDate>Sun, 08 Jan 2023 13:28:14 GMT</pubDate>
      <description>  &lt;p&gt;
While doing a migration of some big xslt 3 project into plain C# we run into a case
that was not obvious to resolve.
&lt;/p&gt;
&lt;p&gt;
Documents we process can be from a tiny to a moderate size. Being stored in xml they
might take from virtually zero to, say, 10-20 MB.
&lt;/p&gt;
&lt;p&gt;
In C# we may rewrite Xslt code virtually in one-to-one manner using standard features
like XDocument, LINQ, regular classes, built-in collections, and so on. Clearly C#
has a reacher repertoire, so task is easily solved unless you run into multiple opportunities
to solve it.
&lt;/p&gt;
&lt;p&gt;
The simplest solution is to use XDocument API to represent data at runtime, and use
LINQ to query it. All features like xslt keys, templates, functions, xpath sequences,
arrays and maps and primitive types are natuarally mapped into C# language and its
APIs.
&lt;/p&gt;
&lt;p&gt;
Taking several xslt transformations we could see that xslt to C# rewrite is rather
straightforward and produces recognizable functional programs that have close C# source
code size to their original Xslt. As a bonus C# lets you write code in asynchronous
way, so C# wins in a runtime scalability, and in a design-time support.
&lt;/p&gt;
&lt;p&gt;
But can you do it better in C#, especially when some data has well defined xml schemas?
&lt;/p&gt;
&lt;p&gt;
The natural step, in our opinion, would be to produce C# plain object model from xml
schema and use it for runtime processing. Fortunately .NET has xml serialization attributes
and tools to produce classes from xml schemas. With small efforts we have created
a relevant class hierarchy for a rather big xml schema. XmlSerializer is used to convert
object model to and from xml through XmlReader and XmlWriter. So, we get typed replacement
of generic XDocument that still supports the same LINQ API over collections of objects,
and takes less memory at runtime.
&lt;/p&gt;
&lt;p&gt;
The next step would be to commit a simple test like: 
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;
read object model;
&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;
transform it;
&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;
write it back.
&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
We have created such tests both for XDocument and for object model cases, and compared
results from different perspectives.
&lt;/p&gt;
&lt;p&gt;
Both solution produce very similar code, which is also similar to original xslt both
in style and size.
&lt;/p&gt;
&lt;p&gt;
Object model has static typing, which is much better to support.
&lt;/p&gt;
&lt;p&gt;
But the most unexpected outcome is that object model was up to 20% slower due to serialization
and deserialization even with pregenerated xmlserializer assemblies. Difference of
transformation performance and memory consumption was so unnoticable that it can be
neglected. These results were confirmed with multiple tests, with multiple cycles
including heating up cycles.
&lt;/p&gt;
&lt;p&gt;
Here we run into a case where static typing harms more than helps. Because of the
nature of our processing pipeline, which is offline batch, this difference can be
mapped into 10th of minutes or even more.
&lt;/p&gt;
&lt;p&gt;
Thus in this particular case we decided to stay with runtime typing as a more performant
way of processing in C#. 
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=486afbcd-3e16-4240-97c4-3c985d6c6754" /&gt;</description>
      <comments>http://www.nesterovsky-bros.com/weblog/CommentView,guid,486afbcd-3e16-4240-97c4-3c985d6c6754.aspx</comments>
      <category>.NET</category>
      <category>xslt</category>
    </item>
    <item>
      <trackback:ping>http://www.nesterovsky-bros.com/weblog/Trackback.aspx?guid=fdbaf9f5-827b-4a1f-9e52-4ec569801784</trackback:ping>
      <pingback:server>http://www.nesterovsky-bros.com/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,fdbaf9f5-827b-4a1f-9e52-4ec569801784.aspx</pingback:target>
      <dc:creator>Vladimir Nesterovsky</dc:creator>
      <georss:point>0 0</georss:point>
      <wfw:commentRss>http://www.nesterovsky-bros.com/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=fdbaf9f5-827b-4a1f-9e52-4ec569801784</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Xslt is oftentimes thought as a tool to take input xml, and run transformation to
get html or some xml on output. Our use case is more complex, and is closer to a data
mining of big data in batch. Our transformation pipelines often take hour or more
to run even with SSD disks and with CPU cores fully loaded with work.
</p>
        <p>
So, we're looking for performance opportunities, and xml vs json might be promising.
</p>
        <p>
Here are our hypotheses:
</p>
        <ul>
          <li>
json is lighter than xml to serialize and deserialize;</li>
          <li>
json stored as map(*), array(*) and other items() are ligher than node() at runtime,
in particular subtree copy is zero cost in json;</li>
          <li>
templates with match patterns are efficiently can be implemented with maps();</li>
          <li>
there is incremental way forward from use of xml to use of json.</li>
        </ul>
        <p>
If it pays off we might be switching xml format to json all over, even though it is
a development effort.
</p>
        <p>
But to proceed we need to commit an experiment to measure processing speed of xml
vs json in xslt.
</p>
        <p>
Now our task is to find an isolated small representative sample to prove or reject
our hypotheses. 
</p>
        <p>
Better to start off with some existing transformation, and change it from use of xml
to json. 
</p>
        <p>
The question is whether there is such a candidate.
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=fdbaf9f5-827b-4a1f-9e52-4ec569801784" />
      </body>
      <title>xml vs json</title>
      <guid isPermaLink="false">http://www.nesterovsky-bros.com/weblog/PermaLink,guid,fdbaf9f5-827b-4a1f-9e52-4ec569801784.aspx</guid>
      <link>http://www.nesterovsky-bros.com/weblog/2022/04/16/xmlVsJson.aspx</link>
      <pubDate>Sat, 16 Apr 2022 19:03:04 GMT</pubDate>
      <description>&lt;p&gt;
Xslt is oftentimes thought as a tool to take input xml, and run transformation to
get html or some xml on output. Our use case is more complex, and is closer to a data
mining of big data in batch. Our transformation pipelines often take hour or more
to run even with SSD disks and with CPU cores fully loaded with work.
&lt;/p&gt;
&lt;p&gt;
So, we&amp;#39;re looking for performance opportunities, and xml vs json might be promising.
&lt;/p&gt;
&lt;p&gt;
Here are our hypotheses:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
json is lighter than xml to serialize and deserialize;&lt;/li&gt;
&lt;li&gt;
json stored as map(*), array(*) and other items() are ligher than node() at runtime,
in particular subtree copy is zero cost in json;&lt;/li&gt;
&lt;li&gt;
templates with match patterns are efficiently can be implemented with maps();&lt;/li&gt;
&lt;li&gt;
there is incremental way forward from use of xml to use of json.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
If it pays off we might be switching xml format to json all over, even though it is
a development effort.
&lt;/p&gt;
&lt;p&gt;
But to proceed we need to commit an experiment to measure processing speed of xml
vs json in xslt.
&lt;/p&gt;
&lt;p&gt;
Now our task is to find an isolated small representative sample to prove or reject
our hypotheses. 
&lt;/p&gt;
&lt;p&gt;
Better to start off with some existing transformation, and change it from use of xml
to json. 
&lt;/p&gt;
&lt;p&gt;
The question is whether there is such a candidate.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=fdbaf9f5-827b-4a1f-9e52-4ec569801784" /&gt;</description>
      <comments>http://www.nesterovsky-bros.com/weblog/CommentView,guid,fdbaf9f5-827b-4a1f-9e52-4ec569801784.aspx</comments>
      <category>Thinking aloud</category>
      <category>xslt</category>
    </item>
    <item>
      <trackback:ping>http://www.nesterovsky-bros.com/weblog/Trackback.aspx?guid=5440bb74-6b87-4ec5-9119-715b3e16b9a7</trackback:ping>
      <pingback:server>http://www.nesterovsky-bros.com/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,5440bb74-6b87-4ec5-9119-715b3e16b9a7.aspx</pingback:target>
      <dc:creator>Vladimir Nesterovsky</dc:creator>
      <georss:point>0 0</georss:point>
      <wfw:commentRss>http://www.nesterovsky-bros.com/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=5440bb74-6b87-4ec5-9119-715b3e16b9a7</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">Couple of days ago, while integrating with
someones C# library, we had to debug it, as something went wrong. The code is big
and obscure but for the integration purposes it's rather simple: you just create
and call a class, that's all. Yet, something just did not work. We had to prove
that it's not our fault, as the other side is uncooperative and would not run
common debug session to resolve the problem. 
<p></p><p>
To simplify the matter as much as possible here is the case: 
</p><blockquote><pre>var input = ...
var x = new X();
var output = x.Execute(input);
</pre></blockquote><p>
You pass correct input, and get correct output. Simple, right? But it did not work!
So, we delved into the foreign code, and this is what we have seen: 
</p><blockquote><pre>class X: Y
{
  public Output Execute(Input input)
  {
    return Perform(input);
  }

  protected override Output Run(Input input)
  { 
    ...

     return output;
  }
}

class Y: Z
{
  ...
}

class Z
{
  protected Output Perform(Input input)
  {
    return Run(Input);
  }
        
  protected virtual Output Run(Input input)
  {
    return null;
  }
}</pre></blockquote><p></p><p>
Do you see, still flow is simple, right? We call <code>X.Execute()</code>, it calls <code>Z.Perform()</code>,
which in turn calls overriden <code>X.Run()</code> that returns the result. 
</p><p>
But to our puzzlement we got <code>null</code> on output, as if <code>Z.Run()</code> was
called! 
</p><p>
We stepped through the code in debugger and confirmed that <code>Z.Perform()</code> calls <code>Z.Run()</code>,
even though "<code>this</code>" instance is of type <code>X</code>. 
</p><p>
How can it be? It's a nonsence! Yet, no overriden method was ever called. 
</p><p>
No matter how much scrunity we applied to sources <code>X</code> and <code>Z</code> it
just did not work. 
</p><p></p><p>
We verified that the signature of <code>X.Run()</code> matches the signature of <code>Z.Run()</code>,
so it overrides the method. 
</p><p>
Then what do we see here? 
</p><p>
And then enlightenment come! Yes, <code>X.Run()</code> overrides the method, but what
method? 
</p><p>
We looked closely at class <code>Y</code>, and bingo, we can see there following: 
</p><blockquote><pre>class Y: Z
{
  ...

  protected virtual Output Run(Input input)
  {
    return null;
  }
      
  ...
}</pre></blockquote><p>
So, <code>X.Run()</code> overrides <code>Y.Run()</code> and not <code>Z.Run()</code>! 
</p><p>
Per .NET <code>Y.Run()</code> and <code>Z.Run()</code> are two independant virtual
methods, where <code>Y.Run()</code> in addition hides <code>Z.Run()</code>. 
</p><p>
IDE even issued a warning that it's better declare <code>Y.Run()</code> as: 
</p><blockquote><pre>protected new virtual Output Run(Input input)
{
  return null;
}</pre></blockquote><p>
So, someones code was plainly wrong: <code>Y.Run()</code> had to use <code><b>override</b></code> rather
than <code><b>virtual</b></code>. 
</p><p>
We won, right? 
</p><p>
Well, it's hard to call it a win. 
</p><p>
We spent a hour looking at someones ugly code just to prove we're still sane. 
</p><p></p><p>
So, what is conclusion of this story? 
</p><p>
We think here it is: 
</p><ul><li>
be cautious while looking at someones code;</li><li>
look at IDE warnings, don't disregard them, and try to resolve all of them in
your code base;</li><li>
try to write simple code.</li></ul><img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=5440bb74-6b87-4ec5-9119-715b3e16b9a7" /></body>
      <title>Bad code</title>
      <guid isPermaLink="false">http://www.nesterovsky-bros.com/weblog/PermaLink,guid,5440bb74-6b87-4ec5-9119-715b3e16b9a7.aspx</guid>
      <link>http://www.nesterovsky-bros.com/weblog/2022/01/15/BadCode.aspx</link>
      <pubDate>Sat, 15 Jan 2022 13:55:08 GMT</pubDate>
      <description>Couple of days ago, while integrating with someones C# library, we had to debug it, as something went wrong.
        The code is big and obscure but for the integration purposes it&amp;#39;s rather simple: you just create and call a class, that&amp;#39;s all.
        Yet, something just did not work. We had to prove that it&amp;#39;s not our fault, as the other side is uncooperative and would not run common debug session to resolve the problem.
    &lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
To simplify the matter as much as possible here is the case: 
&lt;/p&gt;
&lt;blockquote&gt; &lt;pre&gt;var input = ...
var x = new X();
var output = x.Execute(input);
&lt;/pre&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
You pass correct input, and get correct output. Simple, right? But it did not work!
So, we delved into the foreign code, and this is what we have seen: 
&lt;/p&gt;
&lt;blockquote&gt; &lt;pre&gt;class X: Y
{
  public Output Execute(Input input)
  {
    return Perform(input);
  }

  protected override Output Run(Input input)
  { 
    ...

     return output;
  }
}

class Y: Z
{
  ...
}

class Z
{
  protected Output Perform(Input input)
  {
    return Run(Input);
  }
        
  protected virtual Output Run(Input input)
  {
    return null;
  }
}&lt;/pre&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
Do you see, still flow is simple, right? We call &lt;code&gt;X.Execute()&lt;/code&gt;, it calls &lt;code&gt;Z.Perform()&lt;/code&gt;,
which in turn calls overriden &lt;code&gt;X.Run()&lt;/code&gt; that returns the result. 
&lt;/p&gt;
&lt;p&gt;
But to our puzzlement we got &lt;code&gt;null&lt;/code&gt; on output, as if &lt;code&gt;Z.Run()&lt;/code&gt; was
called! 
&lt;/p&gt;
&lt;p&gt;
We stepped through the code in debugger and confirmed that &lt;code&gt;Z.Perform()&lt;/code&gt; calls &lt;code&gt;Z.Run()&lt;/code&gt;,
even though &amp;quot;&lt;code&gt;this&lt;/code&gt;&amp;quot; instance is of type &lt;code&gt;X&lt;/code&gt;. 
&lt;/p&gt;
&lt;p&gt;
How can it be? It&amp;#39;s a nonsence! Yet, no overriden method was ever called. 
&lt;/p&gt;
&lt;p&gt;
No matter how much scrunity we applied to sources &lt;code&gt;X&lt;/code&gt; and &lt;code&gt;Z&lt;/code&gt; it
just did not work. 
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
We verified that the signature of &lt;code&gt;X.Run()&lt;/code&gt; matches the signature of &lt;code&gt;Z.Run()&lt;/code&gt;,
so it overrides the method. 
&lt;/p&gt;
&lt;p&gt;
Then what do we see here? 
&lt;/p&gt;
&lt;p&gt;
And then enlightenment come! Yes, &lt;code&gt;X.Run()&lt;/code&gt; overrides the method, but what
method? 
&lt;/p&gt;
&lt;p&gt;
We looked closely at class &lt;code&gt;Y&lt;/code&gt;, and bingo, we can see there following: 
&lt;/p&gt;
&lt;blockquote&gt; &lt;pre&gt;class Y: Z
{
  ...

  protected virtual Output Run(Input input)
  {
    return null;
  }
      
  ...
}&lt;/pre&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
So, &lt;code&gt;X.Run()&lt;/code&gt; overrides &lt;code&gt;Y.Run()&lt;/code&gt; and not &lt;code&gt;Z.Run()&lt;/code&gt;! 
&lt;/p&gt;
&lt;p&gt;
Per .NET &lt;code&gt;Y.Run()&lt;/code&gt; and &lt;code&gt;Z.Run()&lt;/code&gt; are two independant virtual
methods, where &lt;code&gt;Y.Run()&lt;/code&gt; in addition hides &lt;code&gt;Z.Run()&lt;/code&gt;. 
&lt;/p&gt;
&lt;p&gt;
IDE even issued a warning that it&amp;#39;s better declare &lt;code&gt;Y.Run()&lt;/code&gt; as: 
&lt;/p&gt;
&lt;blockquote&gt; &lt;pre&gt;protected new virtual Output Run(Input input)
{
  return null;
}&lt;/pre&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
So, someones code was plainly wrong: &lt;code&gt;Y.Run()&lt;/code&gt; had to use &lt;code&gt;&lt;b&gt;override&lt;/b&gt;&lt;/code&gt; rather
than &lt;code&gt;&lt;b&gt;virtual&lt;/b&gt;&lt;/code&gt;. 
&lt;/p&gt;
&lt;p&gt;
We won, right? 
&lt;/p&gt;
&lt;p&gt;
Well, it&amp;#39;s hard to call it a win. 
&lt;/p&gt;
&lt;p&gt;
We spent a hour looking at someones ugly code just to prove we&amp;#39;re still sane. 
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
So, what is conclusion of this story? 
&lt;/p&gt;
&lt;p&gt;
We think here it is: 
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
be cautious while looking at someones code;&lt;/li&gt;
&lt;li&gt;
look at IDE warnings, don&amp;#39;t disregard them, and try to resolve all of them in
your code base;&lt;/li&gt;
&lt;li&gt;
try to write simple code.&lt;/li&gt;
&lt;/ul&gt;
&lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=5440bb74-6b87-4ec5-9119-715b3e16b9a7" /&gt;</description>
      <comments>http://www.nesterovsky-bros.com/weblog/CommentView,guid,5440bb74-6b87-4ec5-9119-715b3e16b9a7.aspx</comments>
      <category>.NET</category>
      <category>Thinking aloud</category>
    </item>
    <item>
      <trackback:ping>http://www.nesterovsky-bros.com/weblog/Trackback.aspx?guid=3042e60d-8943-47f0-9595-0d8e9cfb268c</trackback:ping>
      <pingback:server>http://www.nesterovsky-bros.com/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,3042e60d-8943-47f0-9595-0d8e9cfb268c.aspx</pingback:target>
      <dc:creator>Vladimir Nesterovsky</dc:creator>
      <georss:point>0 0</georss:point>
      <wfw:commentRss>http://www.nesterovsky-bros.com/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=3042e60d-8943-47f0-9595-0d8e9cfb268c</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Lately we work great deal of time with <a href="https://en.wikipedia.org/wiki/Cosmos_DB">Azure's
CosmosDB</a>.
</p>
        <p>
This is how it's defined:
</p>
        <blockquote>
          <i>"It is schema-agnostic, horizontally scalable, and generally classified
as a <a href="https://en.wikipedia.org/wiki/NoSQL">NoSQL</a> database."</i>
        </blockquote>
        <p>
This, unconfident in itself, quote below is clarified as:
</p>
        <blockquote>
          <i>"The SQL API lets clients create, update and delete containers and
items. Items can be queried with a read-only, JSON-friendly SQL dialect."</i>
        </blockquote>
        <p>
To be honest this SQL API made us favor CosmosDB.
</p>
        <p>
So, we started a development with CosmosDB as a data storage.
</p>
        <p>
The next development ingredient we learned the hard way is to try to refrain from
clever techniques. 
</p>
        <p>
The lesson we learned is simple: after you finish with a project, provided it's
not a toy, you give it to people who will be supporting it. You should think about
those future developers before you're going to insert some cleverness in you code.
</p>
        <p>
With this common sense we selected <a href="https://en.wikipedia.org/wiki/Entity_Framework">EF
Core</a> as a library that will serve as an interface between C# and the database.
</p>
        <p>
Initialy all went well until we needed to store a list of strings as a document property
and found it's not possible.
</p>
        <p>
Why? - was a naive question.
</p>
        <p>
Answer puzzled us a lot - because string is not an "Entity" (what ever it
means), and EF is about framework of entities.
</p>
        <p>
You could argue with this argument as long as you like, it just does not work. It
is especially bad if you need to store a class that you do not directly control e.g.
structures returned from other services.
</p>
        <p>
Next pothole with EF was when we tried to run an innocent query that joins the data
from document: e.g. document contains items, and you want to query some items from
some documents.
</p>
        <p>
Guess what?
</p>
        <p>
Right, EF Core does not support it.
</p>
        <p>
Why?
</p>
        <p>
Because!
</p>
        <p>
Later we have found that many other constructs and functions that you easily use in
SQL dialect of CosmosDB are not possible or supported in EF Core.
</p>
        <p>
We were very upset with those crutches and came to a conclusion that EF Core harms
more than helps when you work with CosmosDB.
</p>
        <p>
We went on and looked at how you work directly with CosmosDB client, and have found
that it has all features ready:
</p>
        <ul>
          <li>
you may give it SQL and bind parameters;</li>
          <li>
you may convert result items to objects;</li>
          <li>
you may create, delete, update and query data;</li>
        </ul>
        <p>
So, do we need EF Core? 
</p>
        <p>
We answered, no.
</p>
        <p>
This does not mean we reject the value of EF Core but here our conclusion was that
this API layer just complicated things instead making them simpler. It might be that
EF Core for CosmosDB is not mature enough at this time.
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=3042e60d-8943-47f0-9595-0d8e9cfb268c" />
      </body>
      <title>CosmosDB with EF Core</title>
      <guid isPermaLink="false">http://www.nesterovsky-bros.com/weblog/PermaLink,guid,3042e60d-8943-47f0-9595-0d8e9cfb268c.aspx</guid>
      <link>http://www.nesterovsky-bros.com/weblog/2021/10/20/CosmosDBWithEFCore.aspx</link>
      <pubDate>Wed, 20 Oct 2021 16:11:39 GMT</pubDate>
      <description>&lt;p&gt;
Lately we work great deal of time with &lt;a href="https://en.wikipedia.org/wiki/Cosmos_DB"&gt;Azure&amp;#39;s
CosmosDB&lt;/a&gt;.
&lt;/p&gt;
&lt;p&gt;
This is how it&amp;#39;s defined:
&lt;/p&gt;
&lt;blockquote&gt;&lt;i&gt;"It is schema-agnostic, horizontally scalable, and generally classified
as a &lt;a href="https://en.wikipedia.org/wiki/NoSQL"&gt;NoSQL&lt;/a&gt; database."&lt;/i&gt;&lt;/blockquote&gt; 
&lt;p&gt;
This, unconfident in itself, quote below is clarified as:
&lt;/p&gt;
&lt;blockquote&gt;&lt;i&gt;"The SQL API lets clients create, update and delete containers and
items. Items can be queried with a read-only, JSON-friendly SQL dialect."&lt;/i&gt;&lt;/blockquote&gt; 
&lt;p&gt;
To be honest this SQL API made us favor CosmosDB.
&lt;/p&gt;
&lt;p&gt;
So, we started a development with CosmosDB as a data storage.
&lt;/p&gt;
&lt;p&gt;
The next development ingredient we learned the hard way is to try to refrain from
clever techniques. 
&lt;/p&gt;
&lt;p&gt;
The lesson we learned is simple: after you finish with a project, provided it&amp;#39;s
not a toy, you give it to people who will be supporting it. You should think about
those future developers before you&amp;#39;re going to insert some cleverness in you code.
&lt;/p&gt;
&lt;p&gt;
With this common sense we selected &lt;a href="https://en.wikipedia.org/wiki/Entity_Framework"&gt;EF
Core&lt;/a&gt; as a library that will serve as an interface between C# and the database.
&lt;/p&gt;
&lt;p&gt;
Initialy all went well until we needed to store a list of strings as a document property
and found it&amp;#39;s not possible.
&lt;/p&gt;
&lt;p&gt;
Why? - was a naive question.
&lt;/p&gt;
&lt;p&gt;
Answer puzzled us a lot - because string is not an &amp;quot;Entity&amp;quot; (what ever it
means), and EF is about framework of entities.
&lt;/p&gt;
&lt;p&gt;
You could argue with this argument as long as you like, it just does not work. It
is especially bad if you need to store a class that you do not directly control e.g.
structures returned from other services.
&lt;/p&gt;
&lt;p&gt;
Next pothole with EF was when we tried to run an innocent query that joins the data
from document: e.g. document contains items, and you want to query some items from
some documents.
&lt;/p&gt;
&lt;p&gt;
Guess what?
&lt;/p&gt;
&lt;p&gt;
Right, EF Core does not support it.
&lt;/p&gt;
&lt;p&gt;
Why?
&lt;/p&gt;
&lt;p&gt;
Because!
&lt;/p&gt;
&lt;p&gt;
Later we have found that many other constructs and functions that you easily use in
SQL dialect of CosmosDB are not possible or supported in EF Core.
&lt;/p&gt;
&lt;p&gt;
We were very upset with those crutches and came to a conclusion that EF Core harms
more than helps when you work with CosmosDB.
&lt;/p&gt;
&lt;p&gt;
We went on and looked at how you work directly with CosmosDB client, and have found
that it has all features ready:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
you may give it SQL and bind parameters;&lt;/li&gt;
&lt;li&gt;
you may convert result items to objects;&lt;/li&gt;
&lt;li&gt;
you may create, delete, update and query data;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
So, do we need EF Core? 
&lt;/p&gt;
&lt;p&gt;
We answered, no.
&lt;/p&gt;
&lt;p&gt;
This does not mean we reject the value of EF Core but here our conclusion was that
this API layer just complicated things instead making them simpler. It might be that
EF Core for CosmosDB is not mature enough at this time.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=3042e60d-8943-47f0-9595-0d8e9cfb268c" /&gt;</description>
      <comments>http://www.nesterovsky-bros.com/weblog/CommentView,guid,3042e60d-8943-47f0-9595-0d8e9cfb268c.aspx</comments>
      <category>Azure</category>
      <category>Thinking aloud</category>
    </item>
    <item>
      <trackback:ping>http://www.nesterovsky-bros.com/weblog/Trackback.aspx?guid=9121c6f9-e622-4d71-b25b-58763fa5d88e</trackback:ping>
      <pingback:server>http://www.nesterovsky-bros.com/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,9121c6f9-e622-4d71-b25b-58763fa5d88e.aspx</pingback:target>
      <dc:creator>Vladimir Nesterovsky</dc:creator>
      <georss:point>0 0</georss:point>
      <wfw:commentRss>http://www.nesterovsky-bros.com/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=9121c6f9-e622-4d71-b25b-58763fa5d88e</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Recently we have found that <a href="https://docs.microsoft.com/en-us/dotnet/api/system.runtime.serialization.formatters.binary.binaryformatter.serialize?view=net-5.0">BinaryFormatter.Serialize</a> and <a href="https://docs.microsoft.com/en-us/dotnet/api/system.runtime.serialization.formatters.binary.binaryformatter.deserialize?view=net-5.0">BinaryFormatter.Deserialize</a> methods
are marked as obsolete in .NET 5.0, and are declared dangerous:
</p>
        <blockquote>
          <i>The <strong>BinaryFormatter</strong> type is dangerous and is <strong>not</strong> recommended
for data processing. Applications should stop using BinaryFormatter as soon as possible,
even if they believe the data they're processing to be trustworthy. BinaryFormatter
is insecure and can't be made secure.</i>
        </blockquote>
        <p>
See <a href="https://docs.microsoft.com/en-us/dotnet/standard/serialization/binaryformatter-security-guide">BinaryFormatter
security guide</a> for more details.
</p>
        <p>
That guide along with its links go and expand on what problems BinaryFormatter poses.
The schema of dangeous use cases, we have seen so far, is like that:
</p>
        <ul>
          <li>
two different sides communicate to each other;</li>
          <li>
one side supplies input in BinaryFormatter's format;</li>
          <li>
other side reads input using BinaryFormatter and instantiates classes.</li>
        </ul>
        <p>
A threat arises when two sides cannot trust to each other or cannot establish trusted
communication chanel. In these cases malign input can be supplied to a side reading
the data, which might lead to unexpected code execution, deny of service, data exposure
and to other bad consequences.
</p>
        <p>
Arguing like this, today's maintainers of .NET concluded that it's better to tear
down BinaryFormatter and similar APIs out of the framework.
</p>
        <p>
Note that they don't claim BinaryFormatter itself, or Reflection API that it uses,
as a core of the problem. They blame on communication.
</p>
        <p>
Spelling out clearly what are concerns could help to everyone to better understand
how to address it. In the area of security of communication there are a lot of ready
solutions like:
</p>
        <ul>
          <li>
use signature to avoid tampering the data;</li>
          <li>
use encription to avoid spying the data;</li>
          <li>
use access rights to avoid even access to the data;</li>
          <li>
use secure communication channels.</li>
        </ul>
        <p>
We can surely state that without applying these solutions no other serialization format
is reliable and is subject of the same vulnerabilities.
</p>
        <p>
 
</p>
        <p>
After all it looked like an attempt to throw out the baby with the bath water. The
good news is that thankfully to now modular structure of .NET runtime we're able
to access binary serialization library, which are (and will be) available on nugets
repositories. So, it's futile effort to erase this usefull API. 
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=9121c6f9-e622-4d71-b25b-58763fa5d88e" />
      </body>
      <title>Binary serialization in .NET 5.0</title>
      <guid isPermaLink="false">http://www.nesterovsky-bros.com/weblog/PermaLink,guid,9121c6f9-e622-4d71-b25b-58763fa5d88e.aspx</guid>
      <link>http://www.nesterovsky-bros.com/weblog/2021/02/02/BinarySerializationInNET50.aspx</link>
      <pubDate>Tue, 02 Feb 2021 12:39:37 GMT</pubDate>
      <description>&lt;p&gt;
Recently we have found that &lt;a href="https://docs.microsoft.com/en-us/dotnet/api/system.runtime.serialization.formatters.binary.binaryformatter.serialize?view=net-5.0"&gt;BinaryFormatter.Serialize&lt;/a&gt; and &lt;a href="https://docs.microsoft.com/en-us/dotnet/api/system.runtime.serialization.formatters.binary.binaryformatter.deserialize?view=net-5.0"&gt;BinaryFormatter.Deserialize&lt;/a&gt; methods
are marked as obsolete in .NET 5.0, and are declared dangerous:
&lt;/p&gt;
&lt;blockquote&gt;&lt;i&gt;The &lt;strong&gt;BinaryFormatter&lt;/strong&gt; type is dangerous and is &lt;strong&gt;not&lt;/strong&gt; recommended
for data processing. Applications should stop using BinaryFormatter as soon as possible,
even if they believe the data they're processing to be trustworthy. BinaryFormatter
is insecure and can't be made secure.&lt;/i&gt;&lt;/blockquote&gt; 
&lt;p&gt;
See &lt;a href="https://docs.microsoft.com/en-us/dotnet/standard/serialization/binaryformatter-security-guide"&gt;BinaryFormatter
security guide&lt;/a&gt; for more details.
&lt;/p&gt;
&lt;p&gt;
That guide along with its links go and expand on what problems BinaryFormatter poses.
The schema of dangeous use cases, we have seen so far, is like that:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
two different sides communicate to each other;&lt;/li&gt;
&lt;li&gt;
one side supplies input in BinaryFormatter&amp;#39;s format;&lt;/li&gt;
&lt;li&gt;
other side reads input using BinaryFormatter and instantiates classes.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
A threat arises when two sides cannot trust to each other or cannot establish trusted
communication chanel. In these cases malign input can be supplied to a side reading
the data, which might lead to unexpected code execution, deny of service, data exposure
and to other bad consequences.
&lt;/p&gt;
&lt;p&gt;
Arguing like this, today's maintainers of .NET concluded that it's better to tear
down BinaryFormatter and similar APIs out of the framework.
&lt;/p&gt;
&lt;p&gt;
Note that they don&amp;#39;t claim BinaryFormatter itself, or Reflection API that it uses,
as a core of the problem. They blame on communication.
&lt;/p&gt;
&lt;p&gt;
Spelling out clearly what are concerns could help to everyone to better understand
how to address it. In the area of security of communication there are a lot of ready
solutions like:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
use signature to avoid tampering the data;&lt;/li&gt;
&lt;li&gt;
use encription to avoid spying the data;&lt;/li&gt;
&lt;li&gt;
use access rights to avoid even access to the data;&lt;/li&gt;
&lt;li&gt;
use secure communication channels.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
We can surely state that without applying these solutions no other serialization format
is reliable and is subject of the same vulnerabilities.
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
After all it looked like an attempt to throw out the baby with the bath water. The
good news is that thankfully to now modular structure of .NET runtime we&amp;#39;re able
to access binary serialization library, which are (and will be) available on nugets
repositories. So, it&amp;#39;s futile effort to erase this usefull API. 
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=9121c6f9-e622-4d71-b25b-58763fa5d88e" /&gt;</description>
      <comments>http://www.nesterovsky-bros.com/weblog/CommentView,guid,9121c6f9-e622-4d71-b25b-58763fa5d88e.aspx</comments>
      <category>.NET</category>
      <category>Thinking aloud</category>
    </item>
    <item>
      <trackback:ping>http://www.nesterovsky-bros.com/weblog/Trackback.aspx?guid=b69227a9-de75-4062-aa5b-82c8dff548e1</trackback:ping>
      <pingback:server>http://www.nesterovsky-bros.com/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,b69227a9-de75-4062-aa5b-82c8dff548e1.aspx</pingback:target>
      <dc:creator>Arthur Nesterovsky</dc:creator>
      <georss:point>0 0</georss:point>
      <wfw:commentRss>http://www.nesterovsky-bros.com/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=b69227a9-de75-4062-aa5b-82c8dff548e1</wfw:commentRss>
      <title>Collecting public data from Internet</title>
      <guid isPermaLink="false">http://www.nesterovsky-bros.com/weblog/PermaLink,guid,b69227a9-de75-4062-aa5b-82c8dff548e1.aspx</guid>
      <link>http://www.nesterovsky-bros.com/weblog/2021/01/01/CollectingPublicDataFromInternet.aspx</link>
      <pubDate>Fri, 01 Jan 2021 14:34:37 GMT</pubDate>
      <description>&lt;p&gt;
Earlier we wrote that recently we've gotten few tasks related to Machine Learning.
The prerequisites to such task is to collect and prepare the input data. Usually the
required data is scattered across public sites, some of them are in plain text format
(or close to it), but others are accessible as output of public applications. To obtain
the required data for such sites you have to navigate thourgh pages, which often requires
keeping state between navigations. 
&lt;/p&gt;
&lt;p&gt;
In order to implement this task you need some kind of crawler/scraper of the websites.
Fortunately, there are a lot of frameworks, libraries and tools in C# (and in other
languages too) that allow to do this (visit &lt;a href="https://nugetmusthaves.com/Tag/crawler" target="_blank"&gt;this&lt;/a&gt; or &lt;a href="https://prowebscraper.com/blog/50-best-open-source-web-crawlers/" target="_blank"&gt;this&lt;/a&gt; site
to see most popular of them), for example: 
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
ScrapySharp&lt;/li&gt;
&lt;li&gt;
ABot&lt;/li&gt;
&lt;li&gt;
HtmlAgilityPack&lt;/li&gt;
&lt;li&gt;
DotnetSpider&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
There are pros and cons of using these libraries. Most crucial cons is a lack of support
of rich UI based on heavy client-side scripts and client-side state support. Since
not all such libraries implement fully browser emulation and even more, some of them
do not support Javascript execution. So, they suit for gathering information from
simple web pages, but no library allows to easy navigate to some page of a web application
that keeps rich client-side state. Even best of them, like ScrapySharp, require heavy
programming to achieve the result.
&lt;/p&gt;
&lt;p&gt;
Then, suddenly, we've recalled that already for several years we're using Selenium
and web drivers to automate web tests for AngularJS/Angular projects. After short
discussion we came to conclusion that there is no big difference between testing web
application and collecting data, since one of testing stages is collecting of actual
results (data) from the tested page, and usually our tests consist of chains of actions
performed on consequently visited pages. 
&lt;/p&gt;
&lt;p&gt;
This way we came to idea to use WebDriver API implemented by &lt;a href="https://www.selenium.dev/documentation/en/" target="_blank"&gt;Selenium
project&lt;/a&gt;. There are implementations of this API in different languages, and in
C# too.
&lt;/p&gt;
&lt;p&gt;
Using WebDriver we easily implement cumbersome navigation of a complex web application
and can collect required data. Moreover, it allows to run WebDriver in screenless
mode. Some of its features allow to create a snapshots of virtual screen and store
HTML sources that would resulted of Javascript execution. These features are very
useful during run-time troubleshooting. To create a complex web application navigation
we need only a bit more knowledge than usual web application's user - we need to identify
somehow pages' elements for example by CSS selectors or by id of HTML elements (as
we do this for tests). All the rest, like coockies, view state (if any), value of
hidden fields, some Javascript events will be transparent in this case. 
&lt;/p&gt;
&lt;p&gt;
Although one may say that approach with Selenium is rather fat, it's ought to mention
that it is rather scalable. You may either to run several threads with different WebDriver
instances in each thread or run several processes simultaneously. 
&lt;/p&gt;
&lt;p&gt;
However, beside pros there are cons in the solution with Selenium. They will appear
when you'll decide to publish it, e.g. to Azure environment. Take a note that approach
with Selenium requires a browser on the server, there is also a problem with Azure
itself, as it's Microsoft's platform and Selenium is a product of their main competitor
Google... So, some issues aren't techincals. The only possible solution is to use
PaaS approach instead of SaaS, but in this case you have to support everything by
yourself... 
&lt;/p&gt;
&lt;p&gt;
The other problem is that if your application will implement rather aggressive crawling,
so either servers where you gather data or your own host might ban it. So, be gentle,
play nice, and implement delays between requests. 
&lt;/p&gt;
&lt;p&gt;
Also, take into account that when you're implementing any crawler some problems may
appear on law level, since not all web sites allow pull anything you want. Many sites
use terms &amp; conditions that defines rules for the site users (that you cralwer should
follow to), otherwise legal actions may be used against them (or their owners in case
of crawler). There is &lt;a href="https://www.c-sharpcorner.com/article/web-crawling-with-c-sharp/" targte="_blank"&gt;very
interesting article&lt;/a&gt; that describes many pitfalls when you implement your own crawler. 
&lt;/p&gt;
&lt;p&gt;
To summarize everything we told early, the Selenium project could be used in many
scenarios, and one of them is to create a powerful crawler. 
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=b69227a9-de75-4062-aa5b-82c8dff548e1" /&gt;</description>
      <comments>http://www.nesterovsky-bros.com/weblog/CommentView,guid,b69227a9-de75-4062-aa5b-82c8dff548e1.aspx</comments>
      <category>ML.NET</category>
      <category>Thinking aloud</category>
      <category>Tips and tricks</category>
    </item>
    <item>
      <trackback:ping>http://www.nesterovsky-bros.com/weblog/Trackback.aspx?guid=799a45cc-83c0-4057-baaa-5089f8ffb484</trackback:ping>
      <pingback:server>http://www.nesterovsky-bros.com/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,799a45cc-83c0-4057-baaa-5089f8ffb484.aspx</pingback:target>
      <dc:creator>Vladimir Nesterovsky</dc:creator>
      <georss:point>0 0</georss:point>
      <wfw:commentRss>http://www.nesterovsky-bros.com/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=799a45cc-83c0-4057-baaa-5089f8ffb484</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
While doing <a href="https://www.oneadvanced.com/services/ca-gen-modernisation/">Cool:GEN
migratiotions to Java and C#</a> we produce rather big Angular applications.
</p>
        <p>
Everything is fine: server runs a REST APIs, and client is an Angular application
with components per each window, dialog or screen. The only problem is with the word
big.
</p>
        <p>
We observe that enterprises that used Cool:GEN to develop their workflow come to migration
stage with applications containing thousands of windows. In simple cases, after assessment,
clients are able to split their monolith workflow into a set of independent applications.
But even then we are dealing with Angular applications containing hundreds to many
thousands components.
</p>
        <p>
Now, lets look at Angular world. <a href="https://angular.io/guide/ivy">Best practices</a> advice
to (and actually almost force you to) use Ahead Of Time, Ivy compilation of all components
and their templates.
</p>
        <p>
Naive attempt to build such monolith Angular application will most surely fail. Angular
uses <a href="https://nodejs.org/en/">nodejs</a> for build, and chances are close
to 100% of nodejs to run out of memory during the <code>ng build</code>. 
</p>
        <p>
You may fight and throw at it a capable build machine with 16 or better with 32GB
of RAM, and instruct nodejs to use all of it. 
</p>
        <p>
Well, it's rather poor and extensive way of dealing with scale problems but it
works.
</p>
        <p>
Next hurdle you run into is time. We know it might take days just to build it. 
</p>
        <p>
You may ask why?
</p>
        <p>
Well, angular is doing its best to <a href="https://angular.io/guide/template-typecheck">validate
templates</a>! 
</p>
        <p>
Unfortunately the only viable workaround is to switch this nice feature off for such
a big project.
</p>
        <p>
With such setup you're able to build angular project in just 20-30 minutes!
</p>
        <p>
Well, this is a big progress if you compare complete failure vs something that at
least passes the build.
</p>
        <p>
But what's next?
</p>
        <p>
Sure, there are next problems:
</p>
        <ul>
          <li>
scripts both development and production are of nonsense size: like several dozen megabytes
for production, and some even higher number for development.</li>
          <li>
            <code>ng serve</code> eats even more memory and builds even longer making nightmare
out of development and support of such an application;</li>
          <li>
startup of such application, if it will start at all, is very slow.</li>
        </ul>
        <p>
So, what can be done? How can we create a manageable Angular application containing
that many components?
</p>
        <p>
Angular advices <a href="https://angular.io/guide/lazy-loading-ngmodules">Lazy-loading
feature modules</a>.
</p>
        <p>
That's reasonable advice!
</p>
        <p>
We can create coarse grained modules containing subsets of components or fine grained
modules containing one component.
</p>
        <p>
So, does it help?
</p>
        <p>
Yes, but it does not solve all problems:
</p>
        <ul>
          <li>
            <code>ng build</code> and <code>ng serve</code> are still very slow;</li>
          <li>
build produces multiple small scripts that are loaded on demand, so at least application
works in browser.</li>
        </ul>
        <p>
Yet, other important problem is still there: we have multiple severly separated server
REST controllers with components that represent them.
</p>
        <p>
On the server side we have Java or C# REST controllers hosting business logic. They
are separated per multiple projects probably managed by separate teams, and probably
kept in separate GITs (or whatever). On the client side we have a fat angular project
storing everything kept in single source repository.
</p>
        <p>
This is not going to work from management perspective.
</p>
        <p>
So the next step is try to split fat Angular project into multiple small projects.
So, let's say we shall have 100 small angular libraries combinded by master project.
</p>
        <p>
This is not going to work either due to nature of npm projects, as it will requre
terabytes of cloned node_modules folders for each library, and many hours to build
each of them.
</p>
        <p>
It seems there is a room for improvments in npm area. There is no point to make dedicated
copies of node_modules. It's much easier to have a local cache of artifacts.
</p>
        <p>
So, what is the direction? How to create big angular project after all?
</p>
        <p>
What we have here is:
</p>
        <ul>
          <li>
a big enterprise level application;</li>
          <li>
it is modular but modules must work together to form desired workflow;</li>
          <li>
different modules are supported by different teams (both server and client side);</li>
          <li>
client Angular components correspond to REST controllers on the server.</li>
          <li>
all pages use the same styles and the same set of UI controls;</li>
        </ul>
        <p>
Looking from this perspective all development can be seen as:
</p>
        <ul>
          <li>
development and support of unified styles and ui components that must be reused through
the application;</li>
          <li>
development of server side and REST controllers that implement business logic;</li>
          <li>
development of templates of components (note that components themselves do nothing
except expose their templates).</li>
        </ul>
        <p>
Studying this design suggests important and independent role of templates just like
it is in AngularJS!
</p>
        <p>
In contrast Angular templates are only a tool used by components. It's not obvious
how to use thousands of templates without first building thousands components; neither
it's obvious how to dynamically host those templates (routes do not help here).
</p>
        <p>
Though not obvious it's still possible to do it though it requires use a bit lower
level API than tutorials suggest. Ingredients are:
</p>
        <ul>
          <li>
use of Just In Time (in contrast to Ahead Of Time) compilation, and use View Enginev
(in contrast to Ivy);</li>
          <li>
use <a href="https://angular.io/api/core/ViewContainerRef#viewcontainerref">ViewContainerRef</a> to
host components dynamically;</li>
          <li>
Dynamic components and modules that you can create on demand using templates loaded
e.g. through <code>HttpClient</code>.</li>
        </ul>
        <p>
To make things short we shall show the example of dynamic components in next article.
</p>
        <p>
Here we shall emphasize that such design allows us to create small angular application
that builds under 20 seconds with component templates served along with the REST controllers,
and stored in the same Git. 
</p>
        <p>
So, if you say have a server subproject exposing REST controller say in the form:
api/area/MyComponent then its template may be exposed as resource: page/area/MyComponent.
Templates are loaded and compiled on demand at runtime thus making application light.
At the same time templates may be cached in browser cache thus reducing number of
roundtrips to the server.
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=799a45cc-83c0-4057-baaa-5089f8ffb484" />
      </body>
      <title>Big Angular applications</title>
      <guid isPermaLink="false">http://www.nesterovsky-bros.com/weblog/PermaLink,guid,799a45cc-83c0-4057-baaa-5089f8ffb484.aspx</guid>
      <link>http://www.nesterovsky-bros.com/weblog/2020/12/29/BigAngularApplications.aspx</link>
      <pubDate>Tue, 29 Dec 2020 18:15:25 GMT</pubDate>
      <description>  &lt;p&gt;
While doing &lt;a href="https://www.oneadvanced.com/services/ca-gen-modernisation/"&gt;Cool:GEN
migratiotions to Java and C#&lt;/a&gt; we produce rather big Angular applications.
&lt;/p&gt;
&lt;p&gt;
Everything is fine: server runs a REST APIs, and client is an Angular application
with components per each window, dialog or screen. The only problem is with the word
big.
&lt;/p&gt;
&lt;p&gt;
We observe that enterprises that used Cool:GEN to develop their workflow come to migration
stage with applications containing thousands of windows. In simple cases, after assessment,
clients are able to split their monolith workflow into a set of independent applications.
But even then we are dealing with Angular applications containing hundreds to many
thousands components.
&lt;/p&gt;
&lt;p&gt;
Now, lets look at Angular world. &lt;a href="https://angular.io/guide/ivy"&gt;Best practices&lt;/a&gt; advice
to (and actually almost force you to) use Ahead Of Time, Ivy compilation of all components
and their templates.
&lt;/p&gt;
&lt;p&gt;
Naive attempt to build such monolith Angular application will most surely fail. Angular
uses &lt;a href="https://nodejs.org/en/"&gt;nodejs&lt;/a&gt; for build, and chances are close
to 100% of nodejs to run out of memory during the &lt;code&gt;ng build&lt;/code&gt;. 
&lt;/p&gt;
&lt;p&gt;
You may fight and throw at it a capable build machine with 16 or better with 32GB
of RAM, and instruct nodejs to use all of it. 
&lt;/p&gt;
&lt;p&gt;
Well, it&amp;#39;s rather poor and extensive way of dealing with scale problems but it
works.
&lt;/p&gt;
&lt;p&gt;
Next hurdle you run into is time. We know it might take days just to build it. 
&lt;/p&gt;
&lt;p&gt;
You may ask why?
&lt;/p&gt;
&lt;p&gt;
Well, angular is doing its best to &lt;a href="https://angular.io/guide/template-typecheck"&gt;validate
templates&lt;/a&gt;! 
&lt;/p&gt;
&lt;p&gt;
Unfortunately the only viable workaround is to switch this nice feature off for such
a big project.
&lt;/p&gt;
&lt;p&gt;
With such setup you&amp;#39;re able to build angular project in just 20-30 minutes!
&lt;/p&gt;
&lt;p&gt;
Well, this is a big progress if you compare complete failure vs something that at
least passes the build.
&lt;/p&gt;
&lt;p&gt;
But what&amp;#39;s next?
&lt;/p&gt;
&lt;p&gt;
Sure, there are next problems:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
scripts both development and production are of nonsense size: like several dozen megabytes
for production, and some even higher number for development.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;ng serve&lt;/code&gt; eats even more memory and builds even longer making nightmare
out of development and support of such an application;&lt;/li&gt;
&lt;li&gt;
startup of such application, if it will start at all, is very slow.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
So, what can be done? How can we create a manageable Angular application containing
that many components?
&lt;/p&gt;
&lt;p&gt;
Angular advices &lt;a href="https://angular.io/guide/lazy-loading-ngmodules"&gt;Lazy-loading
feature modules&lt;/a&gt;.
&lt;/p&gt;
&lt;p&gt;
That&amp;#39;s reasonable advice!
&lt;/p&gt;
&lt;p&gt;
We can create coarse grained modules containing subsets of components or fine grained
modules containing one component.
&lt;/p&gt;
&lt;p&gt;
So, does it help?
&lt;/p&gt;
&lt;p&gt;
Yes, but it does not solve all problems:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;ng build&lt;/code&gt; and &lt;code&gt;ng serve&lt;/code&gt; are still very slow;&lt;/li&gt;
&lt;li&gt;
build produces multiple small scripts that are loaded on demand, so at least application
works in browser.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
Yet, other important problem is still there: we have multiple severly separated server
REST controllers with components that represent them.
&lt;/p&gt;
&lt;p&gt;
On the server side we have Java or C# REST controllers hosting business logic. They
are separated per multiple projects probably managed by separate teams, and probably
kept in separate GITs (or whatever). On the client side we have a fat angular project
storing everything kept in single source repository.
&lt;/p&gt;
&lt;p&gt;
This is not going to work from management perspective.
&lt;/p&gt;
&lt;p&gt;
So the next step is try to split fat Angular project into multiple small projects.
So, let&amp;#39;s say we shall have 100 small angular libraries combinded by master project.
&lt;/p&gt;
&lt;p&gt;
This is not going to work either due to nature of npm projects, as it will requre
terabytes of cloned node_modules folders for each library, and many hours to build
each of them.
&lt;/p&gt;
&lt;p&gt;
It seems there is a room for improvments in npm area. There is no point to make dedicated
copies of node_modules. It&amp;#39;s much easier to have a local cache of artifacts.
&lt;/p&gt;
&lt;p&gt;
So, what is the direction? How to create big angular project after all?
&lt;/p&gt;
&lt;p&gt;
What we have here is:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
a big enterprise level application;&lt;/li&gt;
&lt;li&gt;
it is modular but modules must work together to form desired workflow;&lt;/li&gt;
&lt;li&gt;
different modules are supported by different teams (both server and client side);&lt;/li&gt;
&lt;li&gt;
client Angular components correspond to REST controllers on the server.&lt;/li&gt;
&lt;li&gt;
all pages use the same styles and the same set of UI controls;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
Looking from this perspective all development can be seen as:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
development and support of unified styles and ui components that must be reused through
the application;&lt;/li&gt;
&lt;li&gt;
development of server side and REST controllers that implement business logic;&lt;/li&gt;
&lt;li&gt;
development of templates of components (note that components themselves do nothing
except expose their templates).&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
Studying this design suggests important and independent role of templates just like
it is in AngularJS!
&lt;/p&gt;
&lt;p&gt;
In contrast Angular templates are only a tool used by components. It&amp;#39;s not obvious
how to use thousands of templates without first building thousands components; neither
it&amp;#39;s obvious how to dynamically host those templates (routes do not help here).
&lt;/p&gt;
&lt;p&gt;
Though not obvious it&amp;#39;s still possible to do it though it requires use a bit lower
level API than tutorials suggest. Ingredients are:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
use of Just In Time (in contrast to Ahead Of Time) compilation, and use View Enginev
(in contrast to Ivy);&lt;/li&gt;
&lt;li&gt;
use &lt;a href="https://angular.io/api/core/ViewContainerRef#viewcontainerref"&gt;ViewContainerRef&lt;/a&gt; to
host components dynamically;&lt;/li&gt;
&lt;li&gt;
Dynamic components and modules that you can create on demand using templates loaded
e.g. through &lt;code&gt;HttpClient&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
To make things short we shall show the example of dynamic components in next article.
&lt;/p&gt;
&lt;p&gt;
Here we shall emphasize that such design allows us to create small angular application
that builds under 20 seconds with component templates served along with the REST controllers,
and stored in the same Git. 
&lt;/p&gt;
&lt;p&gt;
So, if you say have a server subproject exposing REST controller say in the form:
api/area/MyComponent then its template may be exposed as resource: page/area/MyComponent.
Templates are loaded and compiled on demand at runtime thus making application light.
At the same time templates may be cached in browser cache thus reducing number of
roundtrips to the server.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=799a45cc-83c0-4057-baaa-5089f8ffb484" /&gt;</description>
      <comments>http://www.nesterovsky-bros.com/weblog/CommentView,guid,799a45cc-83c0-4057-baaa-5089f8ffb484.aspx</comments>
      <category>Angular</category>
      <category>AngularJS</category>
      <category>Thinking aloud</category>
    </item>
    <item>
      <trackback:ping>http://www.nesterovsky-bros.com/weblog/Trackback.aspx?guid=638aefac-fd7a-431a-9d7f-0aeef885d9a5</trackback:ping>
      <pingback:server>http://www.nesterovsky-bros.com/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,638aefac-fd7a-431a-9d7f-0aeef885d9a5.aspx</pingback:target>
      <dc:creator>Arthur Nesterovsky</dc:creator>
      <georss:point>0 0</georss:point>
      <wfw:commentRss>http://www.nesterovsky-bros.com/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=638aefac-fd7a-431a-9d7f-0aeef885d9a5</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <img src="https://i.ytimg.com/vi/VJTpbZrBAeU/hqdefault.jpg" width="200" style="float: left; margin-right: 5px;" />Eventually
we've started to deal with tasks that required machine learning. Thus, the good tutorial
for ML.NET was required and we had <a href="https://youtu.be/VJTpbZrBAeU" target="_blank">found
this one</a> that goes along with <a href="https://github.com/jeffprosise/ML.NET" target="_blank">good
simple codesamples</a>. Thanks to Jeff Prosise. Hope this may be helpfull to you too.
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=638aefac-fd7a-431a-9d7f-0aeef885d9a5" />
      </body>
      <title>ML.NET tutorial</title>
      <guid isPermaLink="false">http://www.nesterovsky-bros.com/weblog/PermaLink,guid,638aefac-fd7a-431a-9d7f-0aeef885d9a5.aspx</guid>
      <link>http://www.nesterovsky-bros.com/weblog/2020/12/16/MLNETTutorial.aspx</link>
      <pubDate>Wed, 16 Dec 2020 11:38:57 GMT</pubDate>
      <description>&lt;p&gt;
&lt;img src="https://i.ytimg.com/vi/VJTpbZrBAeU/hqdefault.jpg" width="200" style="float: left; margin-right: 5px;" /&gt;Eventually
we've started to deal with tasks that required machine learning. Thus, the good tutorial
for ML.NET was required and we had &lt;a href="https://youtu.be/VJTpbZrBAeU" target="_blank"&gt;found
this one&lt;/a&gt; that goes along with &lt;a href="https://github.com/jeffprosise/ML.NET" target="_blank"&gt;good
simple codesamples&lt;/a&gt;. Thanks to Jeff Prosise. Hope this may be helpfull to you too.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=638aefac-fd7a-431a-9d7f-0aeef885d9a5" /&gt;</description>
      <comments>http://www.nesterovsky-bros.com/weblog/CommentView,guid,638aefac-fd7a-431a-9d7f-0aeef885d9a5.aspx</comments>
      <category>.NET</category>
      <category>ML.NET</category>
      <category>Tips and tricks</category>
    </item>
    <item>
      <trackback:ping>http://www.nesterovsky-bros.com/weblog/Trackback.aspx?guid=ec795ede-3e18-473f-bff9-204ea1cecf49</trackback:ping>
      <pingback:server>http://www.nesterovsky-bros.com/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,ec795ede-3e18-473f-bff9-204ea1cecf49.aspx</pingback:target>
      <dc:creator>Vladimir Nesterovsky</dc:creator>
      <georss:point>0 0</georss:point>
      <wfw:commentRss>http://www.nesterovsky-bros.com/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=ec795ede-3e18-473f-bff9-204ea1cecf49</wfw:commentRss>
      <title>Groups in SQL</title>
      <guid isPermaLink="false">http://www.nesterovsky-bros.com/weblog/PermaLink,guid,ec795ede-3e18-473f-bff9-204ea1cecf49.aspx</guid>
      <link>http://www.nesterovsky-bros.com/weblog/2020/08/05/GroupsInSQL.aspx</link>
      <pubDate>Wed, 05 Aug 2020 07:44:07 GMT</pubDate>
      <description>  &lt;p&gt;
Recently our colleague turned to us and asked to help to deal with some complex query.
&lt;/p&gt;
&lt;p&gt;
It has turned out that the complex part was to understand what he wants to achieve.
&lt;/p&gt;
&lt;p&gt;
After listening to him we have forumulated the task in our words and have confirmed
that that is what he wants.
&lt;/p&gt;
&lt;p&gt;
So, that&amp;#39;s the task in our formulation:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
Assume you have events. 
&lt;/li&gt;
&lt;li&gt;
Each event acts upon one or more accounts.&lt;/li&gt;
&lt;li&gt;
Find all events that act on the same set of accounts.&lt;/li&gt;
&lt;li&gt;
Note we deal with mutiple millions of events and accounts.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
Data is defined like this:
&lt;/p&gt;
&lt;blockquote&gt;&lt;pre&gt;create table dbo.Event
(
  EventID bigint not null,
  AccountID varchar(18) not null,
  primary key(EventID, AccountID)
);&lt;/pre&gt;&lt;/blockquote&gt; 
&lt;p&gt;
Requested query turned out to be very simple, yet, not as simple as one would think
to account big amout of data:
&lt;/p&gt;
&lt;blockquote&gt;&lt;pre&gt;&lt; S2.EventID and
    S1.Items = S2.Items and
    S1.Hash = S2.Hash and
    not exists
    (
      select AccountID from D where EventID = S1.EventID
      except
      select AccountID from D where EventID = S2.EventID
    );&lt;/pre&gt;with D as
(
  select * from dbo.Event
),
S as
(
  select
    EventID,
    count(*) Items,
    checksum_agg(checksum(AccountID)) Hash
  from
    D
  group by
    EventID
)
select
  S1.EventID, S2.EventID
from
  S S1
  inner join
  S S2
  on
    S1.EventID 
&lt;/blockquote&gt; 
&lt;p&gt;
The idea is to:
&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
calculate a hash derived from list of accounts for each group;&lt;/li&gt;
&lt;li&gt;
join groups with the same hash;&lt;/li&gt;
&lt;li&gt;
verify that matched groups fit perfectly.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;
Even simpler solution that does not use hashes is not scaleable, as it&amp;#39;s performance
is slower than O(N^2), where N - is a number of events. It has unacceptable time with
N ~1e4, nothing to say about N ~1e7.
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
At this point our colleague was already satisfied, as he got result in couple of minutes
for a task that he could not even formalize as SQL.
&lt;/p&gt;
&lt;p&gt;
But we felt it could be even better.
&lt;/p&gt;
&lt;p&gt;
We looked at statistics:
&lt;/p&gt;
&lt;blockquote&gt;&lt;pre&gt;
with D as
(
  select * from dbo.Event
),
S as
(
  select
    EventID,
    count(*) Items
  from
    D
  group by
    EventID
)
select
  Items, count(*) EventCount
from
  S
group by
  Items
order by
  EventCount desc;&lt;/pre&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
and have seen that most of the events, about 90%, deal with single account, and all
other with two and more (some of them act upon big number of accounts).
&lt;/p&gt;
&lt;p&gt;
The nature of the dataset gave us a hint of more verbose but more fast query:
&lt;/p&gt;
&lt;blockquote&gt;&lt;pre&gt;&lt; S2.EventID and
    S1.Items = 1 and
    S2.Items = 1 and
    S1.AccountID = S2.AccountID
union all
select
  S1.EventID, S2.EventID
from
  S S1
  inner join
  S S2
  on
    S1.EventID &lt; S2.EventID and
    S1.Items &gt;with D as
(
  select * from dbo.Event
),
S as
(
  select
    EventID,
    min(AccountID) AccountID,
    count(*) Items,
    checksum_agg(checksum(AccountID)) Hash
  from
    D
  group by
    EventID
)
select
  S1.EventID, S2.EventID
from
  S S1
  inner join
  S S2
  on
    S1.EventID  1 and
    S2.Items &gt; 1 and
    S1.Items = S2.Items and
    S1.Hash = S2.Hash and
    not exists
    (
      select AccountID from D where EventID = S1.EventID
      except
      select AccountID from D where EventID = S2.EventID
    );&lt;/pre&gt;&lt;/blockquote&gt; 
&lt;p&gt;
This query produced results in twenty seconds instead of couple of minutes for a dataset
with ~1e7 rows.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=ec795ede-3e18-473f-bff9-204ea1cecf49" /&gt;</description>
      <comments>http://www.nesterovsky-bros.com/weblog/CommentView,guid,ec795ede-3e18-473f-bff9-204ea1cecf49.aspx</comments>
      <category>SQL Server puzzle</category>
      <category>Thinking aloud</category>
      <category>Tips and tricks</category>
    </item>
    <item>
      <trackback:ping>http://www.nesterovsky-bros.com/weblog/Trackback.aspx?guid=4196bfb4-24a3-4d7d-bea9-59bc907ce4ba</trackback:ping>
      <pingback:server>http://www.nesterovsky-bros.com/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,4196bfb4-24a3-4d7d-bea9-59bc907ce4ba.aspx</pingback:target>
      <dc:creator>Vladimir Nesterovsky</dc:creator>
      <georss:point>0 0</georss:point>
      <wfw:commentRss>http://www.nesterovsky-bros.com/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=4196bfb4-24a3-4d7d-bea9-59bc907ce4ba</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Not sure what is use of our <a href="https://github.com/nesterovsky-bros/xslt-graph">Xslt
Graph exercises</a> but what we are sure with is that it stresses different parts
of Saxon Xslt engine and helps to find and resolve different bugs.
</p>
        <p>
While implementing <a href="https://github.com/nesterovsky-bros/xslt-graph/blob/master/biconnected-components.xslt">biconnected
components algorithm</a> we incidently run into <a href="https://github.com/nesterovsky-bros/xslt-graph/blob/master/tests/saxon-10.1-internal-error.xslt">internal
error with Saxon 10.1</a> with rather simple xslt:
</p>
        <blockquote>
          <pre>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;xsl:stylesheet version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:xs="http://www.w3.org/2001/XMLSchema"
  xmlns:array="http://www.w3.org/2005/xpath-functions/array"
  exclude-result-prefixes="xs array"&gt;

  &lt;xsl:template match="/"&gt;
    &lt;xsl:sequence select="
      array:fold-left
      (
        [8, 9], 
        (), 
        function($first as item(), $second as item()) 
        {  
          min(($first, $second))
        }
      )"/&gt;
  &lt;/xsl:template&gt;

&lt;/xsl:stylesheet&gt;</pre>
        </blockquote>
        <p>
More detail can be found at Saxon's issue tracker: <a href="https://saxonica.plan.io/issues/4578">Bug
#4578: NullPointerException when array:fold-left|right $zero argument is an empty
sequence</a>. 
</p>
        <p>
Bug is promptly resolved.
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=4196bfb4-24a3-4d7d-bea9-59bc907ce4ba" />
      </body>
      <title>Xslt Graph and Saxon processor</title>
      <guid isPermaLink="false">http://www.nesterovsky-bros.com/weblog/PermaLink,guid,4196bfb4-24a3-4d7d-bea9-59bc907ce4ba.aspx</guid>
      <link>http://www.nesterovsky-bros.com/weblog/2020/06/08/XsltGraphAndSaxonProcessor.aspx</link>
      <pubDate>Mon, 08 Jun 2020 05:58:32 GMT</pubDate>
      <description>&lt;p&gt;
Not sure what is use of our &lt;a href="https://github.com/nesterovsky-bros/xslt-graph"&gt;Xslt
Graph exercises&lt;/a&gt; but what we are sure with is that it stresses different parts
of Saxon Xslt engine and helps to find and resolve different bugs.
&lt;/p&gt;
&lt;p&gt;
While implementing &lt;a href="https://github.com/nesterovsky-bros/xslt-graph/blob/master/biconnected-components.xslt"&gt;biconnected
components algorithm&lt;/a&gt; we incidently run into &lt;a href="https://github.com/nesterovsky-bros/xslt-graph/blob/master/tests/saxon-10.1-internal-error.xslt"&gt;internal
error with Saxon 10.1&lt;/a&gt; with rather simple xslt:
&lt;/p&gt;
&lt;blockquote&gt;&lt;pre&gt;&amp;lt;?xml version="1.0" encoding="utf-8"?&gt;
&amp;lt;xsl:stylesheet version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:xs="http://www.w3.org/2001/XMLSchema"
  xmlns:array="http://www.w3.org/2005/xpath-functions/array"
  exclude-result-prefixes="xs array"&gt;

  &amp;lt;xsl:template match="/"&gt;
    &amp;lt;xsl:sequence select="
      array:fold-left
      (
        [8, 9], 
        (), 
        function($first as item(), $second as item()) 
        {  
          min(($first, $second))
        }
      )"/&gt;
  &amp;lt;/xsl:template&gt;

&amp;lt;/xsl:stylesheet&gt;&lt;/pre&gt;&lt;/blockquote&gt; 
&lt;p&gt;
More detail can be found at Saxon's issue tracker: &lt;a href="https://saxonica.plan.io/issues/4578"&gt;Bug
#4578: NullPointerException when array:fold-left|right $zero argument is an empty
sequence&lt;/a&gt;. 
&lt;/p&gt;
&lt;p&gt;
Bug is promptly resolved.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=4196bfb4-24a3-4d7d-bea9-59bc907ce4ba" /&gt;</description>
      <comments>http://www.nesterovsky-bros.com/weblog/CommentView,guid,4196bfb4-24a3-4d7d-bea9-59bc907ce4ba.aspx</comments>
      <category>Tips and tricks</category>
      <category>xslt</category>
    </item>
    <item>
      <trackback:ping>http://www.nesterovsky-bros.com/weblog/Trackback.aspx?guid=8a79cdd8-4d17-416b-a82c-6b597dd36728</trackback:ping>
      <pingback:server>http://www.nesterovsky-bros.com/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,8a79cdd8-4d17-416b-a82c-6b597dd36728.aspx</pingback:target>
      <dc:creator>Vladimir Nesterovsky</dc:creator>
      <georss:point>0 0</georss:point>
      <wfw:commentRss>http://www.nesterovsky-bros.com/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=8a79cdd8-4d17-416b-a82c-6b597dd36728</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
While working on algorithm to trace <a href="https://en.wikipedia.org/wiki/Biconnected_component">Biconnected
components</a> for <a href="https://github.com/nesterovsky-bros/xslt-graph">Graph
API in the XSLT</a>  we realized that we implemented it unconventionally.
</p>
        <h3>A pseudocode in <a href="https://en.wikipedia.org/wiki/Biconnected_component">Wikipedia</a> is:
</h3>
        <pre>GetArticulationPoints(i, d)
    visited[i] := true
    depth[i] := d
    low[i] := d
    childCount := 0
    isArticulation := false

    <b>for
each</b> ni <b>in</b> adj[i] <b>do</b><b>if</b> not visited[ni] <b>then</b> parent[ni]
:= i GetArticulationPoints(ni, d + 1) childCount := childCount + 1 <b>if</b> low[ni]
≥ depth[i] <b>then</b> isArticulation := true low[i] := Min (low[i], low[ni]) <b>else
if</b> ni ≠ parent[i] <b>then</b> low[i] := Min (low[i], depth[ni]) <b>if</b> (parent[i]
≠ <b>null</b><b>and</b> isArticulation) <b>or</b> (parent[i] = <b>null</b><b>and</b> childCount
&gt; 1) <b>then</b> Output i as articulation point</pre>
        <p>
That algorithm is based on the fact that connected graph can be represented as a tree
of biconnected components. Vertices of such <b>tree</b> are called articulation points.
Implementation deals with a depth of each vertex, and with a lowpoint parameter that
is also related to vertex depth during Depth-First-Search.
</p>
        <p>
Out of interest we approached to the problem from different perspective. A vertex
is an articulation point if it has neighbors that cannot be combined into a path not
containing this vertex. As well as classical algorithm we use Depth-First-Search to
navigate the graph, but in contrast we collect cycles that pass through each vertex.
If during back pass of Depth-First-Search we find not cycle from "child"
to "ancestor" then it is necessary an articulation point.
</p>
        <h3>Here is pseudocode:
</h3>
        <pre>GetArticulationPoints(v, p) -&gt; result
    index = index + 1
    visited[v] = index 
    result = index
    articulation = p = null ? -1 : 0

    <b>for
each</b> n <b>in</b> neighbors of v <b>except</b> p <b>do</b><b>if</b> visited[n]
= 0 <b>then</b> nresult = GetArticulationPoints(n, v) result = min(result, nresult) <b>if</b> nresult
&gt;= visited[v] <b>then</b> articulation = articulation + 1 <b>else</b> result =
min(result, visited[n]) <b>if</b> articulation &gt; 0 <b>then</b> Output v as articulation
point</pre>
        <p>
Algorithms' complexity are the same.
</p>
        <p>
What is interesting is that we see no obvious way to transform one algorithm into
the other except from starting from Graph theory.
</p>
        <p>
More is on <a href="https://github.com/nesterovsky-bros/xslt-graph/wiki/Algorithm-for-Biconnected-components">Wiki</a>.
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=8a79cdd8-4d17-416b-a82c-6b597dd36728" />
      </body>
      <title>Algorithm for Biconnected components</title>
      <guid isPermaLink="false">http://www.nesterovsky-bros.com/weblog/PermaLink,guid,8a79cdd8-4d17-416b-a82c-6b597dd36728.aspx</guid>
      <link>http://www.nesterovsky-bros.com/weblog/2020/05/24/AlgorithmForBiconnectedComponents.aspx</link>
      <pubDate>Sun, 24 May 2020 12:15:02 GMT</pubDate>
      <description>  &lt;p&gt;
While working on algorithm to trace &lt;a href="https://en.wikipedia.org/wiki/Biconnected_component"&gt;Biconnected
components&lt;/a&gt; for &lt;a href="https://github.com/nesterovsky-bros/xslt-graph"&gt;Graph
API in the XSLT&lt;/a&gt;&amp;nbsp; we realized that we implemented it unconventionally.
&lt;/p&gt;
&lt;h3&gt;A pseudocode in &lt;a href="https://en.wikipedia.org/wiki/Biconnected_component"&gt;Wikipedia&lt;/a&gt; is:
&lt;/h3&gt;
&lt;pre&gt;GetArticulationPoints(i, d)
    visited[i] := true
    depth[i] := d
    low[i] := d
    childCount := 0
    isArticulation := false

    &lt;b&gt;for
each&lt;/b&gt; ni &lt;b&gt;in&lt;/b&gt; adj[i] &lt;b&gt;do&lt;/b&gt; &lt;b&gt;if&lt;/b&gt; not visited[ni] &lt;b&gt;then&lt;/b&gt; parent[ni]
:= i GetArticulationPoints(ni, d + 1) childCount := childCount + 1 &lt;b&gt;if&lt;/b&gt; low[ni]
≥ depth[i] &lt;b&gt;then&lt;/b&gt; isArticulation := true low[i] := Min (low[i], low[ni]) &lt;b&gt;else
if&lt;/b&gt; ni ≠ parent[i] &lt;b&gt;then&lt;/b&gt; low[i] := Min (low[i], depth[ni]) &lt;b&gt;if&lt;/b&gt; (parent[i]
≠ &lt;b&gt;null&lt;/b&gt; &lt;b&gt;and&lt;/b&gt; isArticulation) &lt;b&gt;or&lt;/b&gt; (parent[i] = &lt;b&gt;null&lt;/b&gt; &lt;b&gt;and&lt;/b&gt; childCount
&amp;gt; 1) &lt;b&gt;then&lt;/b&gt; Output i as articulation point&lt;/pre&gt;
&lt;p&gt;
That algorithm is based on the fact that connected graph can be represented as a tree
of biconnected components. Vertices of such &lt;b&gt;tree&lt;/b&gt; are called articulation points.
Implementation deals with a depth of each vertex, and with a lowpoint parameter that
is also related to vertex depth during Depth-First-Search.
&lt;/p&gt;
&lt;p&gt;
Out of interest we approached to the problem from different perspective. A vertex
is an articulation point if it has neighbors that cannot be combined into a path not
containing this vertex. As well as classical algorithm we use Depth-First-Search to
navigate the graph, but in contrast we collect cycles that pass through each vertex.
If during back pass of Depth-First-Search we find not cycle from &amp;quot;child&amp;quot;
to &amp;quot;ancestor&amp;quot; then it is necessary an articulation point.
&lt;/p&gt;
&lt;h3&gt;Here is pseudocode:
&lt;/h3&gt;
&lt;pre&gt;GetArticulationPoints(v, p) -&amp;gt; result
    index = index + 1
    visited[v] = index 
    result = index
    articulation = p = null ? -1 : 0

    &lt;b&gt;for
each&lt;/b&gt; n &lt;b&gt;in&lt;/b&gt; neighbors of v &lt;b&gt;except&lt;/b&gt; p &lt;b&gt;do&lt;/b&gt; &lt;b&gt;if&lt;/b&gt; visited[n]
= 0 &lt;b&gt;then&lt;/b&gt; nresult = GetArticulationPoints(n, v) result = min(result, nresult) &lt;b&gt;if&lt;/b&gt; nresult
&amp;gt;= visited[v] &lt;b&gt;then&lt;/b&gt; articulation = articulation + 1 &lt;b&gt;else&lt;/b&gt; result =
min(result, visited[n]) &lt;b&gt;if&lt;/b&gt; articulation &amp;gt; 0 &lt;b&gt;then&lt;/b&gt; Output v as articulation
point&lt;/pre&gt;
&lt;p&gt;
Algorithms&amp;#39; complexity are the same.
&lt;/p&gt;
&lt;p&gt;
What is interesting is that we see no obvious way to transform one algorithm into
the other except from starting from Graph theory.
&lt;/p&gt;
&lt;p&gt;
More is on &lt;a href="https://github.com/nesterovsky-bros/xslt-graph/wiki/Algorithm-for-Biconnected-components"&gt;Wiki&lt;/a&gt;.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=8a79cdd8-4d17-416b-a82c-6b597dd36728" /&gt;</description>
      <comments>http://www.nesterovsky-bros.com/weblog/CommentView,guid,8a79cdd8-4d17-416b-a82c-6b597dd36728.aspx</comments>
      <category>Thinking aloud</category>
      <category>xslt</category>
    </item>
    <item>
      <trackback:ping>http://www.nesterovsky-bros.com/weblog/Trackback.aspx?guid=c7ab748a-9b08-425c-83be-907ab4b7fef3</trackback:ping>
      <pingback:server>http://www.nesterovsky-bros.com/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,c7ab748a-9b08-425c-83be-907ab4b7fef3.aspx</pingback:target>
      <dc:creator>Vladimir Nesterovsky</dc:creator>
      <georss:point>0 0</georss:point>
      <wfw:commentRss>http://www.nesterovsky-bros.com/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=c7ab748a-9b08-425c-83be-907ab4b7fef3</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Michael Key's <a href="http://www.saxonica.com/papers/xmlprague-2020mhk.pdf">"A
Proposal for XSLT 4.0"</a> has spinned our interest in what could be added or
changed in XSLT. This way we decided to implement <a href="https://github.com/nesterovsky-bros/xslt-graph">Graph
API purely in xslt</a>. Our goal was to prove that:
</p>
        <ul>
          <li>
it's possible to provide efficient implementation of different Graph Algorithms in
XSLT;</li>
          <li>
to build Graph API the way that engine could provide native implementations of Grahp
Algorithms.</li>
          <li>
to find through an experiments what could be added to XSLT as a language.</li>
        </ul>
        <p>
At present we may confirm that first <a href="https://github.com/nesterovsky-bros/xslt-graph">two
goals are reachable</a>; and experiments have shown that XSLT could provide more help
to make program better, e.g. we have seen that language could simplify coding cycles.
</p>
        <p>
Graph algorithms are often expressed with while cycles, e.g <a href="https://en.wikipedia.org/wiki/Dijkstra%27s_algorithm">"Dijkstra's
algorithm"</a> has:
</p>
        <pre>12      while Q is not empty:
13          u ← vertex in Q with min dist[u]  
</pre>
        <p>
body is executed when condition is satisfied, but condition is impacted by body itself.
</p>
        <p>
In xslt 3.0 we did this with simple recursion:
</p>
        <pre>
&lt;xsl:template name="f:while" as="item()*"&gt;
  &lt;xsl:param name="condition" as="function(item()*) as xs:boolean"/&gt;
  &lt;xsl:param name="action" as="function(item()*) as item()*"/&gt;
  &lt;xsl:param name="next" as="function(item()*, item()*) as item()*"/&gt;
  &lt;xsl:param name="state" as="item()*"/&gt;

  &lt;xsl:if test="$condition($state)"&gt;
    &lt;xsl:variable name="items" as="item()*" select="$action($state)"/&gt;

    &lt;xsl:sequence select="$items"/&gt;

    &lt;xsl:call-template name="f:while"&gt;
      &lt;xsl:with-param name="condition" select="$condition"/&gt;
      &lt;xsl:with-param name="action" select="$action"/&gt;
      &lt;xsl:with-param name="next" select="$next"/&gt;
      &lt;xsl:with-param name="state" select="$next($state, $items)"/&gt;
    &lt;/xsl:call-template&gt;
  &lt;/xsl:if&gt;
&lt;/xsl:template&gt;
</pre>
        <p>
But here is the point. It could be done in more comprehended way. E.g. to let <code>xsl:iterate</code> without <code>select</code> to
cycle until <code>xsl:break</code> is reached.
</p>
        <pre>&lt;xsl:iterate&gt;
  &lt;xsl:param name="name" as="..." value="..."/&gt;
  
  &lt;xsl:if test="..."&gt;
    &lt;xsl:break/&gt;
  &lt;/xsl:if&gt;

  ...
&lt;/xsl:iterate&gt;</pre>
        <p>
So, what we propose is to let <code>xsl:iterate/@select</code> to be optional, and
change the behavior of processor when the attribute is missing from compilation error
to a valid behavior. This should not impact on any existing valid XSLT 3.0 program. 
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=c7ab748a-9b08-425c-83be-907ab4b7fef3" />
      </body>
      <title>On XSLT 4</title>
      <guid isPermaLink="false">http://www.nesterovsky-bros.com/weblog/PermaLink,guid,c7ab748a-9b08-425c-83be-907ab4b7fef3.aspx</guid>
      <link>http://www.nesterovsky-bros.com/weblog/2020/05/19/OnXSLT4.aspx</link>
      <pubDate>Tue, 19 May 2020 07:00:25 GMT</pubDate>
      <description>&lt;p&gt;
Michael Key&amp;#39;s &lt;a href="http://www.saxonica.com/papers/xmlprague-2020mhk.pdf"&gt;&amp;quot;A
Proposal for XSLT 4.0&amp;quot;&lt;/a&gt; has spinned our interest in what could be added or
changed in XSLT. This way we decided to implement &lt;a href="https://github.com/nesterovsky-bros/xslt-graph"&gt;Graph
API purely in xslt&lt;/a&gt;. Our goal was to prove that:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
it's possible to provide efficient implementation of different Graph Algorithms in
XSLT;&lt;/li&gt;
&lt;li&gt;
to build Graph API the way that engine could provide native implementations of Grahp
Algorithms.&lt;/li&gt;
&lt;li&gt;
to find through an experiments what could be added to XSLT as a language.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
At present we may confirm that first &lt;a href="https://github.com/nesterovsky-bros/xslt-graph"&gt;two
goals are reachable&lt;/a&gt;; and experiments have shown that XSLT could provide more help
to make program better, e.g. we have seen that language could simplify coding cycles.
&lt;/p&gt;
&lt;p&gt;
Graph algorithms are often expressed with while cycles, e.g &lt;a href="https://en.wikipedia.org/wiki/Dijkstra%27s_algorithm"&gt;&amp;quot;Dijkstra&amp;#39;s
algorithm&amp;quot;&lt;/a&gt; has:
&lt;/p&gt;
&lt;pre&gt;12      while Q is not empty:
13          u ← vertex in Q with min dist[u]  
&lt;/pre&gt;
&lt;p&gt;
body is executed when condition is satisfied, but condition is impacted by body itself.
&lt;/p&gt;
&lt;p&gt;
In xslt 3.0 we did this with simple recursion:
&lt;/p&gt;
&lt;pre&gt;
&amp;lt;xsl:template name="f:while" as="item()*"&gt;
  &amp;lt;xsl:param name="condition" as="function(item()*) as xs:boolean"/&gt;
  &amp;lt;xsl:param name="action" as="function(item()*) as item()*"/&gt;
  &amp;lt;xsl:param name="next" as="function(item()*, item()*) as item()*"/&gt;
  &amp;lt;xsl:param name="state" as="item()*"/&gt;

  &amp;lt;xsl:if test="$condition($state)"&gt;
    &amp;lt;xsl:variable name="items" as="item()*" select="$action($state)"/&gt;

    &amp;lt;xsl:sequence select="$items"/&gt;

    &amp;lt;xsl:call-template name="f:while"&gt;
      &amp;lt;xsl:with-param name="condition" select="$condition"/&gt;
      &amp;lt;xsl:with-param name="action" select="$action"/&gt;
      &amp;lt;xsl:with-param name="next" select="$next"/&gt;
      &amp;lt;xsl:with-param name="state" select="$next($state, $items)"/&gt;
    &amp;lt;/xsl:call-template&gt;
  &amp;lt;/xsl:if&gt;
&amp;lt;/xsl:template&gt;
&lt;/pre&gt;
&lt;p&gt;
But here is the point. It could be done in more comprehended way. E.g. to let &lt;code&gt;xsl:iterate&lt;/code&gt; without &lt;code&gt;select&lt;/code&gt; to
cycle until &lt;code&gt;xsl:break&lt;/code&gt; is reached.
&lt;/p&gt;
&lt;pre&gt;&amp;lt;xsl:iterate&amp;gt;
  &amp;lt;xsl:param name=&amp;quot;name&amp;quot; as=&amp;quot;...&amp;quot; value=&amp;quot;...&amp;quot;/&amp;gt;
  
  &amp;lt;xsl:if test=&amp;quot;...&amp;quot;&amp;gt;
    &amp;lt;xsl:break/&amp;gt;
  &amp;lt;/xsl:if&amp;gt;

  ...
&amp;lt;/xsl:iterate&amp;gt;&lt;/pre&gt;
&lt;p&gt;
So, what we propose is to let &lt;code&gt;xsl:iterate/@select&lt;/code&gt; to be optional, and
change the behavior of processor when the attribute is missing from compilation error
to a valid behavior. This should not impact on any existing valid XSLT 3.0 program. 
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=c7ab748a-9b08-425c-83be-907ab4b7fef3" /&gt;</description>
      <comments>http://www.nesterovsky-bros.com/weblog/CommentView,guid,c7ab748a-9b08-425c-83be-907ab4b7fef3.aspx</comments>
      <category>Thinking aloud</category>
      <category>xslt</category>
    </item>
    <item>
      <trackback:ping>http://www.nesterovsky-bros.com/weblog/Trackback.aspx?guid=57573dd7-7ec0-47e3-891e-aa186277e0f2</trackback:ping>
      <pingback:server>http://www.nesterovsky-bros.com/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,57573dd7-7ec0-47e3-891e-aa186277e0f2.aspx</pingback:target>
      <dc:creator>Vladimir Nesterovsky</dc:creator>
      <georss:point>0 0</georss:point>
      <wfw:commentRss>http://www.nesterovsky-bros.com/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=57573dd7-7ec0-47e3-891e-aa186277e0f2</wfw:commentRss>
      <title>Graphs in XSLT</title>
      <guid isPermaLink="false">http://www.nesterovsky-bros.com/weblog/PermaLink,guid,57573dd7-7ec0-47e3-891e-aa186277e0f2.aspx</guid>
      <link>http://www.nesterovsky-bros.com/weblog/2020/05/12/GraphsInXSLT.aspx</link>
      <pubDate>Tue, 12 May 2020 06:08:51 GMT</pubDate>
      <description>  &lt;p&gt;
Recently we've read an article &lt;a href="http://www.saxonica.com/papers/xmlprague-2020mhk.pdf"&gt;&amp;quot;A
Proposal for XSLT 4.0&amp;quot;&lt;/a&gt;, and thought it worth to suggest one more idea. We
have written a &lt;a href="https://saxonica.plan.io/boards/2/topics/7870"&gt;message&lt;/a&gt; to
Michael Kay, author of this proposal. Here it is: 
&lt;/p&gt;
&lt;blockquote style="font-style: italic"&gt; &lt;b&gt;A&amp;V&lt;/b&gt; 
&lt;p&gt;
Historically xslt, xquery and xpath were dealing with trees. Nowadays it became much
common to process graphs. Many tasks can be formulated in terms of graphs, and in
particular any task processing trees is also graph task. 
&lt;/p&gt;
&lt;p&gt;
I suggest to take a deeper look in this direction. 
&lt;/p&gt;
&lt;p&gt;
As an inspiration I may suggest to look at &lt;a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2020/p1709r2.pdf"&gt;&amp;quot;P1709R2:
Graph Library&amp;quot;&lt;/a&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;- the C++ proposal. 
&lt;/p&gt;
&lt;br /&gt;
&lt;b&gt;Michael Kay&lt;/b&gt; 
&lt;p&gt;
I have for many years found it frustrating that XML is confined to hierarchic relationships
(things like IDREF and XLink are clumsy workarounds); also the fact that the arbitrary
division of data into &amp;quot;documents&amp;quot; plays such a decisive role: documents
should only exist in the serialized representation of the model, not in the model
itself. 
&lt;/p&gt;
&lt;p&gt;
I started my career working with the Codasyl-defined network data model. It&amp;#39;s
a fine and very flexible data model; its downfall was the (DOM-like) procedural navigation
language. So I&amp;#39;ve often wondered what one could do trying to re-invent the Codasyl
model in a more modern idiom, coupling it with an XPath-like declarative access language
extended to handle networks (graphs) rather than hierarchies. 
&lt;/p&gt;
&lt;p&gt;
I&amp;#39;ve no idea how close a reinventiion of Codasyl would be to some of the modern
graph data models; it would be interesting to see. The other interesting aspect of
this is whether you can make it work for schema-less data. 
&lt;/p&gt;
&lt;p&gt;
But I don&amp;#39;t think that would be an incremental evolution of XSLT; I think it would
be something completely new. 
&lt;/p&gt;
&lt;br /&gt;
&lt;b&gt;A&amp;V&lt;/b&gt; 
&lt;p&gt;
I was not so radical in my thoughts. &lt;img alt=":-)" src="http://www.nesterovsky-bros.com/weblog/smilies/happy.gif"&gt; 
&lt;/p&gt;
&lt;p&gt;
Even C++ API is not so radical, as they do not impose hard requirements on internal
graph representation but rather define template API that will work both with third
party representations (they even mention Fortran) or several built-in implementations
that uses standard vectors. 
&lt;/p&gt;
&lt;p&gt;
Their strong point is in algorithms provided as part of library and not graph internal
structure (I think authors of that paper have structured it not the best way). E.g.
in the second part they list graph algorithms: Depth First Search (DFS); Breadth First
Search (BFS); Topological Sort (TopoSort); Shortest Paths Algorithms; Dijkstra Algorithms;
and so on. 
&lt;/p&gt;
&lt;p&gt;
If we shall try to map it to xpath world them graph on API level might be represented
as a user function or as a map of user functions. 
&lt;/p&gt;
&lt;p&gt;
On a storage level user may implement graph using a sequence of maps or map of maps,
or even using xdm elements. 
&lt;/p&gt;
&lt;p&gt;
So, my approach is evolutional. In fact I suggest pure API that could even be implemented
now. 
&lt;/p&gt;
&lt;br /&gt;
&lt;b&gt;Michael Kay&lt;/b&gt; 
&lt;p&gt;
Yes, there&amp;#39;s certainly scope for graph-oriented functions such as &lt;code&gt;closure($origin,
$function)&lt;/code&gt; and &lt;code&gt;is-reachable($origin, $function)&lt;/code&gt; and &lt;code&gt;find-path($origin,
$destination, $function)&lt;/code&gt; where we use the existing data model, treating any
item as a node in a graph, and representing the arcs using functions. There are a
few complications, e.g. what&amp;#39;s the identity comparison between arbitrary items,
but it can probably be done. 
&lt;/p&gt;
&lt;br /&gt;
&lt;b&gt;A&amp;V&lt;/b&gt; &lt;blockquote&gt; &gt; There are a few complications, e.g. what&amp;#39;s the identity
comparison between arbitrary items, but it can probably be done. &lt;/blockquote&gt; 
&lt;p&gt;
One approach to address this is through definition of graph API. E.g. to define graph
as a map (interface analogy) of functions, with equality functions, if required: 
&lt;/p&gt;
&lt;pre&gt;map
{
  vertices: function(),
  edges: function(),
  value: function(vertex),
  in-vertex: function(edge),
  out-vertex: function(edge),
  edges: function(vertex),
  is-in-vertex: function(edge, vertex),
  is-out-vertex: function(edge, vertex)
  ...
}&lt;/pre&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
Not sure how far this will go but who knows. 
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=57573dd7-7ec0-47e3-891e-aa186277e0f2" /&gt;</description>
      <comments>http://www.nesterovsky-bros.com/weblog/CommentView,guid,57573dd7-7ec0-47e3-891e-aa186277e0f2.aspx</comments>
      <category>Thinking aloud</category>
      <category>xslt</category>
    </item>
    <item>
      <trackback:ping>http://www.nesterovsky-bros.com/weblog/Trackback.aspx?guid=2aaf8fdd-8795-43a8-a35d-c2710d017607</trackback:ping>
      <pingback:server>http://www.nesterovsky-bros.com/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,2aaf8fdd-8795-43a8-a35d-c2710d017607.aspx</pingback:target>
      <dc:creator>Arthur Nesterovsky</dc:creator>
      <georss:point>0 0</georss:point>
      <wfw:commentRss>http://www.nesterovsky-bros.com/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=2aaf8fdd-8795-43a8-a35d-c2710d017607</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
It's not a secret that COVID-19 epidemic will change our world significantly. <img alt="picture more than 30 years ago" src="https://phasechange.ai/wp-content/uploads/2018/10/are-you-a-cobol-programmer-dinosaur-11-4-97_20181012_tje.png" style="float: left; width: 350px;" />It
impacts on economics and public services, especially on social services of our countries.
We saw this in our country and now the same happens in US. Probably the same thing
happens in all countries all over the world that suffer from COVID-19.
</p>
        <p>
Usually, nowadays, such services are exposed online, but nobody expected such extreme
loading of these services. And they start molder under such load. Programs start crash...
and somebody has to fix them. It's just a temporary technical inconvenience when there
is staff that familiar with such programs and technologies, but what about situation
when programs and technologies are obsolete? When staff that may support them are
about to retire due to ages, when knowledge were almost lost... It's very scary when
such applications rules very important spheres of our life such social services, finances,
medicine, defence etc. Something similar happened in US, so US government asked IBM
about a help with their stuff written in COBOL.
</p>
        <p>
Probably, in short term, they'll close the gaps, but taking in account the fact that
epidemic won't dissolve in a month, there is a risk to still in the same hole... There
are two ways to solve this issue in long term:
</p>
        <ol>
          <li>
to make COBOL widely used program language and to teach enough programmers that will
use it. This is exactly what IBM tries to do, see <a href="https://www.techspot.com/news/84796-us-states-desperate-cobol-programmers-ibm-offering-free.html" target="_blank">this
article</a>, but this way to nowhere, since it is not too popular in society of software
developers. 
</li>
          <li>
to migrate such application to new technologies and new platform (e.g. Java or C#
on UNIX/Windows). In this case organizations obtain scalable applications and ability
to find human resources that may fix/modernize such applications step by step, in
spare time, without loosing existing functionality. This is what our company <a href="http://www.oneadvanced.com" target="_blank"><b>Advanced</b></a> may
provide. And we are not alone. There are many such companies that may implement such
migration on high level of quality. 
</li>
        </ol>
        <p>
And many professionals (even those that deal with COBOL on day by day basis) think
that only 2nd way is viable. Let's see what will happen... More about the issue, see <a href="https://arstechnica.com/tech-policy/2020/04/ibm-scrambles-to-find-or-train-more-cobol-programmers-to-help-states" target="_blank">here</a>.
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=2aaf8fdd-8795-43a8-a35d-c2710d017607" />
      </body>
      <title>COBOL - raise from the dead or RIP?</title>
      <guid isPermaLink="false">http://www.nesterovsky-bros.com/weblog/PermaLink,guid,2aaf8fdd-8795-43a8-a35d-c2710d017607.aspx</guid>
      <link>http://www.nesterovsky-bros.com/weblog/2020/04/15/COBOLRaiseFromTheDeadOrRIP.aspx</link>
      <pubDate>Wed, 15 Apr 2020 06:00:51 GMT</pubDate>
      <description>&lt;p&gt;
It's not a secret that COVID-19 epidemic will change our world significantly. &lt;img alt="picture more than 30 years ago" src="https://phasechange.ai/wp-content/uploads/2018/10/are-you-a-cobol-programmer-dinosaur-11-4-97_20181012_tje.png" style="float: left; width: 350px;" /&gt;It
impacts on economics and public services, especially on social services of our countries.
We saw this in our country and now the same happens in US. Probably the same thing
happens in all countries all over the world that suffer from COVID-19.
&lt;/p&gt;
&lt;p&gt;
Usually, nowadays, such services are exposed online, but nobody expected such extreme
loading of these services. And they start molder under such load. Programs start crash...
and somebody has to fix them. It's just a temporary technical inconvenience when there
is staff that familiar with such programs and technologies, but what about situation
when programs and technologies are obsolete? When staff that may support them are
about to retire due to ages, when knowledge were almost lost... It's very scary when
such applications rules very important spheres of our life such social services, finances,
medicine, defence etc. Something similar happened in US, so US government asked IBM
about a help with their stuff written in COBOL.
&lt;/p&gt;
&lt;p&gt;
Probably, in short term, they'll close the gaps, but taking in account the fact that
epidemic won't dissolve in a month, there is a risk to still in the same hole... There
are two ways to solve this issue in long term:
&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
to make COBOL widely used program language and to teach enough programmers that will
use it. This is exactly what IBM tries to do, see &lt;a href="https://www.techspot.com/news/84796-us-states-desperate-cobol-programmers-ibm-offering-free.html" target="_blank"&gt;this
article&lt;/a&gt;, but this way to nowhere, since it is not too popular in society of software
developers. 
&lt;/li&gt;
&lt;li&gt;
to migrate such application to new technologies and new platform (e.g. Java or C#
on UNIX/Windows). In this case organizations obtain scalable applications and ability
to find human resources that may fix/modernize such applications step by step, in
spare time, without loosing existing functionality. This is what our company &lt;a href="http://www.oneadvanced.com" target="_blank"&gt;&lt;b&gt;Advanced&lt;/b&gt;&lt;/a&gt; may
provide. And we are not alone. There are many such companies that may implement such
migration on high level of quality. 
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;
And many professionals (even those that deal with COBOL on day by day basis) think
that only 2nd way is viable. Let's see what will happen... More about the issue, see &lt;a href="https://arstechnica.com/tech-policy/2020/04/ibm-scrambles-to-find-or-train-more-cobol-programmers-to-help-states" target="_blank"&gt;here&lt;/a&gt;.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=2aaf8fdd-8795-43a8-a35d-c2710d017607" /&gt;</description>
      <comments>http://www.nesterovsky-bros.com/weblog/CommentView,guid,2aaf8fdd-8795-43a8-a35d-c2710d017607.aspx</comments>
      <category>Thinking aloud</category>
    </item>
    <item>
      <trackback:ping>http://www.nesterovsky-bros.com/weblog/Trackback.aspx?guid=2d7b9eb9-ad1b-40fa-9a55-f5afa260b2a8</trackback:ping>
      <pingback:server>http://www.nesterovsky-bros.com/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,2d7b9eb9-ad1b-40fa-9a55-f5afa260b2a8.aspx</pingback:target>
      <dc:creator>Vladimir Nesterovsky</dc:creator>
      <georss:point>0 0</georss:point>
      <wfw:commentRss>http://www.nesterovsky-bros.com/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=2d7b9eb9-ad1b-40fa-9a55-f5afa260b2a8</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
People compare these two technologies, and it seems an established fact is that Angular
is evolutionally more advanced framework. We're not going to contradict, contrary,
we agree with it, but it's better for an opinion to be grounded on facts that
one can evaluate and verify.
</p>
        <p>
Fortunately we got a chance to make such a comparison.
</p>
        <p>
We support conversions of <a href="https://en.wikipedia.org/wiki/CA_Gen">Cool:GEN</a> (a
legacy <a href="https://en.wikipedia.org/wiki/Computer-aided_software_engineering">CASE</a> tool
with roots in 80th) to java or C#. In its time Cool:GEN allowed to greatly automate
enterprise development using Mainframes as a server side and Mainframe terminals or
Win32 GUIs as clients.
</p>
        <p>
The legacy of this tool are probably hundreds of business and database models, milions
of programs generated on COBOL on Mainframes and on C or Java on Windows and Linux.
All this runs to this time in many econimic sectors.
</p>
        <p>
Usually the client is some enterprise that invested a lot into design, development
and support of their business model using Cool:GEN but now most such clients a trying
not to lose this legacy but to convert it into something that goes in parallel with
todays technologies.
</p>
        <p>
As original technology is sound, so it is possible to map it to todays Java or C#
on server, REST or SOAP as a transport, and Angular, AngularJS or some other on client.
Such automatic conversion is an essense of our conversions efforts.
</p>
        <p>
To understand a scope consider a typical enterprise client that has 2-3 thousand windows
that are backed by 20-30 thousand programs.
</p>
        <p>
Now, consider that the conversion is done. On output among other things we produce
a clean java or C# web application with REST and SOAP interface, and Angular or AngularJS
web client that encapsulates those 2-3 thousand windows.
</p>
        <p>
Each window definition is rather small 5-10 KB in html form, but whole mass of windows
takes 10-30 MB, which is not small any more.
</p>
        <p>
For AngularJS we generate just those html templates, but for Angular we need to generate
separate components for each window that includes typescript class, template and style.
</p>
        <p>
While amout of generated resource for AngularJS stays in those 10-30 MB, generated
Angular takes at least 5-10 MB more.
</p>
        <p>
The next step is build. 
</p>
        <p>
AngularJS builds distribution that includes all used libraries and a set of templates,
and it takes something like a minute from the CPU. Produced output is about 300 KB
minified script and those 10-30 MB of templates (multiple files with 5-10 KB each
one).
</p>
        <p>
Angular (here we talk about version 9) builds distribution that includes all used
libraries and a set of compiled components that are to be loaded lazily on demand.
Without of the both angular builder that performs tree shaking build takes days. With
tree shaking off it takes 40 minutes. This is the first notable difference. Produced
output for ES2015 (latest javascript) is about 1 MB, and 15-100 KB per each compiled
component. This is the second notable difference that already impacts end user rather
than developer.
</p>
        <p>
The third difference is in the end user experience. Though we have built equalvalent
Angular and AngularJS frontend we observe load time of angular is higher. This cannot
only be ascribed to bigger file sizes. It seems internal initialization also takes
more time for Angular.
</p>
        <p>
So, our experience in this particular test shows that Angular has more room to improve.
In particular: compile time, bundle size, runtime speed and simplicity of dynamic
loading (we have strong cases when template compilation is not the best approach).
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=2d7b9eb9-ad1b-40fa-9a55-f5afa260b2a8" />
      </body>
      <title>Angular vs AngularJS. Practical comparison.</title>
      <guid isPermaLink="false">http://www.nesterovsky-bros.com/weblog/PermaLink,guid,2d7b9eb9-ad1b-40fa-9a55-f5afa260b2a8.aspx</guid>
      <link>http://www.nesterovsky-bros.com/weblog/2020/04/04/AngularVsAngularJSPracticalComparison.aspx</link>
      <pubDate>Sat, 04 Apr 2020 12:37:15 GMT</pubDate>
      <description>  &lt;p&gt;
People compare these two technologies, and it seems an established fact is that Angular
is evolutionally more advanced framework. We&amp;#39;re not going to contradict, contrary,
we agree with it, but it&amp;#39;s better for an opinion to be grounded on facts that
one can evaluate and verify.
&lt;/p&gt;
&lt;p&gt;
Fortunately we got a chance to make such a comparison.
&lt;/p&gt;
&lt;p&gt;
We support conversions of &lt;a href="https://en.wikipedia.org/wiki/CA_Gen"&gt;Cool:GEN&lt;/a&gt; (a
legacy &lt;a href="https://en.wikipedia.org/wiki/Computer-aided_software_engineering"&gt;CASE&lt;/a&gt; tool
with roots in 80th) to java or C#. In its time Cool:GEN allowed to greatly automate
enterprise development using Mainframes as a server side and Mainframe terminals or
Win32 GUIs as clients.
&lt;/p&gt;
&lt;p&gt;
The legacy of this tool are probably hundreds of business and database models, milions
of programs generated on COBOL on Mainframes and on C or Java on Windows and Linux.
All this runs to this time in many econimic sectors.
&lt;/p&gt;
&lt;p&gt;
Usually the client is some enterprise that invested a lot into design, development
and support of their business model using Cool:GEN but now most such clients a trying
not to lose this legacy but to convert it into something that goes in parallel with
todays technologies.
&lt;/p&gt;
&lt;p&gt;
As original technology is sound, so it is possible to map it to todays Java or C#
on server, REST or SOAP as a transport, and Angular, AngularJS or some other on client.
Such automatic conversion is an essense of our conversions efforts.
&lt;/p&gt;
&lt;p&gt;
To understand a scope consider a typical enterprise client that has 2-3 thousand windows
that are backed by 20-30 thousand programs.
&lt;/p&gt;
&lt;p&gt;
Now, consider that the conversion is done. On output among other things we produce
a clean java or C# web application with REST and SOAP interface, and Angular or AngularJS
web client that encapsulates those 2-3 thousand windows.
&lt;/p&gt;
&lt;p&gt;
Each window definition is rather small 5-10 KB in html form, but whole mass of windows
takes 10-30 MB, which is not small any more.
&lt;/p&gt;
&lt;p&gt;
For AngularJS we generate just those html templates, but for Angular we need to generate
separate components for each window that includes typescript class, template and style.
&lt;/p&gt;
&lt;p&gt;
While amout of generated resource for AngularJS stays in those 10-30 MB, generated
Angular takes at least 5-10 MB more.
&lt;/p&gt;
&lt;p&gt;
The next step is build. 
&lt;/p&gt;
&lt;p&gt;
AngularJS builds distribution that includes all used libraries and a set of templates,
and it takes something like a minute from the CPU. Produced output is about 300 KB
minified script and those 10-30 MB of templates (multiple files with 5-10 KB each
one).
&lt;/p&gt;
&lt;p&gt;
Angular (here we talk about version 9) builds distribution that includes all used
libraries and a set of compiled components that are to be loaded lazily on demand.
Without of the both angular builder that performs tree shaking build takes days. With
tree shaking off it takes 40 minutes. This is the first notable difference. Produced
output for ES2015 (latest javascript) is about 1 MB, and 15-100 KB per each compiled
component. This is the second notable difference that already impacts end user rather
than developer.
&lt;/p&gt;
&lt;p&gt;
The third difference is in the end user experience. Though we have built equalvalent
Angular and AngularJS frontend we observe load time of angular is higher. This cannot
only be ascribed to bigger file sizes. It seems internal initialization also takes
more time for Angular.
&lt;/p&gt;
&lt;p&gt;
So, our experience in this particular test shows that Angular has more room to improve.
In particular: compile time, bundle size, runtime speed and simplicity of dynamic
loading (we have strong cases when template compilation is not the best approach).
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=2d7b9eb9-ad1b-40fa-9a55-f5afa260b2a8" /&gt;</description>
      <comments>http://www.nesterovsky-bros.com/weblog/CommentView,guid,2d7b9eb9-ad1b-40fa-9a55-f5afa260b2a8.aspx</comments>
      <category>AngularJS</category>
      <category>Java</category>
      <category>Thinking aloud</category>
      <category>Tips and tricks</category>
    </item>
    <item>
      <trackback:ping>http://www.nesterovsky-bros.com/weblog/Trackback.aspx?guid=d7ee8d6a-1d30-4d18-ac5d-463f5b3afceb</trackback:ping>
      <pingback:server>http://www.nesterovsky-bros.com/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,d7ee8d6a-1d30-4d18-ac5d-463f5b3afceb.aspx</pingback:target>
      <dc:creator>Vladimir Nesterovsky</dc:creator>
      <georss:point>0 0</georss:point>
      <wfw:commentRss>http://www.nesterovsky-bros.com/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=d7ee8d6a-1d30-4d18-ac5d-463f5b3afceb</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Yesterday we run into another Saxon bug. See <a href="https://saxonica.plan.io/issues/4449" target="_blank">NPE
in CaseVariants</a>.
</p>
        <p>
The problem happened just once and never reproduced. Inspection of Saxon sources hinted
that it can be a race condition.
</p>
        <p>
Michael Kay agreed with our conclusion and fixed the problem in the code along with
several other similar places.
</p>
        <p>
It is such rare kind of bug that it might appear once during whole product life cycle.
So, we may consider the fix is personal. <img alt=":-)" src="http://www.nesterovsky-bros.com/weblog/smilies/happy.gif" /></p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=d7ee8d6a-1d30-4d18-ac5d-463f5b3afceb" />
      </body>
      <title>Another help to Saxon project</title>
      <guid isPermaLink="false">http://www.nesterovsky-bros.com/weblog/PermaLink,guid,d7ee8d6a-1d30-4d18-ac5d-463f5b3afceb.aspx</guid>
      <link>http://www.nesterovsky-bros.com/weblog/2020/02/03/AnotherHelpToSaxonProject.aspx</link>
      <pubDate>Mon, 03 Feb 2020 06:36:00 GMT</pubDate>
      <description>  &lt;p&gt;
Yesterday we run into another Saxon bug. See &lt;a href="https://saxonica.plan.io/issues/4449" target="_blank"&gt;NPE
in CaseVariants&lt;/a&gt;.
&lt;/p&gt;
&lt;p&gt;
The problem happened just once and never reproduced. Inspection of Saxon sources hinted
that it can be a race condition.
&lt;/p&gt;
&lt;p&gt;
Michael Kay agreed with our conclusion and fixed the problem in the code along with
several other similar places.
&lt;/p&gt;
&lt;p&gt;
It is such rare kind of bug that it might appear once during whole product life cycle.
So, we may consider the fix is personal. &lt;img alt=":-)" src="http://www.nesterovsky-bros.com/weblog/smilies/happy.gif"&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=d7ee8d6a-1d30-4d18-ac5d-463f5b3afceb" /&gt;</description>
      <comments>http://www.nesterovsky-bros.com/weblog/CommentView,guid,d7ee8d6a-1d30-4d18-ac5d-463f5b3afceb.aspx</comments>
    </item>
    <item>
      <trackback:ping>http://www.nesterovsky-bros.com/weblog/Trackback.aspx?guid=861382a1-a2b8-4b39-a9f4-1f7a2148bf59</trackback:ping>
      <pingback:server>http://www.nesterovsky-bros.com/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,861382a1-a2b8-4b39-a9f4-1f7a2148bf59.aspx</pingback:target>
      <dc:creator>Vladimir Nesterovsky</dc:creator>
      <georss:point>0 0</georss:point>
      <wfw:commentRss>http://www.nesterovsky-bros.com/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=861382a1-a2b8-4b39-a9f4-1f7a2148bf59</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
We were asked to help with search service in one enterprise. We were told that their
SharePoint portal does not serve their need. Main complaints were about the quality
of search results.
</p>
        <p>
They have decided to implement external index of SharePoint content, using <a href="https://www.elastic.co/">Elastic</a>,
and expose custom search API within the enterprise.
</p>
        <p>
        </p>
        <p>
We questioned their conclusions, asked why did they think Elastic will give much better
results, asked did they try to figure out why SharePoint give no desired results.
</p>
        <p>
Answers did not convince us though we have joined the project.
</p>
        <p>
        </p>
        <p>
What do you think? Elastic did not help at all though they hoped very much that its
query language will help to rank results in a way that matched documents will be found.
After all they thought it was a problem of ranking of results.
</p>
        <p>
        </p>
        <p>
Here we have started our analysis. We took a specific document that must be found
but is never returned from search.
</p>
        <p>
        </p>
        <p>
It turned to be well known problem, at least we dealt with closely related one in
the past. There are two ingredients here:
</p>
        <ul>
          <li>
documents that have low chances to be found are PDFs;</li>
          <li>
we live in Israel, so most texts are Hebrew, which means words are written from right
to left, while some other texts from left to right. See <a href="https://en.wikipedia.org/wiki/Bi-directional_text" target="_blank">Bi-directional
text</a>.</li>
        </ul>
        <p>
Traditionally PDF documents are provided in a way that only distantly resembles logical
structure of original content. E.g., paragraphs of texts are often represented as
unrelated runs of text lines, or as set of text runs representing single words, or
independant characters. No need to say that additional complication comes from that
Hebrew text are often represented visually (from left to right, as if "hello"
would be stored as "olleh" and would be just printed from right to left).
Another common feature of PDF are custom fonts with uncanonical mappings, or images
with glyphs of letters.
</p>
        <p>
You can implement these tricks in other document formats but for some reason PDF is
only format we have seen that regularly and intensively uses these techniques.
</p>
        <p>
        </p>
        <p>
At this point we have realized that it's not a fault of a search engine to find
the document but the feature of the PDF to expose its text to a crawler in a form
that cannot be used for search. In fact, PDF cannot search by itself in such documents,
as when you try to find some text in the document opened in a pdf viewer, that you
clearly see in the document, you often find nothing.
</p>
        <p>
        </p>
        <p>
A question. What should you do in this case when no any PDF text extractor can give
you correct text but text is there when you looking at document in a pdf viewer?
</p>
        <p>
        </p>
        <p>
We decided it's time to go in the direction of image recognition. Thankfully,
nowdays it's a matter of available processing resources.
</p>
        <p>
Our goal was:
</p>
        <ol>
          <li>
Have images of each PDF page. This task is immediately solved with <a href="https://pdfbox.apache.org/" target="_blank">Apache
PDFBox (A Java PDF Library) - it's time to say this is java project.</a></li>
          <li>
Run Optical Character Recognition (OCR) over images, and get extracted texts. This
is perfectly done by <a href="https://github.com/tesseract-ocr/tesseract" target="_blank">tesseract-ocr/tesseract</a>,
and thankfully to its java wrapper <a href="https://github.com/bytedeco/javacpp-presets/tree/master/tesseract" target="_blank">bytedeco/javacpp-presets</a> we
can immediately call this C++ API from java.</li>
        </ol>
        <p>
The only small nuisance of tesseract is that it does not expose table recognition
info, but we can easily overcome it (we solved this task in the past), as along with
each text run tesseract exposes its position.
</p>
        <p>
        </p>
        <p>
What are results of the run of such program?
</p>
        <ol>
          <li>
Full success! It works with high quality of recognition. Indeed, there is no any physical
noise that impacts quality.</li>
          <li>
Slow speed - up to several seconds per recognition per page.</li>
          <li>
Scalable solution. Slow speed can be compensated by almost unlimited theoretical scalability.</li>
        </ol>
        <p>
        </p>
        <p>
So, what is the lesson we have taked from this experience?
</p>
        <p>
        </p>
        <p>
Well, you should question yourself, test and verify ideas on the ground before building
any theories that will lead you in completely wrong direction. After all people started
to realize there was no need to claim on SharePoint, to throw it, and to spend great
deal of time and money just to prove that the problem is in the different place.
</p>
        <p>
A sample source code can be found at <a href="https://github.com/nesterovsky-bros/pdf.ocr/blob/master/src/main/java/nesterovskyBros/pdf/ocr/App.java" target="_blank">App.java</a></p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=861382a1-a2b8-4b39-a9f4-1f7a2148bf59" />
      </body>
      <title>Theory vs practice</title>
      <guid isPermaLink="false">http://www.nesterovsky-bros.com/weblog/PermaLink,guid,861382a1-a2b8-4b39-a9f4-1f7a2148bf59.aspx</guid>
      <link>http://www.nesterovsky-bros.com/weblog/2019/07/26/TheoryVsPractice.aspx</link>
      <pubDate>Fri, 26 Jul 2019 16:38:11 GMT</pubDate>
      <description>&lt;p&gt;
We were asked to help with search service in one enterprise. We were told that their
SharePoint portal does not serve their need. Main complaints were about the quality
of search results.
&lt;/p&gt;
&lt;p&gt;
They have decided to implement external index of SharePoint content, using &lt;a href="https://www.elastic.co/"&gt;Elastic&lt;/a&gt;,
and expose custom search API within the enterprise.
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
We questioned their conclusions, asked why did they think Elastic will give much better
results, asked did they try to figure out why SharePoint give no desired results.
&lt;/p&gt;
&lt;p&gt;
Answers did not convince us though we have joined the project.
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
What do you think? Elastic did not help at all though they hoped very much that its
query language will help to rank results in a way that matched documents will be found.
After all they thought it was a problem of ranking of results.
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
Here we have started our analysis. We took a specific document that must be found
but is never returned from search.
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
It turned to be well known problem, at least we dealt with closely related one in
the past. There are two ingredients here:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
documents that have low chances to be found are PDFs;&lt;/li&gt;
&lt;li&gt;
we live in Israel, so most texts are Hebrew, which means words are written from right
to left, while some other texts from left to right. See &lt;a href="https://en.wikipedia.org/wiki/Bi-directional_text" target="_blank"&gt;Bi-directional
text&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
Traditionally PDF documents are provided in a way that only distantly resembles logical
structure of original content. E.g., paragraphs of texts are often represented as
unrelated runs of text lines, or as set of text runs representing single words, or
independant characters. No need to say that additional complication comes from that
Hebrew text are often represented visually (from left to right, as if &amp;quot;hello&amp;quot;
would be stored as &amp;quot;olleh&amp;quot; and would be just printed from right to left).
Another common feature of PDF are custom fonts with uncanonical mappings, or images
with glyphs of letters.
&lt;/p&gt;
&lt;p&gt;
You can implement these tricks in other document formats but for some reason PDF is
only format we have seen that regularly and intensively uses these techniques.
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
At this point we have realized that it&amp;#39;s not a fault of a search engine to find
the document but the feature of the PDF to expose its text to a crawler in a form
that cannot be used for search. In fact, PDF cannot search by itself in such documents,
as when you try to find some text in the document opened in a pdf viewer, that you
clearly see in the document, you often find nothing.
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
A question. What should you do in this case when no any PDF text extractor can give
you correct text but text is there when you looking at document in a pdf viewer?
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
We decided it&amp;#39;s time to go in the direction of image recognition. Thankfully,
nowdays it&amp;#39;s a matter of available processing resources.
&lt;/p&gt;
&lt;p&gt;
Our goal was:
&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
Have images of each PDF page. This task is immediately solved with &lt;a href="https://pdfbox.apache.org/" target="_blank"&gt;Apache
PDFBox (A Java PDF Library) - it's time to say this is java project.&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
Run Optical Character Recognition (OCR) over images, and get extracted texts. This
is perfectly done by &lt;a href="https://github.com/tesseract-ocr/tesseract" target="_blank"&gt;tesseract-ocr/tesseract&lt;/a&gt;,
and thankfully to its java wrapper &lt;a href="https://github.com/bytedeco/javacpp-presets/tree/master/tesseract" target="_blank"&gt;bytedeco/javacpp-presets&lt;/a&gt; we
can immediately call this C++ API from java.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;
The only small nuisance of tesseract is that it does not expose table recognition
info, but we can easily overcome it (we solved this task in the past), as along with
each text run tesseract exposes its position.
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
What are results of the run of such program?
&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
Full success! It works with high quality of recognition. Indeed, there is no any physical
noise that impacts quality.&lt;/li&gt;
&lt;li&gt;
Slow speed - up to several seconds per recognition per page.&lt;/li&gt;
&lt;li&gt;
Scalable solution. Slow speed can be compensated by almost unlimited theoretical scalability.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
So, what is the lesson we have taked from this experience?
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
Well, you should question yourself, test and verify ideas on the ground before building
any theories that will lead you in completely wrong direction. After all people started
to realize there was no need to claim on SharePoint, to throw it, and to spend great
deal of time and money just to prove that the problem is in the different place.
&lt;/p&gt;
&lt;p&gt;
A sample source code can be found at &lt;a href="https://github.com/nesterovsky-bros/pdf.ocr/blob/master/src/main/java/nesterovskyBros/pdf/ocr/App.java" target="_blank"&gt;App.java&lt;/a&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=861382a1-a2b8-4b39-a9f4-1f7a2148bf59" /&gt;</description>
      <comments>http://www.nesterovsky-bros.com/weblog/CommentView,guid,861382a1-a2b8-4b39-a9f4-1f7a2148bf59.aspx</comments>
      <category>C++</category>
      <category>Java</category>
      <category>Thinking aloud</category>
      <category>Tips and tricks</category>
    </item>
    <item>
      <trackback:ping>http://www.nesterovsky-bros.com/weblog/Trackback.aspx?guid=6b76a0f7-4eee-4023-8f67-781c38550685</trackback:ping>
      <pingback:server>http://www.nesterovsky-bros.com/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,6b76a0f7-4eee-4023-8f67-781c38550685.aspx</pingback:target>
      <dc:creator>Vladimir Nesterovsky</dc:creator>
      <georss:point>0 0</georss:point>
      <wfw:commentRss>http://www.nesterovsky-bros.com/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=6b76a0f7-4eee-4023-8f67-781c38550685</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
This story started half year ago when Michael Kay, author of Saxon XSLT processor,
was dealing with performance in multithreaded environment. See <a href="https://saxonica.plan.io/issues/3958">Bug
#3958</a>.
</p>
        <p>
The problem is like this.
</p>
        <p>
Given XSLT:
</p>
        <blockquote>
          <pre>&lt;xsl:stylesheet exclude-result-prefixes="#all" 
  version="3.0" 
  xmlns:saxon="http://saxon.sf.net/"
  xmlns:xs="http://www.w3.org/2001/XMLSchema" 
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;

  &lt;xsl:output method="text" /&gt;

  &lt;xsl:template name="main"&gt;
    &lt;xsl:for-each saxon:threads="4" select="1 to 10"&gt;
      &lt;xsl:choose&gt;
        &lt;xsl:when test=". eq 1"&gt;
          &lt;!-- Will take 10 seconds --&gt;
          &lt;xsl:sequence select="
            json-doc('https://httpbin.org/delay/10')?url"/&gt;
        &lt;/xsl:when&gt;
        &lt;xsl:when test=". eq 5"&gt;
          &lt;!-- Will take 9 seconds --&gt;
          &lt;xsl:sequence select="
            json-doc('https://httpbin.org/delay/9')?url"/&gt;
        &lt;/xsl:when&gt;
        &lt;xsl:when test=". eq 10"&gt;
          &lt;!-- Will take 8 seconds --&gt;
          &lt;xsl:sequence select="
            json-doc('https://httpbin.org/delay/8')?url"/&gt;
        &lt;/xsl:when&gt;
      &lt;/xsl:choose&gt;
    &lt;/xsl:for-each&gt;
    &lt;xsl:text&gt;
&lt;/xsl:text&gt;
  &lt;/xsl:template&gt;
&lt;/xsl:stylesheet&gt;</pre>
        </blockquote>
        <p>
Implement engine to achieve best performance of parallel for-each. 
</p>
        <p>
Naive implementation that will distribute iterations per threads will run into unfair
load on threads, so some load-balancing is required. That was the case Saxon EE. 
</p>
        <p>
Michael Kay has been trying to find most elegant way for the implementation and has
written the comment: 
</p>
        <blockquote>
          <i>I can't help feeling that the answer to this must lie in using the
Streams machinery, and Spliterators in particular. I've spent another hour or so reading
all about Spliterators, and I have to confess I really don't understand the paradigm.
If someone can enlighten me, please go ahead...</i>
        </blockquote>
        <p>
We have decided to take the challange and to model the expected behavior using Streams.
Here is our go: 
</p>
        <blockquote>
          <pre>import java.util.stream.IntStream;
import java.util.stream.Stream;
import java.util.function.Consumer;
import java.util.function.Function;

public class Streams
{
  public static class Item&lt;T&gt;
  {
    public Item(int index, T data)
    {
      this.index = index;
      this.data = data;
    }
    
    int index;
    T data;
  }

  public static void main(String[] args)
  {
    run(
      "Sequential",
      input(),
      Streams::action,
      Streams::output,
      true);
    
    run(
      "Parallel ordered", 
      input().parallel(),
      Streams::action,
      Streams::output,
      true);
    
    run(
      "Parallel unordered", 
      input().parallel(),
      Streams::action,
      Streams::output,
      false);    
  }
  
  private static void run(
    String description,
    Stream&lt;Item&lt;String&gt;&gt; input,
    Function&lt;Item&lt;String&gt;, String[]&gt; action,
    Consumer&lt;String[]&gt; output,
    boolean ordered)
  {
    System.out.println(description);
    
    long start = System.currentTimeMillis();
   
    if (ordered)
    {
      input.map(action).forEachOrdered(output);
    }
    else
    {
      input.map(action).forEach(output);
    }
    
    long end = System.currentTimeMillis();
    
    System.out.println("Execution time: " + (end - start) + "ms.");
    System.out.println();
  }
  
  private static Stream&lt;Item&lt;String&gt;&gt; input()
  {
    return IntStream.range(0, 10).
      mapToObj(i -&gt; new Item&lt;String&gt;(i + 1, "Data " + (i + 1)));
  }
  
  private static String[] action(Item&lt;String&gt; item)
  {
    switch(item.index)
    {
      case 1:
      {
        sleep(10);
        
        break;
      }
      case 5:
      {
        sleep(9);
        
        break;
      }
      case 10:
      {
        sleep(8);
        
        break;
      }
      default:
      {
        sleep(1);
        
        break;
      }
    }
    
    String[] result = { "data:", item.data, "index:", item.index + "" };
    
    return result;
  }
  
  private synchronized static void output(String[] value)
  {
    boolean first = true;
    
    for(String item: value)
    {
      if (first)
      {
        first = false;
      }
      else
      {
        System.out.print(' ');
      }
    
      System.out.print(item);
    }

    System.out.println();
  }
  
  private static void sleep(int seconds)
  {
    try
    {
      Thread.sleep(seconds * 1000);
    }
    catch(InterruptedException e)
    {
      throw new IllegalStateException(e);
    }
  }
}</pre>
        </blockquote>
        <p>
We model three cases:
</p>
        <dl>
          <dt>"Sequential"</dt>
          <dd>
slowest, single threaded execution with output: <pre>data: Data 1 index: 1
data: Data 2 index: 2
data: Data 3 index: 3
data: Data 4 index: 4
data: Data 5 index: 5
data: Data 6 index: 6
data: Data 7 index: 7
data: Data 8 index: 8
data: Data 9 index: 9
data: Data 10 index: 10
Execution time: 34009ms.</pre></dd>
          <dt>"Parallel ordered"</dt>
          <dd>
fast, multithread execution preserving order, with output: <pre>data: Data 1 index: 1
data: Data 2 index: 2
data: Data 3 index: 3
data: Data 4 index: 4
data: Data 5 index: 5
data: Data 6 index: 6
data: Data 7 index: 7
data: Data 8 index: 8
data: Data 9 index: 9
data: Data 10 index: 10
Execution time: 10019ms.</pre></dd>
          <dt>"Parallel unordered"</dt>
          <dd>
fastest, multithread execution not preserving order, with output: <pre>data: Data 6 index: 6
data: Data 2 index: 2
data: Data 4 index: 4
data: Data 3 index: 3
data: Data 9 index: 9
data: Data 7 index: 7
data: Data 8 index: 8
data: Data 5 index: 5
data: Data 10 index: 10
data: Data 1 index: 1
Execution time: 10001ms.</pre></dd>
        </dl>
        <p>
What we can add in conclusion is that xslt engine could try automatically decide what
approach to use, as many SQL engines are doing, and not to force developer to go into
low level engine details.
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=6b76a0f7-4eee-4023-8f67-781c38550685" />
      </body>
      <title>Scheduling algorithm for xsl:for-each/@saxon:threads=N</title>
      <guid isPermaLink="false">http://www.nesterovsky-bros.com/weblog/PermaLink,guid,6b76a0f7-4eee-4023-8f67-781c38550685.aspx</guid>
      <link>http://www.nesterovsky-bros.com/weblog/2019/03/24/SchedulingAlgorithmForXslforeachsaxonthreadsN.aspx</link>
      <pubDate>Sun, 24 Mar 2019 07:52:02 GMT</pubDate>
      <description>&lt;p&gt;
This story started half year ago when Michael Kay, author of Saxon XSLT processor,
was dealing with performance in multithreaded environment. See &lt;a href="https://saxonica.plan.io/issues/3958"&gt;Bug
#3958&lt;/a&gt;.
&lt;/p&gt;
&lt;p&gt;
The problem is like this.
&lt;/p&gt;
&lt;p&gt;
Given XSLT:
&lt;/p&gt;
&lt;blockquote&gt; &lt;pre&gt;&amp;lt;xsl:stylesheet exclude-result-prefixes="#all" 
  version="3.0" 
  xmlns:saxon="http://saxon.sf.net/"
  xmlns:xs="http://www.w3.org/2001/XMLSchema" 
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;

  &amp;lt;xsl:output method="text" /&gt;

  &amp;lt;xsl:template name="main"&gt;
    &amp;lt;xsl:for-each saxon:threads="4" select="1 to 10"&gt;
      &amp;lt;xsl:choose&gt;
        &amp;lt;xsl:when test=". eq 1"&gt;
          &amp;lt;!-- Will take 10 seconds --&gt;
          &amp;lt;xsl:sequence select="
            json-doc('https://httpbin.org/delay/10')?url"/&gt;
        &amp;lt;/xsl:when&gt;
        &amp;lt;xsl:when test=". eq 5"&gt;
          &amp;lt;!-- Will take 9 seconds --&gt;
          &amp;lt;xsl:sequence select="
            json-doc('https://httpbin.org/delay/9')?url"/&gt;
        &amp;lt;/xsl:when&gt;
        &amp;lt;xsl:when test=". eq 10"&gt;
          &amp;lt;!-- Will take 8 seconds --&gt;
          &amp;lt;xsl:sequence select="
            json-doc('https://httpbin.org/delay/8')?url"/&gt;
        &amp;lt;/xsl:when&gt;
      &amp;lt;/xsl:choose&gt;
    &amp;lt;/xsl:for-each&gt;
    &amp;lt;xsl:text&gt;&amp;#x0A;&amp;lt;/xsl:text&gt;
  &amp;lt;/xsl:template&gt;
&amp;lt;/xsl:stylesheet&gt;&lt;/pre&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
Implement engine to achieve best performance of parallel for-each. 
&lt;/p&gt;
&lt;p&gt;
Naive implementation that will distribute iterations per threads will run into unfair
load on threads, so some load-balancing is required. That was the case Saxon EE. 
&lt;/p&gt;
&lt;p&gt;
Michael Kay has been trying to find most elegant way for the implementation and has
written the comment: 
&lt;/p&gt;
&lt;blockquote&gt; &lt;i&gt;I can't help feeling that the answer to this must lie in using the
Streams machinery, and Spliterators in particular. I've spent another hour or so reading
all about Spliterators, and I have to confess I really don't understand the paradigm.
If someone can enlighten me, please go ahead...&lt;/i&gt; &lt;/blockquote&gt; 
&lt;p&gt;
We have decided to take the challange and to model the expected behavior using Streams.
Here is our go: 
&lt;/p&gt;
&lt;blockquote&gt;&lt;pre&gt;import java.util.stream.IntStream;
import java.util.stream.Stream;
import java.util.function.Consumer;
import java.util.function.Function;

public class Streams
{
  public static class Item&amp;lt;T&gt;
  {
    public Item(int index, T data)
    {
      this.index = index;
      this.data = data;
    }
    
    int index;
    T data;
  }

  public static void main(String[] args)
  {
    run(
      "Sequential",
      input(),
      Streams::action,
      Streams::output,
      true);
    
    run(
      "Parallel ordered", 
      input().parallel(),
      Streams::action,
      Streams::output,
      true);
    
    run(
      "Parallel unordered", 
      input().parallel(),
      Streams::action,
      Streams::output,
      false);    
  }
  
  private static void run(
    String description,
    Stream&amp;lt;Item&amp;lt;String&gt;&gt; input,
    Function&amp;lt;Item&amp;lt;String&gt;, String[]&gt; action,
    Consumer&amp;lt;String[]&gt; output,
    boolean ordered)
  {
    System.out.println(description);
    
    long start = System.currentTimeMillis();
   
    if (ordered)
    {
      input.map(action).forEachOrdered(output);
    }
    else
    {
      input.map(action).forEach(output);
    }
    
    long end = System.currentTimeMillis();
    
    System.out.println("Execution time: " + (end - start) + "ms.");
    System.out.println();
  }
  
  private static Stream&amp;lt;Item&amp;lt;String&gt;&gt; input()
  {
    return IntStream.range(0, 10).
      mapToObj(i -&gt; new Item&amp;lt;String&gt;(i + 1, "Data " + (i + 1)));
  }
  
  private static String[] action(Item&amp;lt;String&gt; item)
  {
    switch(item.index)
    {
      case 1:
      {
        sleep(10);
        
        break;
      }
      case 5:
      {
        sleep(9);
        
        break;
      }
      case 10:
      {
        sleep(8);
        
        break;
      }
      default:
      {
        sleep(1);
        
        break;
      }
    }
    
    String[] result = { "data:", item.data, "index:", item.index + "" };
    
    return result;
  }
  
  private synchronized static void output(String[] value)
  {
    boolean first = true;
    
    for(String item: value)
    {
      if (first)
      {
        first = false;
      }
      else
      {
        System.out.print(' ');
      }
    
      System.out.print(item);
    }

    System.out.println();
  }
  
  private static void sleep(int seconds)
  {
    try
    {
      Thread.sleep(seconds * 1000);
    }
    catch(InterruptedException e)
    {
      throw new IllegalStateException(e);
    }
  }
}&lt;/pre&gt;&lt;/blockquote&gt; 
&lt;p&gt;
We model three cases:
&lt;/p&gt;
&lt;dl&gt;
&lt;dt&gt;"Sequential"&lt;/dt&gt; 
&lt;dd&gt;
slowest, single threaded execution with output: &lt;pre&gt;data: Data 1 index: 1
data: Data 2 index: 2
data: Data 3 index: 3
data: Data 4 index: 4
data: Data 5 index: 5
data: Data 6 index: 6
data: Data 7 index: 7
data: Data 8 index: 8
data: Data 9 index: 9
data: Data 10 index: 10
Execution time: 34009ms.&lt;/pre&gt;
&lt;/dd&gt;
&lt;dt&gt;"Parallel ordered"&lt;/dt&gt; 
&lt;dd&gt;
fast, multithread execution preserving order, with output: &lt;pre&gt;data: Data 1 index: 1
data: Data 2 index: 2
data: Data 3 index: 3
data: Data 4 index: 4
data: Data 5 index: 5
data: Data 6 index: 6
data: Data 7 index: 7
data: Data 8 index: 8
data: Data 9 index: 9
data: Data 10 index: 10
Execution time: 10019ms.&lt;/pre&gt;
&lt;/dd&gt;
&lt;dt&gt;"Parallel unordered"&lt;/dt&gt; 
&lt;dd&gt;
fastest, multithread execution not preserving order, with output: &lt;pre&gt;data: Data 6 index: 6
data: Data 2 index: 2
data: Data 4 index: 4
data: Data 3 index: 3
data: Data 9 index: 9
data: Data 7 index: 7
data: Data 8 index: 8
data: Data 5 index: 5
data: Data 10 index: 10
data: Data 1 index: 1
Execution time: 10001ms.&lt;/pre&gt;
&lt;/dd&gt;
&lt;/dl&gt;
&lt;p&gt;
What we can add in conclusion is that xslt engine could try automatically decide what
approach to use, as many SQL engines are doing, and not to force developer to go into
low level engine details.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=6b76a0f7-4eee-4023-8f67-781c38550685" /&gt;</description>
      <comments>http://www.nesterovsky-bros.com/weblog/CommentView,guid,6b76a0f7-4eee-4023-8f67-781c38550685.aspx</comments>
      <category>Java</category>
      <category>Thinking aloud</category>
      <category>xslt</category>
    </item>
    <item>
      <trackback:ping>http://www.nesterovsky-bros.com/weblog/Trackback.aspx?guid=7916d7f6-9228-48f2-9b06-d2646328ec33</trackback:ping>
      <pingback:server>http://www.nesterovsky-bros.com/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,7916d7f6-9228-48f2-9b06-d2646328ec33.aspx</pingback:target>
      <dc:creator>Vladimir Nesterovsky</dc:creator>
      <georss:point>0 0</georss:point>
      <wfw:commentRss>http://www.nesterovsky-bros.com/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=7916d7f6-9228-48f2-9b06-d2646328ec33</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Recently we observed how we solved the same task in different versions of XPath: 2.0,
3.0, and 3.1.
</p>
        <p>
Consider, you have a sequence <code>$items</code>, and you want to call some function
over each item of the sequence, and to return combined result.
</p>
        <p>
In XPath 2.0 this was solved like this:
</p>
        <blockquote>
          <pre>for $item in $items return
  f:func($item)</pre>
        </blockquote>
        <p>
In XPath 3.0 this was solved like this:
</p>
        <blockquote>
          <pre>$items!f:func(.)</pre>
        </blockquote>
        <p>
And now with XPath 3.1 that defined an arrow operator =&gt; we attempted to write something
as simple as:
</p>
        <blockquote>
          <pre>$items=&gt;f:func()</pre>
        </blockquote>
        <p>
That is definitely not working, as it is the same as <code>f:func($items)</code>.
</p>
        <p>
Next attempt was:
</p>
        <blockquote>
          <pre>$items!=&gt;f:func()</pre>
        </blockquote>
        <p>
That even does not compile.
</p>
        <p>
So, finally, working expression using =&gt; looks like this:
</p>
        <blockquote>
          <pre>$items!(.=&gt;f:func())</pre>
        </blockquote>
        <p>
This looks like a step back comparing to XPath 3.0 variant.
</p>
        <p>
More than that, XPath grammar of arrow operator forbids the use of predictes, axis
or mapping operators, so this won't compile:
</p>
        <blockquote>
          <pre>$items!(.=&gt;f:func()[1])</pre>
        </blockquote>
        <blockquote>
          <pre>$items!(.=&gt;f:func()!something)</pre>
        </blockquote>
        <p>
Our conclusion is that arrow operator is rather confusing addition to XPath.
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=7916d7f6-9228-48f2-9b06-d2646328ec33" />
      </body>
      <title>XPath through evolution</title>
      <guid isPermaLink="false">http://www.nesterovsky-bros.com/weblog/PermaLink,guid,7916d7f6-9228-48f2-9b06-d2646328ec33.aspx</guid>
      <link>http://www.nesterovsky-bros.com/weblog/2018/11/03/XPathThroughEvolution.aspx</link>
      <pubDate>Sat, 03 Nov 2018 20:59:28 GMT</pubDate>
      <description>  &lt;p&gt;
Recently we observed how we solved the same task in different versions of XPath: 2.0,
3.0, and 3.1.
&lt;/p&gt;
&lt;p&gt;
Consider, you have a sequence &lt;code&gt;$items&lt;/code&gt;, and you want to call some function
over each item of the sequence, and to return combined result.
&lt;/p&gt;
&lt;p&gt;
In XPath 2.0 this was solved like this:
&lt;/p&gt;
&lt;blockquote&gt;&lt;pre&gt;for $item in $items return
  f:func($item)&lt;/pre&gt;&lt;/blockquote&gt; 
&lt;p&gt;
In XPath 3.0 this was solved like this:
&lt;/p&gt;
&lt;blockquote&gt;&lt;pre&gt;$items!f:func(.)&lt;/pre&gt;&lt;/blockquote&gt; 
&lt;p&gt;
And now with XPath 3.1 that defined an arrow operator =&gt; we attempted to write something
as simple as:
&lt;/p&gt;
&lt;blockquote&gt;&lt;pre&gt;$items=&gt;f:func()&lt;/pre&gt;&lt;/blockquote&gt; 
&lt;p&gt;
That is definitely not working, as it is the same as &lt;code&gt;f:func($items)&lt;/code&gt;.
&lt;/p&gt;
&lt;p&gt;
Next attempt was:
&lt;/p&gt;
&lt;blockquote&gt;&lt;pre&gt;$items!=&gt;f:func()&lt;/pre&gt;&lt;/blockquote&gt; 
&lt;p&gt;
That even does not compile.
&lt;/p&gt;
&lt;p&gt;
So, finally, working expression using =&gt; looks like this:
&lt;/p&gt;
&lt;blockquote&gt;&lt;pre&gt;$items!(.=&gt;f:func())&lt;/pre&gt;&lt;/blockquote&gt; 
&lt;p&gt;
This looks like a step back comparing to XPath 3.0 variant.
&lt;/p&gt;
&lt;p&gt;
More than that, XPath grammar of arrow operator forbids the use of predictes, axis
or mapping operators, so this won't compile:
&lt;/p&gt;
&lt;blockquote&gt;&lt;pre&gt;$items!(.=&gt;f:func()[1])&lt;/pre&gt;&lt;/blockquote&gt; &lt;blockquote&gt;&lt;pre&gt;$items!(.=&gt;f:func()!something)&lt;/pre&gt;&lt;/blockquote&gt; 
&lt;p&gt;
Our conclusion is that arrow operator is rather confusing addition to XPath.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=7916d7f6-9228-48f2-9b06-d2646328ec33" /&gt;</description>
      <comments>http://www.nesterovsky-bros.com/weblog/CommentView,guid,7916d7f6-9228-48f2-9b06-d2646328ec33.aspx</comments>
      <category>Thinking aloud</category>
      <category>xslt</category>
    </item>
    <item>
      <trackback:ping>http://www.nesterovsky-bros.com/weblog/Trackback.aspx?guid=2b29772d-bded-4045-b6b8-d0035cb5944f</trackback:ping>
      <pingback:server>http://www.nesterovsky-bros.com/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,2b29772d-bded-4045-b6b8-d0035cb5944f.aspx</pingback:target>
      <dc:creator>Vladimir Nesterovsky</dc:creator>
      <georss:point>0 0</georss:point>
      <wfw:commentRss>http://www.nesterovsky-bros.com/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=2b29772d-bded-4045-b6b8-d0035cb5944f</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Xslt 3.0 defines a feature called streamability: a technique to write xslt code that
is able to handle arbitrary sized inputs. 
</p>
        <p>
This contrasts with conventional xslt code (and xslt engines) where inputs are completely
loaded in memory.
</p>
        <p>
To make code streamable a developer should declare her code as such, and the code
should pass <a href="https://www.w3.org/TR/xslt-30/#streamability">Streamability analysis</a>.
</p>
        <p>
The goal is to define subset of xslt/xpath operations that allow to process input
in one pass.
</p>
        <p>
In simple case it's indeed a simple task to verify that code is streamable, but
the more complex your code is the less trivial it's to witness it is streamable.
</p>
        <p>
On the forums we have seen a lot of discussions, where experts were trying to figure
out whether particular xslt is streamable. At times it's remarkably untrivial
task!
</p>
        <p>
This, in our opinion, clearly manifests that the feature is largerly failed attempt
to inscribe some optimization technique into xslt spec.
</p>
        <p>
The place of such optimization is in the implementation space, and not in spec. Engine
had to attempt such optimization and fallback to the traditional implementation.
</p>
        <p>
The last such example is: <a href="https://saxonica.plan.io/boards/3/topics/7319">Getting
SXST0060 "No streamable path found in expression" when trying to push a
map with grounded nodes to a template of a streamable mode</a>, where both xslt code
and engine developers are not sure that the code is streamable in the first place.
</p>
        <p>
        </p>
        <p>
By the way, besides streamability there is other optimization technique that works
probably in all SQL engines. When data does not fit into memory engine may spill it
on disk. Thus trading memory pressure for disk access. So, why didn't such techninque
find the way into the Xslt or SQL specs?
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=2b29772d-bded-4045-b6b8-d0035cb5944f" />
      </body>
      <title>Xslt Streamability</title>
      <guid isPermaLink="false">http://www.nesterovsky-bros.com/weblog/PermaLink,guid,2b29772d-bded-4045-b6b8-d0035cb5944f.aspx</guid>
      <link>http://www.nesterovsky-bros.com/weblog/2018/10/02/XsltStreamability.aspx</link>
      <pubDate>Tue, 02 Oct 2018 12:50:22 GMT</pubDate>
      <description>  &lt;p&gt;
Xslt 3.0 defines a feature called streamability: a technique to write xslt code that
is able to handle arbitrary sized inputs. 
&lt;/p&gt;
&lt;p&gt;
This contrasts with conventional xslt code (and xslt engines) where inputs are completely
loaded in memory.
&lt;/p&gt;
&lt;p&gt;
To make code streamable a developer should declare her code as such, and the code
should pass &lt;a href="https://www.w3.org/TR/xslt-30/#streamability"&gt;Streamability analysis&lt;/a&gt;.
&lt;/p&gt;
&lt;p&gt;
The goal is to define subset of xslt/xpath operations that allow to process input
in one pass.
&lt;/p&gt;
&lt;p&gt;
In simple case it&amp;#39;s indeed a simple task to verify that code is streamable, but
the more complex your code is the less trivial it&amp;#39;s to witness it is streamable.
&lt;/p&gt;
&lt;p&gt;
On the forums we have seen a lot of discussions, where experts were trying to figure
out whether particular xslt is streamable. At times it&amp;#39;s remarkably untrivial
task!
&lt;/p&gt;
&lt;p&gt;
This, in our opinion, clearly manifests that the feature is largerly failed attempt
to inscribe some optimization technique into xslt spec.
&lt;/p&gt;
&lt;p&gt;
The place of such optimization is in the implementation space, and not in spec. Engine
had to attempt such optimization and fallback to the traditional implementation.
&lt;/p&gt;
&lt;p&gt;
The last such example is: &lt;a href="https://saxonica.plan.io/boards/3/topics/7319"&gt;Getting
SXST0060 &amp;quot;No streamable path found in expression&amp;quot; when trying to push a
map with grounded nodes to a template of a streamable mode&lt;/a&gt;, where both xslt code
and engine developers are not sure that the code is streamable in the first place.
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
By the way, besides streamability there is other optimization technique that works
probably in all SQL engines. When data does not fit into memory engine may spill it
on disk. Thus trading memory pressure for disk access. So, why didn&amp;#39;t such techninque
find the way into the Xslt or SQL specs?
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=2b29772d-bded-4045-b6b8-d0035cb5944f" /&gt;</description>
      <comments>http://www.nesterovsky-bros.com/weblog/CommentView,guid,2b29772d-bded-4045-b6b8-d0035cb5944f.aspx</comments>
      <category>Thinking aloud</category>
      <category>xslt</category>
    </item>
    <item>
      <trackback:ping>http://www.nesterovsky-bros.com/weblog/Trackback.aspx?guid=ebe76efc-3ec2-463d-a666-3741bdebbf82</trackback:ping>
      <pingback:server>http://www.nesterovsky-bros.com/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,ebe76efc-3ec2-463d-a666-3741bdebbf82.aspx</pingback:target>
      <dc:creator>Vladimir Nesterovsky</dc:creator>
      <georss:point>0 0</georss:point>
      <wfw:comment>http://www.nesterovsky-bros.com/weblog/CommentView,guid,ebe76efc-3ec2-463d-a666-3741bdebbf82.aspx</wfw:comment>
      <wfw:commentRss>http://www.nesterovsky-bros.com/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=ebe76efc-3ec2-463d-a666-3741bdebbf82</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Saxon 9.9.0-1 is out!
</p>
        <p>
Shortly we have reported our first bug in the new version. See <a href="https://saxonica.plan.io/issues/3923">https://saxonica.plan.io/issues/3923</a>.
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=ebe76efc-3ec2-463d-a666-3741bdebbf82" />
      </body>
      <title>Saxon 9.9.0-1 is out</title>
      <guid isPermaLink="false">http://www.nesterovsky-bros.com/weblog/PermaLink,guid,ebe76efc-3ec2-463d-a666-3741bdebbf82.aspx</guid>
      <link>http://www.nesterovsky-bros.com/weblog/2018/09/28/Saxon9901IsOut.aspx</link>
      <pubDate>Fri, 28 Sep 2018 17:47:37 GMT</pubDate>
      <description>&lt;p&gt;
Saxon 9.9.0-1 is out!
&lt;/p&gt;
&lt;p&gt;
Shortly we have reported our first bug in the new version. See &lt;a href="https://saxonica.plan.io/issues/3923"&gt;https://saxonica.plan.io/issues/3923&lt;/a&gt;.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=ebe76efc-3ec2-463d-a666-3741bdebbf82" /&gt;</description>
      <comments>http://www.nesterovsky-bros.com/weblog/CommentView,guid,ebe76efc-3ec2-463d-a666-3741bdebbf82.aspx</comments>
      <category>xslt</category>
    </item>
    <item>
      <trackback:ping>http://www.nesterovsky-bros.com/weblog/Trackback.aspx?guid=c54ee192-82aa-4912-a19a-e312b603016d</trackback:ping>
      <pingback:server>http://www.nesterovsky-bros.com/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,c54ee192-82aa-4912-a19a-e312b603016d.aspx</pingback:target>
      <dc:creator>Vladimir Nesterovsky</dc:creator>
      <georss:point>0 0</georss:point>
      <wfw:commentRss>http://www.nesterovsky-bros.com/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=c54ee192-82aa-4912-a19a-e312b603016d</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
After 17 years of experience we still run into dummy bugs in xslt (xpath in fact).
</p>
        <p>
The latest one is related to order of nodes produced by ancestor-or-self axis.
</p>
        <p>
Consider the code:
</p>
        <blockquote>
          <pre>&lt;xsl:stylesheet version="3.0" 
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:xs="http://www.w3.org/2001/XMLSchema"&gt;

  &lt;xsl:template match="/"&gt;
    &lt;xsl:variable name="data" as="element()"&gt;
      &lt;a&gt;
        &lt;b&gt;
          &lt;c/&gt;
        &lt;/b&gt;
      &lt;/a&gt;
    &lt;/xsl:variable&gt;

    &lt;xsl:variable name="item" as="element()" select="($data//c)[1]"/&gt;

    &lt;xsl:message select="$item!ancestor-or-self::*!local-name()"/&gt;
    &lt;xsl:message select="$item!local-name(), $item!..!local-name(), $item!..!..!local-name()"/&gt;
  &lt;/xsl:template&gt;

&lt;/xsl:stylesheet&gt;</pre>
        </blockquote>
        <p>
We expected to have the following outcome
</p>
        <ul>
          <li>
            <code>c b a</code>
          </li>
          <li>
            <code>c b a</code>
          </li>
        </ul>
        <p>
But correct one is
</p>
        <ul>
          <li>
            <code>a b c</code>
          </li>
          <li>
            <code>c b a</code>
          </li>
        </ul>
        <p>
Here is why:
</p>
        <blockquote>
          <i>
            <code>ancestor-or-self::*</code> is an AxisStep. From XPath §3.3.2:</i>
          <br />
          <br />
          <i>[Definition: An axis step returns a sequence of nodes that are reachable from the
context node via a specified axis. Such a step has two parts: an axis, which defines
the "direction of movement" for the step, and a node test, which selects
nodes based on their kind, name, and/or type annotation.] If the context item is a
node, an axis step returns a sequence of zero or more nodes; otherwise, a type error
is raised [err:XPTY0020]. <strong>The resulting node sequence is returned in document
order</strong>. </i>
        </blockquote>
        <p>
For some reason we were thinking that reverse axis produces result in reverse order.
It turns out the reverse order is only within predicate of such axis.
</p>
        <p>
See more at <a href="https://saxonica.plan.io/boards/3/topics/7312">https://saxonica.plan.io/boards/3/topics/7312</a></p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=c54ee192-82aa-4912-a19a-e312b603016d" />
      </body>
      <title>Fail with ancestor-or-self</title>
      <guid isPermaLink="false">http://www.nesterovsky-bros.com/weblog/PermaLink,guid,c54ee192-82aa-4912-a19a-e312b603016d.aspx</guid>
      <link>http://www.nesterovsky-bros.com/weblog/2018/09/27/FailWithAncestororself.aspx</link>
      <pubDate>Thu, 27 Sep 2018 05:52:58 GMT</pubDate>
      <description>&lt;p&gt;
After 17 years of experience we still run into dummy bugs in xslt (xpath in fact).
&lt;/p&gt;
&lt;p&gt;
The latest one is related to order of nodes produced by ancestor-or-self axis.
&lt;/p&gt;
&lt;p&gt;
Consider the code:
&lt;/p&gt;
&lt;blockquote&gt;&lt;pre&gt;&amp;lt;xsl:stylesheet version="3.0" 
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:xs="http://www.w3.org/2001/XMLSchema"&gt;

  &amp;lt;xsl:template match="/"&gt;
    &amp;lt;xsl:variable name="data" as="element()"&gt;
      &amp;lt;a&gt;
        &amp;lt;b&gt;
          &amp;lt;c/&gt;
        &amp;lt;/b&gt;
      &amp;lt;/a&gt;
    &amp;lt;/xsl:variable&gt;

    &amp;lt;xsl:variable name="item" as="element()" select="($data//c)[1]"/&gt;

    &amp;lt;xsl:message select="$item!ancestor-or-self::*!local-name()"/&gt;
    &amp;lt;xsl:message select="$item!local-name(), $item!..!local-name(), $item!..!..!local-name()"/&gt;
  &amp;lt;/xsl:template&gt;

&amp;lt;/xsl:stylesheet&gt;&lt;/pre&gt;&lt;/blockquote&gt; 
&lt;p&gt;
We expected to have the following outcome
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;c b a&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;c b a&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
But correct one is
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;a b c&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;c b a&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
Here is why:
&lt;/p&gt;
&lt;blockquote&gt; &lt;i&gt; &lt;code&gt;ancestor-or-self::*&lt;/code&gt; is an AxisStep. From XPath §3.3.2:&lt;/i&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;[Definition: An axis step returns a sequence of nodes that are reachable from the
context node via a specified axis. Such a step has two parts: an axis, which defines
the &amp;quot;direction of movement&amp;quot; for the step, and a node test, which selects
nodes based on their kind, name, and/or type annotation.] If the context item is a
node, an axis step returns a sequence of zero or more nodes; otherwise, a type error
is raised [err:XPTY0020]. &lt;strong&gt;The resulting node sequence is returned in document
order&lt;/strong&gt;. &lt;/i&gt; &lt;/blockquote&gt; 
&lt;p&gt;
For some reason we were thinking that reverse axis produces result in reverse order.
It turns out the reverse order is only within predicate of such axis.
&lt;/p&gt;
&lt;p&gt;
See more at &lt;a href="https://saxonica.plan.io/boards/3/topics/7312"&gt;https://saxonica.plan.io/boards/3/topics/7312&lt;/a&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=c54ee192-82aa-4912-a19a-e312b603016d" /&gt;</description>
      <comments>http://www.nesterovsky-bros.com/weblog/CommentView,guid,c54ee192-82aa-4912-a19a-e312b603016d.aspx</comments>
      <category>xslt</category>
    </item>
    <item>
      <trackback:ping>http://www.nesterovsky-bros.com/weblog/Trackback.aspx?guid=278ad22c-a125-4dd1-a66e-1a7f1ba0b381</trackback:ping>
      <pingback:server>http://www.nesterovsky-bros.com/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,278ad22c-a125-4dd1-a66e-1a7f1ba0b381.aspx</pingback:target>
      <dc:creator>Vladimir Nesterovsky</dc:creator>
      <georss:point>0 0</georss:point>
      <wfw:comment>http://www.nesterovsky-bros.com/weblog/CommentView,guid,278ad22c-a125-4dd1-a66e-1a7f1ba0b381.aspx</wfw:comment>
      <wfw:commentRss>http://www.nesterovsky-bros.com/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=278ad22c-a125-4dd1-a66e-1a7f1ba0b381</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
XPath 3 has introduced a syntactic sugar for a string concatenation, so following:
</p>
        <blockquote>
          <pre>concat($a, $b)</pre>
        </blockquote>
        <p>
can be now written as:
</p>
        <blockquote>
          <pre>$a || $b</pre>
        </blockquote>
        <p>
This is nice addition, except when you run into a trouble. Being rooted in C world
we unintentionally have written a following xslt code:
</p>
        <blockquote>
          <pre>&lt;xsl:if test="$a || $b"&gt;
...
&lt;/xsl:if&gt;</pre>
        </blockquote>
        <p>
Clearly, we intended to write <code>$a or $b</code>. In contrast <code> $a || $b</code> is
evaluated as <code>concat($a, $b)</code>. If both variables are <code>false()</code> we
get <code>'falsefalse'</code> outcome, which has effective boolean value <code>true()</code>.
This means that test condition of <code>xsl:if</code> is always <code>true()</code>.
</p>
        <p>
        </p>
        <p>
What can be done to avoid such unfortunate typo, which is manifested in no way neither
during compilation nor during runtime?
</p>
        <p>
The answer is to issue informational message during the compilation, e.g. if result
of || operator is converted to a boolean, and if its arguments are booleans also then
chances are high this is typo, and not intentional expression.
</p>
        <p>
We adviced to implement such message in the saxon processor (see <a href="https://saxonica.plan.io/boards/3/topics/7305">https://saxonica.plan.io/boards/3/topics/7305</a>).
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=278ad22c-a125-4dd1-a66e-1a7f1ba0b381" />
      </body>
      <title>|| in boolean expression in XPath</title>
      <guid isPermaLink="false">http://www.nesterovsky-bros.com/weblog/PermaLink,guid,278ad22c-a125-4dd1-a66e-1a7f1ba0b381.aspx</guid>
      <link>http://www.nesterovsky-bros.com/weblog/2018/09/18/InBooleanExpressionInXPath.aspx</link>
      <pubDate>Tue, 18 Sep 2018 12:23:08 GMT</pubDate>
      <description>  &lt;p&gt;
XPath 3 has introduced a syntactic sugar for a string concatenation, so following:
&lt;/p&gt;
&lt;blockquote&gt;&lt;pre&gt;concat($a, $b)&lt;/pre&gt;&lt;/blockquote&gt; 
&lt;p&gt;
can be now written as:
&lt;/p&gt;
&lt;blockquote&gt;&lt;pre&gt;$a || $b&lt;/pre&gt;&lt;/blockquote&gt; 
&lt;p&gt;
This is nice addition, except when you run into a trouble. Being rooted in C world
we unintentionally have written a following xslt code:
&lt;/p&gt;
&lt;blockquote&gt;&lt;pre&gt;&amp;lt;xsl:if test=&amp;quot;$a || $b&amp;quot;&amp;gt;
...
&amp;lt;/xsl:if&amp;gt;&lt;/pre&gt;&lt;/blockquote&gt; 
&lt;p&gt;
Clearly, we intended to write &lt;code&gt;$a or $b&lt;/code&gt;. In contrast &lt;code&gt; $a || $b&lt;/code&gt; is
evaluated as &lt;code&gt;concat($a, $b)&lt;/code&gt;. If both variables are &lt;code&gt;false()&lt;/code&gt; we
get &lt;code&gt;'falsefalse'&lt;/code&gt; outcome, which has effective boolean value &lt;code&gt;true()&lt;/code&gt;.
This means that test condition of &lt;code&gt;xsl:if&lt;/code&gt; is always &lt;code&gt;true()&lt;/code&gt;.
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
What can be done to avoid such unfortunate typo, which is manifested in no way neither
during compilation nor during runtime?
&lt;/p&gt;
&lt;p&gt;
The answer is to issue informational message during the compilation, e.g. if result
of || operator is converted to a boolean, and if its arguments are booleans also then
chances are high this is typo, and not intentional expression.
&lt;/p&gt;
&lt;p&gt;
We adviced to implement such message in the saxon processor (see &lt;a href="https://saxonica.plan.io/boards/3/topics/7305"&gt;https://saxonica.plan.io/boards/3/topics/7305&lt;/a&gt;).
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=278ad22c-a125-4dd1-a66e-1a7f1ba0b381" /&gt;</description>
      <comments>http://www.nesterovsky-bros.com/weblog/CommentView,guid,278ad22c-a125-4dd1-a66e-1a7f1ba0b381.aspx</comments>
      <category>xslt</category>
    </item>
    <item>
      <trackback:ping>http://www.nesterovsky-bros.com/weblog/Trackback.aspx?guid=07cc910c-dabb-4970-9a75-a87d36c9a50b</trackback:ping>
      <pingback:server>http://www.nesterovsky-bros.com/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,07cc910c-dabb-4970-9a75-a87d36c9a50b.aspx</pingback:target>
      <dc:creator>Vladimir Nesterovsky</dc:creator>
      <georss:point>0 0</georss:point>
      <wfw:comment>http://www.nesterovsky-bros.com/weblog/CommentView,guid,07cc910c-dabb-4970-9a75-a87d36c9a50b.aspx</wfw:comment>
      <wfw:commentRss>http://www.nesterovsky-bros.com/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=07cc910c-dabb-4970-9a75-a87d36c9a50b</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
It seems we've found discrepancy in regex implementation during the transformation
in Saxon. Consider the following xslt:
</p>
        <pre>&lt;xsl:stylesheet version="3.0" 
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:xs="http://www.w3.org/2001/XMLSchema"&gt;

  &lt;xsl:template match="/"&gt;
    &lt;xsl:variable name="text" as="xs:string" 
      select="'A = &amp;quot;a&amp;quot; OR B = &amp;quot;b&amp;quot;'"/&gt;

    &lt;xsl:analyze-string regex="&amp;quot;(\\&amp;quot;|.)*?&amp;quot;" select="$text"&gt;
      &lt;xsl:matching-substring&gt;
        &lt;xsl:message&gt;
          &lt;xsl:sequence select="regex-group(0)"/&gt;
        &lt;/xsl:message&gt;
      &lt;/xsl:matching-substring&gt;
    &lt;/xsl:analyze-string&gt;
  &lt;/xsl:template&gt;

&lt;/xsl:stylesheet&gt;</pre>
vs javascript <pre>&lt;html&gt;
&lt;body&gt;
  &lt;script&gt;
    var text = 'A = "a" OR B = "b"';
    var regex = /"(\\"|.)*?"/;
    var match = text.match(regex);

    alert(match[0]);
  &lt;/script&gt;
&lt;/body&gt;
&lt;/html&gt;</pre><p>
xslt produces: "a" OR B = "b"
</p><p>
while javascript: "a"
</p><p>
What is interesting is that we're certain this was working correctly in Saxon several
years ago. 
</p><p>
You can track progress of the bug at: <a href="https://saxonica.plan.io/boards/3/topics/7300">https://saxonica.plan.io/boards/3/topics/7300</a> and
at <a href="https://saxonica.plan.io/issues/3902">https://saxonica.plan.io/issues/3902</a>.
</p><img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=07cc910c-dabb-4970-9a75-a87d36c9a50b" /></body>
      <title>Bug with regex in Saxon xslt</title>
      <guid isPermaLink="false">http://www.nesterovsky-bros.com/weblog/PermaLink,guid,07cc910c-dabb-4970-9a75-a87d36c9a50b.aspx</guid>
      <link>http://www.nesterovsky-bros.com/weblog/2018/09/13/BugWithRegexInSaxonXslt.aspx</link>
      <pubDate>Thu, 13 Sep 2018 06:29:05 GMT</pubDate>
      <description>&lt;p&gt;
It seems we've found discrepancy in regex implementation during the transformation
in Saxon. Consider the following xslt:
&lt;/p&gt;
&lt;pre&gt;&amp;lt;xsl:stylesheet version="3.0" 
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:xs="http://www.w3.org/2001/XMLSchema"&gt;

  &amp;lt;xsl:template match="/"&gt;
    &amp;lt;xsl:variable name="text" as="xs:string" 
      select="'A = &amp;amp;quot;a&amp;amp;quot; OR B = &amp;amp;quot;b&amp;amp;quot;'"/&gt;

    &amp;lt;xsl:analyze-string regex="&amp;amp;quot;(\\&amp;amp;quot;|.)*?&amp;amp;quot;" select="$text"&gt;
      &amp;lt;xsl:matching-substring&gt;
        &amp;lt;xsl:message&gt;
          &amp;lt;xsl:sequence select="regex-group(0)"/&gt;
        &amp;lt;/xsl:message&gt;
      &amp;lt;/xsl:matching-substring&gt;
    &amp;lt;/xsl:analyze-string&gt;
  &amp;lt;/xsl:template&gt;

&amp;lt;/xsl:stylesheet&gt;&lt;/pre&gt;
vs javascript &lt;pre&gt;&amp;lt;html&gt;
&amp;lt;body&gt;
  &amp;lt;script&gt;
    var text = 'A = "a" OR B = "b"';
    var regex = /"(\\"|.)*?"/;
    var match = text.match(regex);

    alert(match[0]);
  &amp;lt;/script&gt;
&amp;lt;/body&gt;
&amp;lt;/html&gt;&lt;/pre&gt;
&lt;p&gt;
xslt produces: "a" OR B = "b"
&lt;/p&gt;
&lt;p&gt;
while javascript: "a"
&lt;/p&gt;
&lt;p&gt;
What is interesting is that we're certain this was working correctly in Saxon several
years ago. 
&lt;/p&gt;
&lt;p&gt;
You can track progress of the bug at: &lt;a href="https://saxonica.plan.io/boards/3/topics/7300"&gt;https://saxonica.plan.io/boards/3/topics/7300&lt;/a&gt; and
at &lt;a href="https://saxonica.plan.io/issues/3902"&gt;https://saxonica.plan.io/issues/3902&lt;/a&gt;.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=07cc910c-dabb-4970-9a75-a87d36c9a50b" /&gt;</description>
      <comments>http://www.nesterovsky-bros.com/weblog/CommentView,guid,07cc910c-dabb-4970-9a75-a87d36c9a50b.aspx</comments>
      <category>xslt</category>
    </item>
    <item>
      <trackback:ping>http://www.nesterovsky-bros.com/weblog/Trackback.aspx?guid=8dcc4028-a6ff-48c9-99e2-72229895c1fb</trackback:ping>
      <pingback:server>http://www.nesterovsky-bros.com/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,8dcc4028-a6ff-48c9-99e2-72229895c1fb.aspx</pingback:target>
      <dc:creator>Vladimir Nesterovsky</dc:creator>
      <georss:point>0 0</georss:point>
      <wfw:commentRss>http://www.nesterovsky-bros.com/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=8dcc4028-a6ff-48c9-99e2-72229895c1fb</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
For more than 25 years continues a discussion in C++ community about exceptions. In
our opinion this can only be compared with math community and their open problems
like <a href="https://en.wikipedia.org/wiki/Hilbert's_problems">Hilbert's 23 problems</a> dated
by 1900.
</p>
        <p>
In essence C++ exception discussion is about efficiency of exceptions vs status codes.
This problem is not so acute in other languages (like java or C#) because those languages
postulate different goals. 
</p>
        <p>
C++ designers have introduced a zero-overhead principle for any language feature,
which is:
</p>
        <ol>
          <li>
If you don’t use some feature you don’t pay for it.</li>
          <li>
If you do use it you cannot (reasonably) write it more efficiently by hand. 
</li>
        </ol>
        <p>
Exceptions comparing to status codes do not withstand this demand. This led to the
fragmentation of C++ comunity where many big projects and code styles ban exceptions
partially or completely.
</p>
        <p>
Make no doubt that all this time people were trying to make exceptions better, and
have found techniques to make them space and run time efficient to some extent, but
still, old plain status codes outperform both in speed (especially in predictability
of time of exception handling logic) and in code size. 
</p>
        <p>
We guess the solution is finally found after the quarter the century of discussion!
</p>
        <p>
WG paper: <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0709r1.pdf">Zero-overhead
deterministic exceptions: Throwing values</a> by Herb Sutter. This "<i>paper
aims to extend C++’s exception model to let functions declare that they throw a statically
specified type by value. This lets the exception handling implementation be exactly
as efficient and deterministic as a local return by value, with zero dynamic or non-local
overheads.</i>"
</p>
        <p>
In other words author suggests to:
</p>
        <ul>
          <li>
extend exception model (in fact implement additional one);</li>
          <li>
make exceptions as fast and as predicable as status codes (which virtually means designate
a status code as a new exception);</li>
        </ul>
        <p>
 
</p>
        <p>
Here are author's arguments:
</p>
        <ol>
          <li>
Status code is usually just a number, and handling an error is like to perform some <code>if</code> or <code>switch</code> statements.</li>
          <li>
Handling errors with status codes is predicable in time and visible in the code though
it burdens the logic very much.</li>
          <li>
Exceptions give clear separation between a control flow and error handling.</li>
          <li>
Exceptions are mostly invisible in the code, so it's not always clear how much
they add to code size and how they impact performance.</li>
          <li>
Statistics show that exceptions add 15 to 30% to size of code, even if no exceptions
are used (violation of zero-overhead principle);</li>
          <li>
Exceptions require Run Time Type Information about types, and have no predictable
memory (stack or heap) footprint  (violation of zero-overhead principle).</li>
        </ol>
        <p>
 
</p>
        <p>
What aurhor suggests might seem too radical but at present it's only viable solution
to reestablish zero-verhead principle and to reunite two C++ camps.
</p>
        <p>
Here is the approach.
</p>
        <ol>
          <li>
Clarify what should be considered as an exception. 
<ol><li>
Contract violation. 
<p>
Are contract violation like invalid values of arguments or invalid post conditions
(unhold invariants) are exceptions or programmer's bugs?
</p><p>
If later then it's best to terminate, as you cannot correctly recover from bug.
</p></li><li>
Virtual Machine fault. 
<p>
What user program can do with stack overflow?
</p><p>
The best according to the author it to terminate.
</p></li><li>
OOM - Out Of Memory error. 
<p>
What is the best way to deal with OOM dyring dynamic allocation.
</p><p>
At present there are two operators:
</p><ul><li><code>new</code> - to allocate memory dynamically and throw <code>bad_alloc</code> on
failure.</li><li><code>new(nothrow)</code> - to allocate memory dynamically and return <code>nullptr</code> on
failure.</li></ul><p>
Herb Sutter suggests to change <code>new</code> behavior to terminate on failure (it
is very hard to properly handle <code>bad_alloc</code> anyway), while <code>new(nothrow)</code> will
still allow to build code that can deal with OOM.
</p></li><li>
Partial success 
<p>
This should never be reported as an error, and status codes should be used to report
the state.
</p></li><li>
Error condition distinct from any type of success. 
<p>
This is where exceptions should be used.
</p></li></ol><p>
Statistics shows that with such separation more than 90% of what curently is an exception
will not be exception any more, so no any hidden exception logic is required: program
either works or terminates.
</p></li>
          <li>
Refactor exception 
<p>
Redefine what exception object is and how it is propagated.
</p><p>
It should be thin value type. At minimum it needs to contain an error code. Suggested
size is up to a couple of pointers.
</p><p>
Compiler should be able to cheaply allocate and copy it on the stack or even in the
processor's registers.
</p><p>
Such simple exception type resolves problems with lifetime of exception object, and
makes exception handling as light as checking status codes.
</p><p>
Exception should be propagated through return chanel, so it's like a new calling
convention that defines either function result or error outcome.
</p></li>
        </ol>
        <p>
        </p>
        <p>
It's not our intention to quote whole the paper here. If you're interested then please
read it. Here we want to outline our concerns.
</p>
        <ol>
          <li>
Exception payload. 
<p>
This paper emphasizes that exception type should be small.
</p><p>
So, what to do with exception payload, if any (at least error message if it's
not a static text)?
</p><p>
If this won't be resolved then developers will start to invent custom mechanisms
like GetLastErrorMessage().
</p><p>
And what to do with aggregate exceptions?
</p><p>
We think this must be clearly addressed.
</p></li>
          <li>
Implemntation shift. 
<p>
We can accept that most of the current exceptions will terminate.
</p><p>
But consider now some container that serves requests, like web container or database.
</p><p>
It may be built from multiple components and serve multiple requests concurently.
If one request will terminate we don't want for container to terminate.
</p><p>
If terminate handler is called then we cannot rely on state of the application. At
least we can expect heap leaks and un-released resources.
</p><p>
So, we either want to be able release heap and other resources per request, or we
want to go down with whole process and let OS deal with it.
</p><p>
In the later case we need to design such containers differently: as a set of cooperative
processes; OS should allow to spin processes more easily.
</p></li>
          <li>
VM with exceptions 
<p>
There are Virtual Machines that allow exception to be thrown on each instruction (like
JVM, or CLI).
</p><p>
You cannot tell in this case that code would never throw exception, as it can out
of the blue!
</p><p>
Event in x86 you can have PAGE FAULT on memory access, which can be translated into
an exception.
</p><p>
So, it's still a question whether the terminate() solution is sound in every case,
and whether compiler can optimize out exception handling if it proves staticlly that
no exception should be thrown.
</p></li>
        </ol>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=8dcc4028-a6ff-48c9-99e2-72229895c1fb" />
      </body>
      <title>C++ Exceptions</title>
      <guid isPermaLink="false">http://www.nesterovsky-bros.com/weblog/PermaLink,guid,8dcc4028-a6ff-48c9-99e2-72229895c1fb.aspx</guid>
      <link>http://www.nesterovsky-bros.com/weblog/2018/08/06/CExceptions.aspx</link>
      <pubDate>Mon, 06 Aug 2018 12:00:10 GMT</pubDate>
      <description>  &lt;p&gt;
For more than 25 years continues a discussion in C++ community about exceptions. In
our opinion this can only be compared with math community and their open problems
like &lt;a href="https://en.wikipedia.org/wiki/Hilbert's_problems"&gt;Hilbert&amp;#39;s 23 problems&lt;/a&gt; dated
by 1900.
&lt;/p&gt;
&lt;p&gt;
In essence C++ exception discussion is about efficiency of exceptions vs status codes.
This problem is not so acute in other languages (like java or C#) because those languages
postulate different goals. 
&lt;/p&gt;
&lt;p&gt;
C++ designers have introduced a zero-overhead principle for any language feature,
which is:
&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
If you don’t use some feature you don’t pay for it.&lt;/li&gt;
&lt;li&gt;
If you do use it you cannot (reasonably) write it more efficiently by hand. 
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;
Exceptions comparing to status codes do not withstand this demand. This led to the
fragmentation of C++ comunity where many big projects and code styles ban exceptions
partially or completely.
&lt;/p&gt;
&lt;p&gt;
Make no doubt that all this time people were trying to make exceptions better, and
have found techniques to make them space and run time efficient to some extent, but
still, old plain status codes outperform both in speed (especially in predictability
of time of exception handling logic) and in code size. 
&lt;/p&gt;
&lt;p&gt;
We guess the solution is finally found after the quarter the century of discussion!
&lt;/p&gt;
&lt;p&gt;
WG paper: &lt;a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0709r1.pdf"&gt;Zero-overhead
deterministic exceptions: Throwing values&lt;/a&gt; by Herb Sutter. This &amp;quot;&lt;i&gt;paper
aims to extend C++’s exception model to let functions declare that they throw a statically
specified type by value. This lets the exception handling implementation be exactly
as efficient and deterministic as a local return by value, with zero dynamic or non-local
overheads.&lt;/i&gt;&amp;quot;
&lt;/p&gt;
&lt;p&gt;
In other words author suggests to:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
extend exception model (in fact implement additional one);&lt;/li&gt;
&lt;li&gt;
make exceptions as fast and as predicable as status codes (which virtually means designate
a status code as a new exception);&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
Here are author&amp;#39;s arguments:
&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
Status code is usually just a number, and handling an error is like to perform some &lt;code&gt;if&lt;/code&gt; or &lt;code&gt;switch&lt;/code&gt; statements.&lt;/li&gt;
&lt;li&gt;
Handling errors with status codes is predicable in time and visible in the code though
it burdens the logic very much.&lt;/li&gt;
&lt;li&gt;
Exceptions give clear separation between a control flow and error handling.&lt;/li&gt;
&lt;li&gt;
Exceptions are mostly invisible in the code, so it&amp;#39;s not always clear how much
they add to code size and how they impact performance.&lt;/li&gt;
&lt;li&gt;
Statistics show that exceptions add 15 to 30% to size of code, even if no exceptions
are used (violation of zero-overhead principle);&lt;/li&gt;
&lt;li&gt;
Exceptions require Run Time Type Information about types, and have no predictable
memory (stack or heap) footprint&amp;nbsp; (violation of zero-overhead principle).&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
What aurhor suggests might seem too radical but at present it&amp;#39;s only viable solution
to reestablish zero-verhead principle and to reunite two C++ camps.
&lt;/p&gt;
&lt;p&gt;
Here is the approach.
&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
Clarify what should be considered as an exception. 
&lt;ol&gt;
&lt;li&gt;
Contract violation. 
&lt;p&gt;
Are contract violation like invalid values of arguments or invalid post conditions
(unhold invariants) are exceptions or programmer&amp;#39;s bugs?
&lt;/p&gt;
&lt;p&gt;
If later then it&amp;#39;s best to terminate, as you cannot correctly recover from bug.
&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
Virtual Machine fault. 
&lt;p&gt;
What user program can do with stack overflow?
&lt;/p&gt;
&lt;p&gt;
The best according to the author it to terminate.
&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
OOM - Out Of Memory error. 
&lt;p&gt;
What is the best way to deal with OOM dyring dynamic allocation.
&lt;/p&gt;
&lt;p&gt;
At present there are two operators:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;new&lt;/code&gt; - to allocate memory dynamically and throw &lt;code&gt;bad_alloc&lt;/code&gt; on
failure.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;new(nothrow)&lt;/code&gt; - to allocate memory dynamically and return &lt;code&gt;nullptr&lt;/code&gt; on
failure.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
Herb Sutter suggests to change &lt;code&gt;new&lt;/code&gt; behavior to terminate on failure (it
is very hard to properly handle &lt;code&gt;bad_alloc&lt;/code&gt; anyway), while &lt;code&gt;new(nothrow)&lt;/code&gt; will
still allow to build code that can deal with OOM.
&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
Partial success 
&lt;p&gt;
This should never be reported as an error, and status codes should be used to report
the state.
&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
Error condition distinct from any type of success. 
&lt;p&gt;
This is where exceptions should be used.
&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;
Statistics shows that with such separation more than 90% of what curently is an exception
will not be exception any more, so no any hidden exception logic is required: program
either works or terminates.
&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
Refactor exception 
&lt;p&gt;
Redefine what exception object is and how it is propagated.
&lt;/p&gt;
&lt;p&gt;
It should be thin value type. At minimum it needs to contain an error code. Suggested
size is up to a couple of pointers.
&lt;/p&gt;
&lt;p&gt;
Compiler should be able to cheaply allocate and copy it on the stack or even in the
processor&amp;#39;s registers.
&lt;/p&gt;
&lt;p&gt;
Such simple exception type resolves problems with lifetime of exception object, and
makes exception handling as light as checking status codes.
&lt;/p&gt;
&lt;p&gt;
Exception should be propagated through return chanel, so it&amp;#39;s like a new calling
convention that defines either function result or error outcome.
&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
It's not our intention to quote whole the paper here. If you're interested then please
read it. Here we want to outline our concerns.
&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
Exception payload. 
&lt;p&gt;
This paper emphasizes that exception type should be small.
&lt;/p&gt;
&lt;p&gt;
So, what to do with exception payload, if any (at least error message if it&amp;#39;s
not a static text)?
&lt;/p&gt;
&lt;p&gt;
If this won&amp;#39;t be resolved then developers will start to invent custom mechanisms
like GetLastErrorMessage().
&lt;/p&gt;
&lt;p&gt;
And what to do with aggregate exceptions?
&lt;/p&gt;
&lt;p&gt;
We think this must be clearly addressed.
&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
Implemntation shift. 
&lt;p&gt;
We can accept that most of the current exceptions will terminate.
&lt;/p&gt;
&lt;p&gt;
But consider now some container that serves requests, like web container or database.
&lt;/p&gt;
&lt;p&gt;
It may be built from multiple components and serve multiple requests concurently.
If one request will terminate we don&amp;#39;t want for container to terminate.
&lt;/p&gt;
&lt;p&gt;
If terminate handler is called then we cannot rely on state of the application. At
least we can expect heap leaks and un-released resources.
&lt;/p&gt;
&lt;p&gt;
So, we either want to be able release heap and other resources per request, or we
want to go down with whole process and let OS deal with it.
&lt;/p&gt;
&lt;p&gt;
In the later case we need to design such containers differently: as a set of cooperative
processes; OS should allow to spin processes more easily.
&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
VM with exceptions 
&lt;p&gt;
There are Virtual Machines that allow exception to be thrown on each instruction (like
JVM, or CLI).
&lt;/p&gt;
&lt;p&gt;
You cannot tell in this case that code would never throw exception, as it can out
of the blue!
&lt;/p&gt;
&lt;p&gt;
Event in x86 you can have PAGE FAULT on memory access, which can be translated into
an exception.
&lt;/p&gt;
&lt;p&gt;
So, it&amp;#39;s still a question whether the terminate() solution is sound in every case,
and whether compiler can optimize out exception handling if it proves staticlly that
no exception should be thrown.
&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=8dcc4028-a6ff-48c9-99e2-72229895c1fb" /&gt;</description>
      <comments>http://www.nesterovsky-bros.com/weblog/CommentView,guid,8dcc4028-a6ff-48c9-99e2-72229895c1fb.aspx</comments>
      <category>C++</category>
      <category>Thinking aloud</category>
    </item>
    <item>
      <trackback:ping>http://www.nesterovsky-bros.com/weblog/Trackback.aspx?guid=65627bb9-7d3e-4769-98e8-efdc138d9179</trackback:ping>
      <pingback:server>http://www.nesterovsky-bros.com/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,65627bb9-7d3e-4769-98e8-efdc138d9179.aspx</pingback:target>
      <dc:creator>Vladimir Nesterovsky</dc:creator>
      <georss:point>0 0</georss:point>
      <wfw:commentRss>http://www.nesterovsky-bros.com/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=65627bb9-7d3e-4769-98e8-efdc138d9179</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
In some code we needed to perform a circular shift of a part of array, like on the
following picture:
</p>
        <p>
          <img style="height: 10em;" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAm0AAAGvCAMAAAA+HRKuAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAMAUExURQAAAAICAgQAAAQEBAYGBgoAAA0AAAgICAoKCgwMDA4ODhYAABwAABAQEBISEhQUFBYWFhgYGBoaGhwcHB4eHjsAACEhISUlJSgoKCoqKiwsLC4uLjExMTU1NTk5OTw8PD4+PkY7O1E1NUBAQEJCQkVFRUhISEpKSkxMTE5OTlFRUVVVVVhXV1lZWVxcXF5eXmBgYGJiYmVlZWhoaGpqamxsbG5ubnJtbXBwcHJycnR0dHZ2dnl5eXx8fH5+frQKCqMqKoVGRtQGBugDA/YAAP8AAP8CAv8EBP8GBv8ICP8KCv8MDP8ODv8QEP8SEv8UFP8WFv8YGP8aGv8cHP8eHv8gIP8iIv8kJP8mJv8oKP8qKv8sLP8uLv8wMP8yMv80NP82Nv84OP86Ov88PP8+Pv9AQP9CQv9ERP9GRv9ISP9KSv9MTP9OTv9QUP9SUv9UVP9WVv9YWP9aWv9cXP9eXv9gYP9iYv9kZP9mZv9oaP9q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htsfbl4wHPhuYnZae9e5nxJ7ww1mdgbD4nxUf9ch0lZwlc+APrvs9VEoMtXmE22fOMLkl282/l78/rIzhE37jmocNOAy1GfgOQ20GvsNQm4HvMNRm4DsMtRn4DkNtBr7DUJuB7zDUZuAr7Pb/DiBWvoZFA+ccAAAAAElFTkSuQmCC" alt="" />
        </p>
        <p>
It's clear what to do, especially in case of one element shift but think about
"optimal" algorithm that does minimal number of data movemenents.
</p>
        <p>
Here is what we have came up with in C#: algorithm doing single pass over data.
</p>
        <blockquote>
          <pre>/// &lt;summary&gt;
/// &lt;para&gt;
/// Moves content of list within open range &lt;code&gt;[start, end)&lt;/code&gt;. 
/// &lt;code&gt;to&lt;/code&gt; should belong to that range.
/// &lt;/para&gt;
/// &lt;para&gt;
/// &lt;code&gt;list[start + (to - start + i) mod (end - start)] = 
/// list[start + i]&lt;/code&gt;, 
/// where i in range&lt;code&gt;[0, end - start)&lt;/ code &gt;.
/// &lt;/para&gt;
/// &lt;/summary&gt;
/// &lt;typeparam name="T"&gt;An element type.&lt;/typeparam&gt;
/// &lt;param name="list"&gt;A list to move data withing.&lt;/param&gt;
/// &lt;param name="start"&gt;Start position, including.&lt;/param&gt;
/// &lt;param name="end"&gt;End position, not incuding.&lt;/param&gt;
/// &lt;param name="to"&gt;Target position.&lt;/param&gt;
public static void CircularMove&lt;T&gt;(IList&lt;T&gt; list, int start, int end, int to)
{
  var size = end - start;
  var step = to - start;
  var anchor = start;
  var pos = start;
  var item = list[pos];

  for(int i = 0; i &lt; size; ++i)
  {
    pos += step;

    if (pos &gt;= end)
    {
      pos -= size;
    }

    var next = list[pos];

    list[pos] = item;
    item = next;

    if (pos == anchor)
    {
      pos = ++anchor;

      if (pos &gt;= end)
      {
        break;
      }

      item = list[pos];
    }
  }
}</pre>
        </blockquote>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=65627bb9-7d3e-4769-98e8-efdc138d9179" />
      </body>
      <title>Circular shift</title>
      <guid isPermaLink="false">http://www.nesterovsky-bros.com/weblog/PermaLink,guid,65627bb9-7d3e-4769-98e8-efdc138d9179.aspx</guid>
      <link>http://www.nesterovsky-bros.com/weblog/2018/06/07/CircularShift.aspx</link>
      <pubDate>Thu, 07 Jun 2018 10:20:27 GMT</pubDate>
      <description>  &lt;p&gt;
In some code we needed to perform a circular shift of a part of array, like on the
following picture:
&lt;/p&gt;
&lt;p&gt;
&lt;img style="height: 10em;" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAm0AAAGvCAMAAAA+HRKuAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAMAUExURQAAAAICAgQAAAQEBAYGBgoAAA0AAAgICAoKCgwMDA4ODhYAABwAABAQEBISEhQUFBYWFhgYGBoaGhwcHB4eHjsAACEhISUlJSgoKCoqKiwsLC4uLjExMTU1NTk5OTw8PD4+PkY7O1E1NUBAQEJCQkVFRUhISEpKSkxMTE5OTlFRUVVVVVhXV1lZWVxcXF5eXmBgYGJiYmVlZWhoaGpqamxsbG5ubnJtbXBwcHJycnR0dHZ2dnl5eXx8fH5+frQKCqMqKoVGRtQGBugDA/YAAP8AAP8CAv8EBP8GBv8ICP8KCv8MDP8ODv8QEP8SEv8UFP8WFv8YGP8aGv8cHP8eHv8gIP8iIv8kJP8mJv8oKP8qKv8sLP8uLv8wMP8yMv80NP82Nv84OP86Ov88PP8+Pv9AQP9CQv9ERP9GRv9ISP9KSv9MTP9OTv9QUP9SUv9UVP9WVv9YWP9aWv9cXP9eXv9gYP9iYv9kZP9mZv9oaP9qav9sbP9ubv9wcP9ycv90dP92dv94eP96ev98fP9+foGBgYSEhIaGhoiIiIqKioyMjI6OjpCQkJKSkpWVlZmZmZycnJ6enqCgoKKioqWlpaioqKqqqqysrK6urrCwsLKysra2tri4uLq6ur29vciHh8iensijo8iqqsizs/+AgP+Cgv+EhP+Ghv+IiP+Kiv+MjP+Ojv+QkP+Skv+UlP+Wlv+YmP+amv+cnP+env+goP+iov+kpP+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ift but think about
&amp;quot;optimal&amp;quot; algorithm that does minimal number of data movemenents.
&lt;/p&gt;
&lt;p&gt;
Here is what we have came up with in C#: algorithm doing single pass over data.
&lt;/p&gt;
&lt;blockquote&gt;&lt;pre&gt;/// &amp;lt;summary&gt;
/// &amp;lt;para&gt;
/// Moves content of list within open range &amp;lt;code&gt;[start, end)&amp;lt;/code&gt;. 
/// &amp;lt;code&gt;to&amp;lt;/code&gt; should belong to that range.
/// &amp;lt;/para&gt;
/// &amp;lt;para&gt;
/// &amp;lt;code&gt;list[start + (to - start + i) mod (end - start)] = 
/// list[start + i]&amp;lt;/code&gt;, 
/// where i in range&amp;lt;code&gt;[0, end - start)&amp;lt;/ code &gt;.
/// &amp;lt;/para&gt;
/// &amp;lt;/summary&gt;
/// &amp;lt;typeparam name="T"&gt;An element type.&amp;lt;/typeparam&gt;
/// &amp;lt;param name="list"&gt;A list to move data withing.&amp;lt;/param&gt;
/// &amp;lt;param name="start"&gt;Start position, including.&amp;lt;/param&gt;
/// &amp;lt;param name="end"&gt;End position, not incuding.&amp;lt;/param&gt;
/// &amp;lt;param name="to"&gt;Target position.&amp;lt;/param&gt;
public static void CircularMove&amp;lt;T&gt;(IList&amp;lt;T&gt; list, int start, int end, int to)
{
  var size = end - start;
  var step = to - start;
  var anchor = start;
  var pos = start;
  var item = list[pos];

  for(int i = 0; i &amp;lt; size; ++i)
  {
    pos += step;

    if (pos &gt;= end)
    {
      pos -= size;
    }

    var next = list[pos];

    list[pos] = item;
    item = next;

    if (pos == anchor)
    {
      pos = ++anchor;

      if (pos &gt;= end)
      {
        break;
      }

      item = list[pos];
    }
  }
}&lt;/pre&gt;&lt;/blockquote&gt; &lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=65627bb9-7d3e-4769-98e8-efdc138d9179" /&gt;</description>
      <comments>http://www.nesterovsky-bros.com/weblog/CommentView,guid,65627bb9-7d3e-4769-98e8-efdc138d9179.aspx</comments>
      <category>Tips and tricks</category>
    </item>
    <item>
      <trackback:ping>http://www.nesterovsky-bros.com/weblog/Trackback.aspx?guid=1040b8e9-5dc4-4af2-a83a-3554ec8bb5b3</trackback:ping>
      <pingback:server>http://www.nesterovsky-bros.com/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,1040b8e9-5dc4-4af2-a83a-3554ec8bb5b3.aspx</pingback:target>
      <dc:creator>Vladimir Nesterovsky</dc:creator>
      <georss:point>0 0</georss:point>
      <wfw:commentRss>http://www.nesterovsky-bros.com/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=1040b8e9-5dc4-4af2-a83a-3554ec8bb5b3</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
We often deal with different SQL DBs, and in particular DB2, Oracle, and SQL Server,
and this is what we have found lately.
</p>
        <p>
Our client has reported a problem with SQL insert into the DB2:
</p>
        <ul>
          <li>
subject table has a small number of columns, but large number of rows;</li>
          <li>
insert should attempt to insert a row but tolerate the duplicate.</li>
        </ul>
        <p>
The prototype table is like this:
</p>
        <blockquote>
          <pre>create table Link(FromID int, ToID int, primary key(FromID, ToID));</pre>
        </blockquote>
        <p>
DB2 SQL insert is like this:
</p>
        <blockquote>
          <pre>insert into Link(FromID, ToID)
values(1, 2)
except
select FromID, ToID from Link;</pre>
        </blockquote>
        <p>
The idea is to have empty row set to insert if there is a duplicate.
</p>
        <p>
SQL Server variant looks like this:
</p>
        <blockquote>
          <pre>insert into Link(FromID, ToID)
select 1, 2
except
select FromID, ToID from Link;</pre>
        </blockquote>
        <p>
Client reported ridiculously slow performance of this SQL, due to table scan to calculate
results of <code>except</code> operator.
</p>
        <p>
Out of interest we performed the same experiment with SQL Server, and found the execution
plan is optimal, and index seek is used to check duplicates. See:
</p>
        <img alt="Execution Plan" src="content/binary/SQLInsertExcept.png" style="width: 600px" />
        <p>
 
</p>
        <p>
The only reasonable way of dealing with such DB2's peculiarity, except trying
to insert and handle duplicate exception, was to qualify <code>select</code> with <code>where</code> clause:
</p>
        <blockquote>
          <pre>insert into Link(FromID, ToID)
values(1, 2)
except
select FromID, ToID from Link where FromID = 1 and ToID = 2;</pre>
        </blockquote>
        <p>
We think DB2 could do better.
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=1040b8e9-5dc4-4af2-a83a-3554ec8bb5b3" />
      </body>
      <title>SQL Server vs DB2</title>
      <guid isPermaLink="false">http://www.nesterovsky-bros.com/weblog/PermaLink,guid,1040b8e9-5dc4-4af2-a83a-3554ec8bb5b3.aspx</guid>
      <link>http://www.nesterovsky-bros.com/weblog/2018/04/14/SQLServerVsDB2.aspx</link>
      <pubDate>Sat, 14 Apr 2018 19:38:20 GMT</pubDate>
      <description>&lt;p&gt;
We often deal with different SQL DBs, and in particular DB2, Oracle, and SQL Server,
and this is what we have found lately.
&lt;/p&gt;
&lt;p&gt;
Our client has reported a problem with SQL insert into the DB2:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
subject table has a small number of columns, but large number of rows;&lt;/li&gt;
&lt;li&gt;
insert should attempt to insert a row but tolerate the duplicate.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
The prototype table is like this:
&lt;/p&gt;
&lt;blockquote&gt;&lt;pre&gt;create table Link(FromID int, ToID int, primary key(FromID, ToID));&lt;/pre&gt;&lt;/blockquote&gt; 
&lt;p&gt;
DB2 SQL insert is like this:
&lt;/p&gt;
&lt;blockquote&gt;&lt;pre&gt;insert into Link(FromID, ToID)
values(1, 2)
except
select FromID, ToID from Link;&lt;/pre&gt;&lt;/blockquote&gt; 
&lt;p&gt;
The idea is to have empty row set to insert if there is a duplicate.
&lt;/p&gt;
&lt;p&gt;
SQL Server variant looks like this:
&lt;/p&gt;
&lt;blockquote&gt;&lt;pre&gt;insert into Link(FromID, ToID)
select 1, 2
except
select FromID, ToID from Link;&lt;/pre&gt;&lt;/blockquote&gt; 
&lt;p&gt;
Client reported ridiculously slow performance of this SQL, due to table scan to calculate
results of &lt;code&gt;except&lt;/code&gt; operator.
&lt;/p&gt;
&lt;p&gt;
Out of interest we performed the same experiment with SQL Server, and found the execution
plan is optimal, and index seek is used to check duplicates. See:
&lt;/p&gt;
&lt;img alt="Execution Plan" src="content/binary/SQLInsertExcept.png" style="width: 600px" /&gt; 
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
The only reasonable way of dealing with such DB2&amp;#39;s peculiarity, except trying
to insert and handle duplicate exception, was to qualify &lt;code&gt;select&lt;/code&gt; with &lt;code&gt;where&lt;/code&gt; clause:
&lt;/p&gt;
&lt;blockquote&gt;&lt;pre&gt;insert into Link(FromID, ToID)
values(1, 2)
except
select FromID, ToID from Link where FromID = 1 and ToID = 2;&lt;/pre&gt;&lt;/blockquote&gt; 
&lt;p&gt;
We think DB2 could do better.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=1040b8e9-5dc4-4af2-a83a-3554ec8bb5b3" /&gt;</description>
      <comments>http://www.nesterovsky-bros.com/weblog/CommentView,guid,1040b8e9-5dc4-4af2-a83a-3554ec8bb5b3.aspx</comments>
      <category>SQL Server puzzle</category>
      <category>Thinking aloud</category>
    </item>
    <item>
      <trackback:ping>http://www.nesterovsky-bros.com/weblog/Trackback.aspx?guid=d5f3031a-b737-4566-a963-75011df3015a</trackback:ping>
      <pingback:server>http://www.nesterovsky-bros.com/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,d5f3031a-b737-4566-a963-75011df3015a.aspx</pingback:target>
      <dc:creator>Vladimir Nesterovsky</dc:creator>
      <georss:point>0 0</georss:point>
      <wfw:commentRss>http://www.nesterovsky-bros.com/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=d5f3031a-b737-4566-a963-75011df3015a</wfw:commentRss>
      <title>JAXB and java.time.* types</title>
      <guid isPermaLink="false">http://www.nesterovsky-bros.com/weblog/PermaLink,guid,d5f3031a-b737-4566-a963-75011df3015a.aspx</guid>
      <link>http://www.nesterovsky-bros.com/weblog/2018/01/24/JAXBAndJavatimeTypes.aspx</link>
      <pubDate>Wed, 24 Jan 2018 06:46:41 GMT</pubDate>
      <description>  &lt;p&gt;
J2SE has become sole large that its different parts don&amp;#39;t play well.
&lt;/p&gt;
&lt;p&gt;
That is pitty but nothing to do. There is probably a lack of resources in Oracle to
fill gaps.
&lt;/p&gt;
&lt;p&gt;
So, to the point. 
&lt;/p&gt;
&lt;p&gt;
There is relatively new API to work with time defined in: &lt;a href="https://docs.oracle.com/javase/8/docs/api/java/time/package-summary.html"&gt;package
java.time&lt;/a&gt;. There is older API &lt;a href="https://docs.oracle.com/javase/8/docs/technotes/guides/xml/jaxb/index.html"&gt;JAXB&lt;/a&gt; to
serialize and deserialize beans to and from XML (and often to JSON). To JAXB viable,
it should be able to deal with basic primitive types. The problem is that JAXB does
not handle &lt;a href="https://docs.oracle.com/javase/8/docs/api/java/time/LocalDate.html"&gt;LocalDate&lt;/a&gt;, &lt;a href="https://docs.oracle.com/javase/8/docs/api/java/time/LocalTime.html"&gt;LocalTime&lt;/a&gt;, &lt;a href="https://docs.oracle.com/javase/8/docs/api/java/time/LocalDateTime.html"&gt;LocalDateTime&lt;/a&gt;,
and &lt;a href="https://docs.oracle.com/javase/8/docs/api/java/time/ZonedDateTime.html"&gt;ZonedDateTime&lt;/a&gt; out
of the box.
&lt;/p&gt;
&lt;p&gt;
We do understand that:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
JAXB is older and java.time is newer API; and that&lt;/li&gt;
&lt;li&gt;
JAXB has no built-in plugin to handle new types.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
But this does not help, and we should define/redefine serialization adapters using
some drop in code or third party libraries. Here are these convenience adapters:
&lt;/p&gt;
&lt;blockquote&gt; 
&lt;p&gt;
&lt;b&gt;LocalDateAdapter.java&lt;/b&gt;
&lt;/p&gt;
&lt;pre&gt;&lt; 0)
    {
      return LocalDate.parse(value);
    }
    
    while(++p &lt; value.length())
    {
      switch(value.charAt(p)) 
      {
        case '+':
        case '-':
        case 'Z':
        {
          return ZonedDateTime.parse(value).toLocalDate();
        }
      }
      
    }
    
    return LocalDateTime.parse(value).toLocalDate();
  }
}&lt;/pre&gt;import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZonedDateTime;

import javax.xml.bind.annotation.adapters.XmlAdapter;

/**
 * An adapter for the bean properties of {@link LocalDate} type. 
 */
public class LocalDateAdapter extends XmlAdapter&amp;lt;String, LocalDate&gt;
{
  /**
   * Converts {@link LocalDate} into a string value.
   * @param value a value to convert. Can be null.
   * @return a string value.
   */
  @Override
  public String marshal(LocalDate value)
    throws Exception
  {
    return value == null ? null : value.toString();
  }

  /**
   * Converts a string value into a {@link LocalDate}
   * instance.
   * @param value a value to convert. Can be null.
   * @return a {@link LocalDate} instance.
   */
  @Override
  public LocalDate unmarshal(String value)
    throws Exception
  {
    if (value == null)
    {
      return null;
    }
    
    int p = value.indexOf('T');
    
    if (p 
        
&lt;p&gt;
&lt;b&gt;LocalDateTimeAdapter.java&lt;/b&gt;
&lt;/p&gt;
&lt;pre&gt;&lt; 0)
    {
      return LocalDateTime.of(LocalDate.parse(value), LocalTime.MIN);
    }
    
    while(++p &lt; value.length())
    {
      switch(value.charAt(p)) 
      {
        case '+':
        case '-':
        case 'Z':
        {
          return ZonedDateTime.parse(value).toLocalDateTime();
        }
      }
      
    }
    
    return LocalDateTime.parse(value);
  }
}&lt;/pre&gt;import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.ZonedDateTime;

import javax.xml.bind.annotation.adapters.XmlAdapter;

/**
 * An adapter for the bean properties of {@link LocalDateTime} type. 
 */
public class LocalDateTimeAdapter extends XmlAdapter&amp;lt;String, LocalDateTime&gt;
{
  /**
   * Converts {@link LocalDateTime} into a string value.
   * @param value a value to convert. Can be null.
   * @return a string value.
   */
  @Override
  public String marshal(LocalDateTime value)
    throws Exception
  {
    return value == null ? null : value.toString();
  }

  /**
   * Converts a string value into a {@link LocalDateTime}  instance.
   * @param value a value to convert. Can be null.
   * @return a {@link LocalDateTime} instance.
   */
  @Override
  public LocalDateTime unmarshal(String value) 
    throws Exception
  {
    if (value == null)
    {
      return null;
    }
    
    int p = value.indexOf('T');
    
    if (p 
        
&lt;p&gt;
&lt;b&gt;LocalTimeAdapter.java&lt;/b&gt;
&lt;/p&gt;
&lt;pre&gt;import java.time.LocalDate;import java.time.LocalTime;

import javax.xml.bind.annotation.adapters.XmlAdapter;

/**
 * An adapter for the bean properties of {@link LocalTime} type. 
 */
public class LocalTimeAdapter extends XmlAdapter&amp;lt;String, LocalTime&gt;
{
  /**
   * Converts {@link LocalTime} into string value.
   * @param value a value to convert. Can be null.
   * @return a string value
   */
  @Override
  public String marshal(LocalTime value)
    throws Exception
  {
    return value == null ? null : value.toString();
  }

  /**
   * Converts a string value into a {@link LocalTime} instance.
   * @param value a value to convert. Can be null.
   * @return a {@link LocalTime} instance.
   */
  @Override
  public LocalTime unmarshal(String value)
    throws Exception
  {
    return value == null ? null : LocalTime.parse(value);
  }
}
&lt;/pre&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
To make them work either field/properties or package should be annotated with JAXB
xml adapters.
&lt;/p&gt;
&lt;p&gt;
The simplest way is to annotate it on package level like this:
&lt;/p&gt;
&lt;blockquote&gt; 
&lt;p&gt;
&lt;b&gt;package-info.java&lt;/b&gt;
&lt;/p&gt;
&lt;pre&gt;@XmlJavaTypeAdapters(
{
  @XmlJavaTypeAdapter(value = LocalDateAdapter.class, type = LocalDate.class),
  @XmlJavaTypeAdapter(value = LocalTimeAdapter.class, type = LocalTime.class),
  @XmlJavaTypeAdapter(value = LocalDateTimeAdapter.class, type = LocalDateTime.class)
})
package com.nesterovskyBros.demo.entities;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;

import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapters;
&lt;/pre&gt;
&lt;/blockquote&gt;&lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=d5f3031a-b737-4566-a963-75011df3015a" /&gt;</description>
      <comments>http://www.nesterovsky-bros.com/weblog/CommentView,guid,d5f3031a-b737-4566-a963-75011df3015a.aspx</comments>
      <category>Java</category>
      <category>Tips and tricks</category>
    </item>
    <item>
      <trackback:ping>http://www.nesterovsky-bros.com/weblog/Trackback.aspx?guid=0d98518f-b70e-4cb7-9e10-0004ebfc43b3</trackback:ping>
      <pingback:server>http://www.nesterovsky-bros.com/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,0d98518f-b70e-4cb7-9e10-0004ebfc43b3.aspx</pingback:target>
      <dc:creator>Vladimir Nesterovsky</dc:creator>
      <georss:point>0 0</georss:point>
      <wfw:commentRss>http://www.nesterovsky-bros.com/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=0d98518f-b70e-4cb7-9e10-0004ebfc43b3</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
We've run into following java function that models some variation of NULL arithmetic:
</p>
        <blockquote>
          <pre>public static Long add(Long value1, Long value2)
{
  return value1 == null ? value2 : value2 == null ? value1 : value1 + value2;
}</pre>
        </blockquote>
        <p>
When this function runs the outcome is different from what we have expected.
</p>
        <p>
Here is a quiz:
</p>
        <ol>
          <li>
            <p>
What is outcome of <code>add(1, 2)</code>:
</p>
            <ol style="list-style-type: lower-alpha">
              <li>
                <code>3</code>;</li>
              <li>
                <code>null</code>;</li>
              <li>
other.</li>
            </ol>
          </li>
          <li>
            <p>
What is outcome of <code>add(3, null)</code>:
</p>
            <ol style="list-style-type: lower-alpha">
              <li>
                <code>3</code>;</li>
              <li>
                <code>null</code>;</li>
              <li>
other.</li>
            </ol>
          </li>
          <li>
            <p>
What is outcome of <code>add(null, 4)</code>:
</p>
            <ol style="list-style-type: lower-alpha">
              <li>
                <code>null</code>;</li>
              <li>
                <code>4</code>;</li>
              <li>
other.</li>
            </ol>
          </li>
          <li>
            <p>
What is outcome of <code>add(null, null)</code>:
</p>
            <ol style="list-style-type: lower-alpha">
              <li>
                <code>null</code>;</li>
              <li>
                <code>0</code>;</li>
              <li>
other.</li>
            </ol>
          </li>
        </ol>
        <p>
Our assumptions were:
</p>
        <ol>
          <li>
            <code>add(1, 2) == 3</code>;</li>
          <li>
            <code>add(3, null) == 3</code>;</li>
          <li>
            <code>add(null, 4) == 4</code>;</li>
          <li>
            <code>add(null, null) == null</code>;</li>
        </ol>
        <p>
Java works differently:
</p>
        <ol>
          <li>
            <code>add(1, 2) == 3</code>;</li>
          <li>
            <code>add(3, null) throws NullPointerException</code>;</li>
          <li>
            <code>add(null, 4) throws NullPointerException</code>;</li>
          <li>
            <code>add(null, null) throws NullPointerException</code>;</li>
        </ol>
        <p>
The problem is with compile time type of ternary <code>?:</code> operator. Compiler
decides it's <code>long</code>, while we intuitively expected <code>Long</code>. Java
casts <code>null</code> to <code>long</code> (which results into <code>NPE</code>),
and then to <code>Long</code>.
</p>
        <p>
Correct code would be:
</p>
        <blockquote>
          <pre>public static Long add(Long value1, Long value2)
{
  if (value1 == null)
  {
    return value2;
  }
  else if (value2 == null)
  {
    return value;
  }
  else
  {
    return value1 + value2;
  }
}</pre>
        </blockquote>
        <p>
This version does not cast anything to <code>long</code>, and works as we originally
expected.
</p>
        <p>
Honestly, we're a bit anexious about this subtle difference of <code>if-then-else</code> and <code>?:</code> operator.
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=0d98518f-b70e-4cb7-9e10-0004ebfc43b3" />
      </body>
      <title>Ternary expression type in java.</title>
      <guid isPermaLink="false">http://www.nesterovsky-bros.com/weblog/PermaLink,guid,0d98518f-b70e-4cb7-9e10-0004ebfc43b3.aspx</guid>
      <link>http://www.nesterovsky-bros.com/weblog/2017/11/22/TernaryExpressionTypeInJava.aspx</link>
      <pubDate>Wed, 22 Nov 2017 12:00:23 GMT</pubDate>
      <description>  &lt;p&gt;
We&amp;#39;ve run into following java function that models some variation of NULL arithmetic:
&lt;/p&gt;
&lt;blockquote&gt;&lt;pre&gt;public static Long add(Long value1, Long value2)
{
  return value1 == null ? value2 : value2 == null ? value1 : value1 + value2;
}&lt;/pre&gt;&lt;/blockquote&gt; 
&lt;p&gt;
When this function runs the outcome is different from what we have expected.
&lt;/p&gt;
&lt;p&gt;
Here is a quiz:
&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;
What is outcome of &lt;code&gt;add(1, 2)&lt;/code&gt;:
&lt;/p&gt;
&lt;ol style="list-style-type: lower-alpha"&gt;
&lt;li&gt;
&lt;code&gt;3&lt;/code&gt;;&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;null&lt;/code&gt;;&lt;/li&gt;
&lt;li&gt;
other.&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;
What is outcome of &lt;code&gt;add(3, null)&lt;/code&gt;:
&lt;/p&gt;
&lt;ol style="list-style-type: lower-alpha"&gt;
&lt;li&gt;
&lt;code&gt;3&lt;/code&gt;;&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;null&lt;/code&gt;;&lt;/li&gt;
&lt;li&gt;
other.&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;
What is outcome of &lt;code&gt;add(null, 4)&lt;/code&gt;:
&lt;/p&gt;
&lt;ol style="list-style-type: lower-alpha"&gt;
&lt;li&gt;
&lt;code&gt;null&lt;/code&gt;;&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;4&lt;/code&gt;;&lt;/li&gt;
&lt;li&gt;
other.&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;
What is outcome of &lt;code&gt;add(null, null)&lt;/code&gt;:
&lt;/p&gt;
&lt;ol style="list-style-type: lower-alpha"&gt;
&lt;li&gt;
&lt;code&gt;null&lt;/code&gt;;&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;0&lt;/code&gt;;&lt;/li&gt;
&lt;li&gt;
other.&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;
Our assumptions were:
&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;add(1, 2) == 3&lt;/code&gt;;&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;add(3, null) == 3&lt;/code&gt;;&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;add(null, 4) == 4&lt;/code&gt;;&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;add(null, null) == null&lt;/code&gt;;&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;
Java works differently:
&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;add(1, 2) == 3&lt;/code&gt;;&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;add(3, null) throws NullPointerException&lt;/code&gt;;&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;add(null, 4) throws NullPointerException&lt;/code&gt;;&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;add(null, null) throws NullPointerException&lt;/code&gt;;&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;
The problem is with compile time type of ternary &lt;code&gt;?:&lt;/code&gt; operator. Compiler
decides it's &lt;code&gt;long&lt;/code&gt;, while we intuitively expected &lt;code&gt;Long&lt;/code&gt;. Java
casts &lt;code&gt;null&lt;/code&gt; to &lt;code&gt;long&lt;/code&gt; (which results into &lt;code&gt;NPE&lt;/code&gt;),
and then to &lt;code&gt;Long&lt;/code&gt;.
&lt;/p&gt;
&lt;p&gt;
Correct code would be:
&lt;/p&gt;
&lt;blockquote&gt;&lt;pre&gt;public static Long add(Long value1, Long value2)
{
  if (value1 == null)
  {
    return value2;
  }
  else if (value2 == null)
  {
    return value;
  }
  else
  {
    return value1 + value2;
  }
}&lt;/pre&gt;&lt;/blockquote&gt; 
&lt;p&gt;
This version does not cast anything to &lt;code&gt;long&lt;/code&gt;, and works as we originally
expected.
&lt;/p&gt;
&lt;p&gt;
Honestly, we&amp;#39;re a bit anexious about this subtle difference of &lt;code&gt;if-then-else&lt;/code&gt; and &lt;code&gt;?:&lt;/code&gt; operator.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=0d98518f-b70e-4cb7-9e10-0004ebfc43b3" /&gt;</description>
      <comments>http://www.nesterovsky-bros.com/weblog/CommentView,guid,0d98518f-b70e-4cb7-9e10-0004ebfc43b3.aspx</comments>
      <category>Java</category>
      <category>Tips and tricks</category>
    </item>
    <item>
      <trackback:ping>http://www.nesterovsky-bros.com/weblog/Trackback.aspx?guid=3afd0395-7226-4773-915a-956b0bb3a598</trackback:ping>
      <pingback:server>http://www.nesterovsky-bros.com/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,3afd0395-7226-4773-915a-956b0bb3a598.aspx</pingback:target>
      <dc:creator>Vladimir Nesterovsky</dc:creator>
      <georss:point>0 0</georss:point>
      <wfw:commentRss>http://www.nesterovsky-bros.com/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=3afd0395-7226-4773-915a-956b0bb3a598</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Don't you think there is something wrong with world map according to Yandex?
</p>
        <p>
          <img src="http://www.nesterovsky-bros.com/images/WorldAccordingToYandex.png" style="width: 600px" />
        </p>
        <p>
They seems have optimized something in Black Sea region.
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=3afd0395-7226-4773-915a-956b0bb3a598" />
      </body>
      <title>World according to Yandex</title>
      <guid isPermaLink="false">http://www.nesterovsky-bros.com/weblog/PermaLink,guid,3afd0395-7226-4773-915a-956b0bb3a598.aspx</guid>
      <link>http://www.nesterovsky-bros.com/weblog/2017/09/02/WorldAccordingToYandex.aspx</link>
      <pubDate>Sat, 02 Sep 2017 14:58:06 GMT</pubDate>
      <description>&lt;p&gt;
Don&amp;#39;t you think there is something wrong with world map according to Yandex?
&lt;/p&gt;
&lt;p&gt;
&lt;img src="http://www.nesterovsky-bros.com/images/WorldAccordingToYandex.png" style="width: 600px" /&gt;
&lt;/p&gt;
&lt;p&gt;
They seems have optimized something in Black Sea region.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=3afd0395-7226-4773-915a-956b0bb3a598" /&gt;</description>
      <comments>http://www.nesterovsky-bros.com/weblog/CommentView,guid,3afd0395-7226-4773-915a-956b0bb3a598.aspx</comments>
    </item>
    <item>
      <trackback:ping>http://www.nesterovsky-bros.com/weblog/Trackback.aspx?guid=9edf3c0e-34f1-4d4a-97ec-94922826204c</trackback:ping>
      <pingback:server>http://www.nesterovsky-bros.com/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,9edf3c0e-34f1-4d4a-97ec-94922826204c.aspx</pingback:target>
      <dc:creator>Vladimir Nesterovsky</dc:creator>
      <georss:point>0 0</georss:point>
      <wfw:commentRss>http://www.nesterovsky-bros.com/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=9edf3c0e-34f1-4d4a-97ec-94922826204c</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Today we wanted to write some code in java that performs some or the other action
depending on a condition. At the same time if some action fails we wanted to fall
back to the other action.
</p>
        <p>
We've written it like this:
</p>
        <blockquote>
          <pre>
switch(boolean_expression)
{
  case true:
  {
    try
    {
      // Some actions.
      break;
    }
    catch(Exception e)
    {
      // Fall back to false route. 
    }
  }
  case false:
  {
    // Other actions.
    break;
  }
}
</pre>
        </blockquote>
        <p>
The fun part is that it's not valid java code.
</p>
        <p>
Why?
</p>
        <p>
The answer can be found in spec: <a href="http://docs.oracle.com/javase/specs/jls/se7/html/jls-14.html#jls-14.11">14.11.
The <code>switch</code> Statement</a></p>
        <blockquote>
          <i> The type of the Expression must be <code>char</code>, <code>byte</code>, <code>short</code>, <code>int</code>, <code>Character</code>, <code>Byte</code>, <code>Short</code>, <code>Integer</code>, <code>String</code>,
or an enum type (<a href="http://docs.oracle.com/javase/specs/jls/se7/html/jls-8.html#jls-8.9" title="8.9. Enums">§8.9</a>),
or a compile-time error occurs. </i>
        </blockquote>
        <p>
But why?
</p>
        <p>
Who knows...
</p>
        <p>
Sure there are workarounds, even with switch, but it just not justified restriction...
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=9edf3c0e-34f1-4d4a-97ec-94922826204c" />
      </body>
      <title>Some fun with java switch</title>
      <guid isPermaLink="false">http://www.nesterovsky-bros.com/weblog/PermaLink,guid,9edf3c0e-34f1-4d4a-97ec-94922826204c.aspx</guid>
      <link>http://www.nesterovsky-bros.com/weblog/2017/08/22/SomeFunWithJavaSwitch.aspx</link>
      <pubDate>Tue, 22 Aug 2017 15:18:29 GMT</pubDate>
      <description>  &lt;p&gt;
Today we wanted to write some code in java that performs some or the other action
depending on a condition. At the same time if some action fails we wanted to fall
back to the other action.
&lt;/p&gt;
&lt;p&gt;
We've written it like this:
&lt;/p&gt;
&lt;blockquote&gt;&lt;pre&gt;
switch(boolean_expression)
{
  case true:
  {
    try
    {
      // Some actions.
      break;
    }
    catch(Exception e)
    {
      // Fall back to false route. 
    }
  }
  case false:
  {
    // Other actions.
    break;
  }
}
&lt;/pre&gt;&lt;/blockquote&gt; 
&lt;p&gt;
The fun part is that it&amp;#39;s not valid java code.
&lt;/p&gt;
&lt;p&gt;
Why?
&lt;/p&gt;
&lt;p&gt;
The answer can be found in spec: &lt;a href="http://docs.oracle.com/javase/specs/jls/se7/html/jls-14.html#jls-14.11"&gt;14.11.
The &lt;code&gt;switch&lt;/code&gt; Statement&lt;/a&gt; 
&lt;/p&gt;
&lt;blockquote&gt;&lt;i&gt; The type of the Expression must be &lt;code&gt;char&lt;/code&gt;, &lt;code&gt;byte&lt;/code&gt;, &lt;code&gt;short&lt;/code&gt;, &lt;code&gt;int&lt;/code&gt;, &lt;code&gt;Character&lt;/code&gt;, &lt;code&gt;Byte&lt;/code&gt;, &lt;code&gt;Short&lt;/code&gt;, &lt;code&gt;Integer&lt;/code&gt;, &lt;code&gt;String&lt;/code&gt;,
or an enum type (&lt;a href="http://docs.oracle.com/javase/specs/jls/se7/html/jls-8.html#jls-8.9" title="8.9. Enums"&gt;§8.9&lt;/a&gt;),
or a compile-time error occurs. &lt;/i&gt;&lt;/blockquote&gt; 
&lt;p&gt;
But why?
&lt;/p&gt;
&lt;p&gt;
Who knows...
&lt;/p&gt;
&lt;p&gt;
Sure there are workarounds, even with switch, but it just not justified restriction...
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=9edf3c0e-34f1-4d4a-97ec-94922826204c" /&gt;</description>
      <comments>http://www.nesterovsky-bros.com/weblog/CommentView,guid,9edf3c0e-34f1-4d4a-97ec-94922826204c.aspx</comments>
      <category>Java</category>
      <category>Thinking aloud</category>
    </item>
    <item>
      <trackback:ping>http://www.nesterovsky-bros.com/weblog/Trackback.aspx?guid=9b8bdeb4-d197-4485-9c5c-c7778d962c68</trackback:ping>
      <pingback:server>http://www.nesterovsky-bros.com/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,9b8bdeb4-d197-4485-9c5c-c7778d962c68.aspx</pingback:target>
      <dc:creator>Vladimir Nesterovsky</dc:creator>
      <georss:point>0 0</georss:point>
      <wfw:commentRss>http://www.nesterovsky-bros.com/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=9b8bdeb4-d197-4485-9c5c-c7778d962c68</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Saxon-HE 9.8.0-3 is out but still problems are there.
</p>
        <p>
See <a href="https://saxonica.plan.io/boards/3/topics/6872">Incorrect behavior in
Saxon-HE-9.8.0-3 (maven)</a>.
</p>
        <p>
Another problem is that we see that something has propably happened with tail call
optimization. Code that was working earlier now give an error:
</p>
        <p>
err:SXLM0001: Too many nested function calls. May be due to infinite recursion.
</p>
        <p>
We have to figure out how to build a simple TC for Michael Kay to test it.
</p>
        <p>
See <a href="https://saxonica.plan.io/boards/3/topics/6875">Saxon-HE 9.8.0-3 Tail
Calls</a>.
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=9b8bdeb4-d197-4485-9c5c-c7778d962c68" />
      </body>
      <title>Incorrect behavior in Saxon-HE-9.8.0-3 (maven)</title>
      <guid isPermaLink="false">http://www.nesterovsky-bros.com/weblog/PermaLink,guid,9b8bdeb4-d197-4485-9c5c-c7778d962c68.aspx</guid>
      <link>http://www.nesterovsky-bros.com/weblog/2017/07/15/IncorrectBehaviorInSaxonHE9803Maven.aspx</link>
      <pubDate>Sat, 15 Jul 2017 14:14:43 GMT</pubDate>
      <description>&lt;p&gt;
Saxon-HE 9.8.0-3 is out but still problems are there.
&lt;/p&gt;
&lt;p&gt;
See &lt;a href="https://saxonica.plan.io/boards/3/topics/6872"&gt;Incorrect behavior in
Saxon-HE-9.8.0-3 (maven)&lt;/a&gt;.
&lt;/p&gt;
&lt;p&gt;
Another problem is that we see that something has propably happened with tail call
optimization. Code that was working earlier now give an error:
&lt;/p&gt;
&lt;p&gt;
err:SXLM0001: Too many nested function calls. May be due to infinite recursion.
&lt;/p&gt;
&lt;p&gt;
We have to figure out how to build a simple TC for Michael Kay to test it.
&lt;/p&gt;
&lt;p&gt;
See &lt;a href="https://saxonica.plan.io/boards/3/topics/6875"&gt;Saxon-HE 9.8.0-3 Tail
Calls&lt;/a&gt;.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=9b8bdeb4-d197-4485-9c5c-c7778d962c68" /&gt;</description>
      <comments>http://www.nesterovsky-bros.com/weblog/CommentView,guid,9b8bdeb4-d197-4485-9c5c-c7778d962c68.aspx</comments>
    </item>
    <item>
      <trackback:ping>http://www.nesterovsky-bros.com/weblog/Trackback.aspx?guid=7a16adad-f987-4c87-909e-3bcc856c58a6</trackback:ping>
      <pingback:server>http://www.nesterovsky-bros.com/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,7a16adad-f987-4c87-909e-3bcc856c58a6.aspx</pingback:target>
      <dc:creator>Vladimir Nesterovsky</dc:creator>
      <georss:point>0 0</georss:point>
      <wfw:commentRss>http://www.nesterovsky-bros.com/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=7a16adad-f987-4c87-909e-3bcc856c58a6</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
We've found that there is a Saxon HE update that was going to fix problems we mentioned
in the previous post, and decided to give it a second chance.
</p>
        <p>
Now Saxon fails with two other errors:
</p>
        <ul>
          <li>
            <a href="https://saxonica.plan.io/boards/3/topics/6838">Bad parent pointer message
in Saxon-HE-9.8.0-2</a>
          </li>
          <li>
            <a href="https://saxonica.plan.io/boards/3/topics/6839">XTDE1061: There is no current
group in Saxon-HE-9.8.0-2</a>
          </li>
        </ul>
        <p>
We shall be waiting for the fixes. Mean time we're back to version 9.7.
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=7a16adad-f987-4c87-909e-3bcc856c58a6" />
      </body>
      <title>Saxon 9.8.0-2 second attempt.</title>
      <guid isPermaLink="false">http://www.nesterovsky-bros.com/weblog/PermaLink,guid,7a16adad-f987-4c87-909e-3bcc856c58a6.aspx</guid>
      <link>http://www.nesterovsky-bros.com/weblog/2017/06/27/Saxon9802SecondAttempt.aspx</link>
      <pubDate>Tue, 27 Jun 2017 22:30:28 GMT</pubDate>
      <description>&lt;p&gt;
We've found that there is a Saxon HE update that was going to fix problems we mentioned
in the previous post, and decided to give it a second chance.
&lt;/p&gt;
&lt;p&gt;
Now Saxon fails with two other errors:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://saxonica.plan.io/boards/3/topics/6838"&gt;Bad parent pointer message
in Saxon-HE-9.8.0-2&lt;/a&gt; 
&lt;li&gt;
&lt;a href="https://saxonica.plan.io/boards/3/topics/6839"&gt;XTDE1061: There is no current
group in Saxon-HE-9.8.0-2&lt;/a&gt; 
&lt;/ul&gt;
&lt;p&gt;
We shall be waiting for the fixes. Mean time we're back to version 9.7.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=7a16adad-f987-4c87-909e-3bcc856c58a6" /&gt;</description>
      <comments>http://www.nesterovsky-bros.com/weblog/CommentView,guid,7a16adad-f987-4c87-909e-3bcc856c58a6.aspx</comments>
      <category>Announce</category>
      <category>xslt</category>
    </item>
    <item>
      <trackback:ping>http://www.nesterovsky-bros.com/weblog/Trackback.aspx?guid=af6dddad-e60e-4f56-83b2-e9f3fce700fd</trackback:ping>
      <pingback:server>http://www.nesterovsky-bros.com/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,af6dddad-e60e-4f56-83b2-e9f3fce700fd.aspx</pingback:target>
      <dc:creator>Vladimir Nesterovsky</dc:creator>
      <georss:point>0 0</georss:point>
      <wfw:commentRss>http://www.nesterovsky-bros.com/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=af6dddad-e60e-4f56-83b2-e9f3fce700fd</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">Finally, Saxon 9.8 is out!<br />
This means that basic xslt 3 is available in the HE version.<br /><br />
Update: as usually, each new release has new bugs...<br />
See https://saxonica.plan.io/boards/3/topics/6809<img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=af6dddad-e60e-4f56-83b2-e9f3fce700fd" /></body>
      <title>Saxon 9.8 is out</title>
      <guid isPermaLink="false">http://www.nesterovsky-bros.com/weblog/PermaLink,guid,af6dddad-e60e-4f56-83b2-e9f3fce700fd.aspx</guid>
      <link>http://www.nesterovsky-bros.com/weblog/2017/06/14/Saxon98IsOut.aspx</link>
      <pubDate>Wed, 14 Jun 2017 21:05:51 GMT</pubDate>
      <description>Finally, Saxon 9.8 is out!&lt;br /&gt;
This means that basic xslt 3 is available in the HE version.&lt;br&gt;
&lt;br&gt;
Update: as usually, each new release has new bugs...&lt;br&gt;
See https://saxonica.plan.io/boards/3/topics/6809&lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=af6dddad-e60e-4f56-83b2-e9f3fce700fd" /&gt;</description>
      <comments>http://www.nesterovsky-bros.com/weblog/CommentView,guid,af6dddad-e60e-4f56-83b2-e9f3fce700fd.aspx</comments>
      <category>xslt</category>
    </item>
    <item>
      <trackback:ping>http://www.nesterovsky-bros.com/weblog/Trackback.aspx?guid=824d5dcd-a1a5-4314-b7fa-1e4447417c9f</trackback:ping>
      <pingback:server>http://www.nesterovsky-bros.com/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,824d5dcd-a1a5-4314-b7fa-1e4447417c9f.aspx</pingback:target>
      <dc:creator>Vladimir Nesterovsky</dc:creator>
      <georss:point>0 0</georss:point>
      <wfw:commentRss>http://www.nesterovsky-bros.com/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=824d5dcd-a1a5-4314-b7fa-1e4447417c9f</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
We have found that Saxon HE 9.7.0-18 has finally exposed partial support to map and
array item types. So, now you can encapsulate your data in sequence rather than having
a single sequence and treating odd and even elements specially.
</p>
        <p>
Basic example is:
</p>
        <blockquote>
          <pre>&lt;xsl:stylesheet version="3.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:xs="http://www.w3.org/2001/XMLSchema"
  xmlns:t="t"
  xmlns:map="http://www.w3.org/2005/xpath-functions/map"
  exclude-result-prefixes="xs t map"&gt;

  &lt;xsl:template match="/"&gt;
    &lt;xsl:variable name="map" as="map(xs:string, xs:string)" select="
      map 
      {
        'Su': 'Sunday',
        'Mo': 'Monday',
        'Tu': 'Tuesday',
        'We': 'Wednesday',
        'Th': 'Thursday',
        'Fr': 'Friday',
        'Sa': 'Saturday'
      }"/&gt;
      
     &lt;xsl:message select="map:keys($map)"/&gt;
  &lt;/xsl:template&gt;  

&lt;/xsl:stylesheet&gt;</pre>
        </blockquote>
        <p>
A list of map functions can be found here <a href="http://www.w3.org/2005/xpath-functions/map/">http://www.w3.org/2005/xpath-functions/map/</a>,
though not all are available, as Saxon HE still does not allow inline functions.
</p>
        <p>
P.S. From the development perspective it's a great harm that Saxon HE is so limited.
Basically limited to xslt 2.0 + some selected parts of 3.0.
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=824d5dcd-a1a5-4314-b7fa-1e4447417c9f" />
      </body>
      <title>Saxon HE map and array types.</title>
      <guid isPermaLink="false">http://www.nesterovsky-bros.com/weblog/PermaLink,guid,824d5dcd-a1a5-4314-b7fa-1e4447417c9f.aspx</guid>
      <link>http://www.nesterovsky-bros.com/weblog/2017/05/16/SaxonHEMapAndArrayTypes.aspx</link>
      <pubDate>Tue, 16 May 2017 06:20:48 GMT</pubDate>
      <description>  &lt;p&gt;
We have found that Saxon HE 9.7.0-18 has finally exposed partial support to map and
array item types. So, now you can encapsulate your data in sequence rather than having
a single sequence and treating odd and even elements specially.
&lt;/p&gt;
&lt;p&gt;
Basic example is:
&lt;/p&gt;
&lt;blockquote&gt;&lt;pre&gt;&amp;lt;xsl:stylesheet version="3.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:xs="http://www.w3.org/2001/XMLSchema"
  xmlns:t="t"
  xmlns:map="http://www.w3.org/2005/xpath-functions/map"
  exclude-result-prefixes="xs t map"&gt;

  &amp;lt;xsl:template match="/"&gt;
    &amp;lt;xsl:variable name="map" as="map(xs:string, xs:string)" select="
      map 
      {
        'Su': 'Sunday',
        'Mo': 'Monday',
        'Tu': 'Tuesday',
        'We': 'Wednesday',
        'Th': 'Thursday',
        'Fr': 'Friday',
        'Sa': 'Saturday'
      }"/&gt;
      
     &amp;lt;xsl:message select="map:keys($map)"/&gt;
  &amp;lt;/xsl:template&gt;  

&amp;lt;/xsl:stylesheet&gt;&lt;/pre&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
A list of map functions can be found here &lt;a href="http://www.w3.org/2005/xpath-functions/map/"&gt;http://www.w3.org/2005/xpath-functions/map/&lt;/a&gt;,
though not all are available, as Saxon HE still does not allow inline functions.
&lt;/p&gt;
&lt;p&gt;
P.S. From the development perspective it&amp;#39;s a great harm that Saxon HE is so limited.
Basically limited to xslt 2.0 + some selected parts of 3.0.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=824d5dcd-a1a5-4314-b7fa-1e4447417c9f" /&gt;</description>
      <comments>http://www.nesterovsky-bros.com/weblog/CommentView,guid,824d5dcd-a1a5-4314-b7fa-1e4447417c9f.aspx</comments>
      <category>Thinking aloud</category>
      <category>xslt</category>
    </item>
    <item>
      <trackback:ping>http://www.nesterovsky-bros.com/weblog/Trackback.aspx?guid=acbef9ad-de11-4fea-b74e-d5c9a619ba50</trackback:ping>
      <pingback:server>http://www.nesterovsky-bros.com/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,acbef9ad-de11-4fea-b74e-d5c9a619ba50.aspx</pingback:target>
      <dc:creator>Vladimir Nesterovsky</dc:creator>
      <georss:point>0 0</georss:point>
      <wfw:commentRss>http://www.nesterovsky-bros.com/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=acbef9ad-de11-4fea-b74e-d5c9a619ba50</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Lately we do not program in XSLT too often but rather in java, C#, SQL and javascript,
but from time to time we have tasks in XSLT.
</p>
        <p>
People claim that those languages are too different and use this argument to explain
why XSLT is only a niche language. We, on the other hand, often spot similarities
between them.
</p>
        <p>
So, what it is in other languages that is implemented as tunnel parameters in XSLT?
</p>
        <p>
To get an answer we reiterated how they work in XSLT, so, you:
</p>
        <ul>
          <li>
define a template with parameters marked as <code>tunnel="yes"</code>;</li>
          <li>
use these parameters the same way as regular parameters;</li>
          <li>
pass template parameters down to other templates marking them as <code>tunnel="yes"</code>;</li>
        </ul>
        <p>
The important difference of regular template parameters from tunnel parameters is
that the tunnel parameters are implicitly passed down the call chain of templates.
This means that you:
</p>
        <ul>
          <li>
define your API that is expected to receive some parameter;</li>
          <li>
pass these parameters somewhere high in the stack, or override them later in the stack
chain;</li>
          <li>
do not bother to propagate them (you might not even know all of the tunnel parameters
passed, so encapsulation is in action);</li>
        </ul>
        <p>
As a result we have a template with some parameters passed explicitly, and some others
are receiving values from somewhere, usually not from direct caller. It’s possible
to say that these tunnel parameters are injected into a template call. This resembles
a lot injection API in other languages where you configure that some parameters are
prepared for you by some container rather then by direct caller.
</p>
        <p>
Now, when we have expressed this idea it seems so obvious but before we thought of
this we did not realize that tunnel parameters in XSLT and Dependency Injection in
other languages are the same thing.
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=acbef9ad-de11-4fea-b74e-d5c9a619ba50" />
      </body>
      <title>View on tunnel parameters in XSLT</title>
      <guid isPermaLink="false">http://www.nesterovsky-bros.com/weblog/PermaLink,guid,acbef9ad-de11-4fea-b74e-d5c9a619ba50.aspx</guid>
      <link>http://www.nesterovsky-bros.com/weblog/2017/03/26/ViewOnTunnelParametersInXSLT.aspx</link>
      <pubDate>Sun, 26 Mar 2017 04:21:36 GMT</pubDate>
      <description>&lt;p&gt;
Lately we do not program in XSLT too often but rather in java, C#, SQL and javascript,
but from time to time we have tasks in XSLT.
&lt;/p&gt;
&lt;p&gt;
People claim that those languages are too different and use this argument to explain
why XSLT is only a niche language. We, on the other hand, often spot similarities
between them.
&lt;/p&gt;
&lt;p&gt;
So, what it is in other languages that is implemented as tunnel parameters in XSLT?
&lt;/p&gt;
&lt;p&gt;
To get an answer we reiterated how they work in XSLT, so, you:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
define a template with parameters marked as &lt;code&gt;tunnel="yes"&lt;/code&gt;;&lt;/li&gt;
&lt;li&gt;
use these parameters the same way as regular parameters;&lt;/li&gt;
&lt;li&gt;
pass template parameters down to other templates marking them as &lt;code&gt;tunnel="yes"&lt;/code&gt;;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
The important difference of regular template parameters from tunnel parameters is
that the tunnel parameters are implicitly passed down the call chain of templates.
This means that you:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
define your API that is expected to receive some parameter;&lt;/li&gt;
&lt;li&gt;
pass these parameters somewhere high in the stack, or override them later in the stack
chain;&lt;/li&gt;
&lt;li&gt;
do not bother to propagate them (you might not even know all of the tunnel parameters
passed, so encapsulation is in action);&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
As a result we have a template with some parameters passed explicitly, and some others
are receiving values from somewhere, usually not from direct caller. It’s possible
to say that these tunnel parameters are injected into a template call. This resembles
a lot injection API in other languages where you configure that some parameters are
prepared for you by some container rather then by direct caller.
&lt;/p&gt;
&lt;p&gt;
Now, when we have expressed this idea it seems so obvious but before we thought of
this we did not realize that tunnel parameters in XSLT and Dependency Injection in
other languages are the same thing.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=acbef9ad-de11-4fea-b74e-d5c9a619ba50" /&gt;</description>
      <comments>http://www.nesterovsky-bros.com/weblog/CommentView,guid,acbef9ad-de11-4fea-b74e-d5c9a619ba50.aspx</comments>
      <category>Thinking aloud</category>
      <category>xslt</category>
    </item>
    <item>
      <trackback:ping>http://www.nesterovsky-bros.com/weblog/Trackback.aspx?guid=71417941-17bf-4a83-8249-5e980b6370fe</trackback:ping>
      <pingback:server>http://www.nesterovsky-bros.com/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,71417941-17bf-4a83-8249-5e980b6370fe.aspx</pingback:target>
      <dc:creator>Vladimir Nesterovsky</dc:creator>
      <georss:point>0 0</georss:point>
      <wfw:commentRss>http://www.nesterovsky-bros.com/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=71417941-17bf-4a83-8249-5e980b6370fe</wfw:commentRss>
      <title>File selection and uploading AngularJS directive for IE8.</title>
      <guid isPermaLink="false">http://www.nesterovsky-bros.com/weblog/PermaLink,guid,71417941-17bf-4a83-8249-5e980b6370fe.aspx</guid>
      <link>http://www.nesterovsky-bros.com/weblog/2017/01/04/FileSelectionAndUploadingAngularJSDirectiveForIE8.aspx</link>
      <pubDate>Wed, 04 Jan 2017 10:52:41 GMT</pubDate>
      <description>    &lt;p&gt;
Although the golden age of IE8 has already passed and Microsoft already has stopped
its support, this browser still occupies about &lt;a href="https://www.netmarketshare.com/browser-market-share.aspx?qprid=2&amp;qpcustomd=0"&gt; 3%
of the of the world market desktop browsers&lt;/a&gt;. Despite this, many big organisations
still use this browser for enterprise web applications. We may confirm this, since
we deal with such organisations around the world. Companies try to get rid of IE8,
but this often requires Windows upgrade and resources to re-test all their web applications.
If such company has many web terminals&amp;nbsp; with Windows 7 or even with XP, this
task becames rather expensive. So, this process advances rather slowly. Meanwhile,
these organizations don&amp;#39;t stop development of new web applications that must work
on new HTML5 browsers and on old IE8. 
&lt;/p&gt;
&lt;p&gt;
A year ago we had developed an &lt;a href="http://www.nesterovsky-bros.com/weblog/2015/11/08/AngularJSFileUpload.aspx"&gt;UIUpload
AngularJS directive and service&lt;/a&gt; that simplifies file uploading in web applications
with AngularJS client. It works as expected on all HTML5 browsers. But few days ago,
we were asked to help with file uploading from AngularJS web application that will
work in IE8. We&amp;#39;ve spent few hours in order to investigate existing third-party
AngularJS directives and components. Here are few of them:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://github.com/nervgh/angular-file-upload"&gt;angular-file-upload&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/danialfarid/ng-file-upload"&gt;ng-file-upload&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href="http://fineuploader.com/"&gt;fine-uploader&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
All of these directives for IE8 degrade down to &lt;code&gt;&amp;lt;form&amp;gt;&lt;/code&gt; and &lt;code&gt;&amp;lt;iframe&amp;gt;&lt;/code&gt; and
then track the uploading progress. These solutions don&amp;#39;t allow to select files
for old browsers. At the same time, our aim was to implement an AngularJS directive
that allows selecting a file and perform uploading, which will work for IE8 and for
new browsers too.
&lt;/p&gt;
&lt;p class="auto-style1"&gt;
Since IE8 neither supports &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/FormData/Using_FormData_Objects"&gt;FormData&lt;/a&gt; nor &lt;a href="https://developer.mozilla.org/en/docs/Web/API/File"&gt;File
API&lt;/a&gt;, thus, the directive must work with DOM elements directly. In order to open
file selection dialog we need to hide&amp;nbsp; &lt;code&gt;&amp;lt;input type=&amp;quot;file&amp;quot;/&amp;gt;&lt;/code&gt; element
and then to route client-side event to it. When a file is selected it is sent to a
server as &lt;code&gt;multipart/form-data&lt;/code&gt; message. The server&amp;#39;s result will be
caught by hidden &lt;code&gt;&amp;lt;iframe&amp;gt;&lt;/code&gt; element and passed to the directive&amp;#39;s
controller. 
&lt;/p&gt;
&lt;p&gt;
After few attempts we&amp;#39;ve implemented the &lt;a href="https://github.com/nesterovsky-bros/FileUpload/blob/master/FileUpload/Scripts/file-upload.js"&gt;desired
directive&lt;/a&gt;. The small VS2015 solution that demonstrates this directive and server-side
file handler you may &lt;a href="https://github.com/nesterovsky-bros/FileUpload"&gt;download
here&lt;/a&gt;.
&lt;/p&gt;
&lt;p&gt;
The key feature of &lt;a href="https://github.com/nesterovsky-bros/FileUpload/blob/master/FileUpload/Scripts/file-upload.js"&gt;this
directive&lt;/a&gt; is emulation of &lt;code&gt;replace&lt;/code&gt; and &lt;code&gt;template&lt;/code&gt; &lt;a href="https://code.angularjs.org/1.2.16/docs/api/ng/service/$compile#-restrict-"&gt;directive&amp;#39;s
definition properties&lt;/a&gt;:
&lt;/p&gt;
&lt;pre style="background-color: #f5f5f5;"&gt;
       var directive =
       {
          restrict: "AE",
          scope:
          {
            id: "@",
            serverUrl: "@",
            accept: "@?",
            onSuccess: "&amp;",
            onError: "&amp;?",
          },
          link: function (scope, element, attrs, controller)
          {
            var id = scope.id || ("fileUpload" + scope.$id);

            var template = "&amp;lt;iframe name='%id%$iframe' id='%id%$iframe' style='display: none;'&amp;gt;" +
              "&amp;lt;/iframe&amp;gt;&amp;lt;form name='%id%$form' enctype='multipart/form-data' " +
              "method='post' action='%action%' target='%id%$iframe'&amp;gt;" +
              "&amp;lt;span style='position:relative;display:inline-block;overflow:hidden;padding:0;'&amp;gt;" +
              "%html%&amp;lt;input type='file' name='%id%$file' id='%id%$file' " +
              "style='position:absolute;height:100%;width:100%;left:-10px;top:-1px;z-index:100;" +
              "font-size:50px;opacity:0;filter:alpha(opacity=0);'/&amp;gt;&amp;lt;/span&amp;gt;&amp;lt;/form&amp;gt;".
                replace("%action%", scope.serverUrl).
                  replace("%html%", element.html()).
                    replace(/%id%/g, id);

            element.replaceWith(template);
            ...
          }
       }
    &lt;/pre&gt;
&lt;p&gt;
We used such emulation, since each directive instance (an element) must have unique
name and ID in order to work properly. On the one hand template that returned by function
should have a root element when you use replace. On the other hand, IE8 doesn&amp;#39;t
like such root element (e.g. we&amp;#39;ve not succeeded to dispatch the click javascript
event to the &lt;code&gt;&amp;lt;input&amp;gt;&lt;/code&gt; element).&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;
The usage of the directive looks like as our previous example (see &lt;a href="https://github.com/nesterovsky-bros/UIUpload"&gt;UIUpload&lt;/a&gt;):
&lt;/p&gt;
&lt;pre style="background-color: #f5f5f5;" class="auto-style1"&gt;
    &amp;lt;a file-upload=&amp;quot;&amp;quot;
      class="btn btn-primary"        
      accept=".*"
      server-url="api/upload"
      on-success="controller.uploadSucceed(data, fileName)"
      on-error="controller.uploadFailed(e)"&amp;gt;Click here to upload file&amp;lt;/a&amp;gt;    &lt;/pre&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
Where:
&lt;/p&gt;
&lt;dl&gt;
&lt;dt style="font-weight: bold"&gt;accept&lt;/dt&gt;
&lt;dd&gt;is a comma separated list of acceptable file extensions.&lt;/dd&gt;
&lt;dt style="font-weight: bold"&gt;server-url&lt;/dt&gt; 
&lt;dd&gt;
is server URL where to upload the selected file. In case when there is no "server-url"
attribute the content of selected file will be passed to success handler as a data
URI.&lt;/dd&gt;
&lt;dt style="font-weight: bold"&gt;on-success&lt;/dt&gt; 
&lt;dd&gt;
A "success" handler, which is called when upload is finished successfully.&lt;/dd&gt;
&lt;dt style="font-weight: bold"&gt;on-error&lt;/dt&gt; 
&lt;dd&gt;
An "error" handler, which is called when upload is failed.&lt;/dd&gt;
&lt;/dl&gt;
&lt;p&gt;
We hope this simple directive may help to keep calm for those of you who is forced
to deal with IE8 and more advanced browsers at the same time.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=71417941-17bf-4a83-8249-5e980b6370fe" /&gt;</description>
      <comments>http://www.nesterovsky-bros.com/weblog/CommentView,guid,71417941-17bf-4a83-8249-5e980b6370fe.aspx</comments>
      <category>.NET</category>
      <category>AngularJS</category>
      <category>ASP.NET</category>
      <category>javascript</category>
    </item>
    <item>
      <trackback:ping>http://www.nesterovsky-bros.com/weblog/Trackback.aspx?guid=6232d896-acc1-4861-b593-e837578557b5</trackback:ping>
      <pingback:server>http://www.nesterovsky-bros.com/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,6232d896-acc1-4861-b593-e837578557b5.aspx</pingback:target>
      <dc:creator>Vladimir Nesterovsky</dc:creator>
      <georss:point>0 0</georss:point>
      <wfw:commentRss>http://www.nesterovsky-bros.com/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=6232d896-acc1-4861-b593-e837578557b5</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Recently we have found and fixed a bug in unreachable statement optimization in jxom.
</p>
        <p>
Latest version of stylesheets can be found at <a href="https://github.com/nesterovsky-bros/languages-xom">github.com
languages-xom</a>.
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=6232d896-acc1-4861-b593-e837578557b5" />
      </body>
      <title>Languages XOM update</title>
      <guid isPermaLink="false">http://www.nesterovsky-bros.com/weblog/PermaLink,guid,6232d896-acc1-4861-b593-e837578557b5.aspx</guid>
      <link>http://www.nesterovsky-bros.com/weblog/2016/12/21/LanguagesXOMUpdate.aspx</link>
      <pubDate>Wed, 21 Dec 2016 22:10:06 GMT</pubDate>
      <description>&lt;p&gt;
Recently we have found and fixed a bug in unreachable statement optimization in jxom.
&lt;/p&gt;
&lt;p&gt;
Latest version of stylesheets can be found at &lt;a href="https://github.com/nesterovsky-bros/languages-xom"&gt;github.com
languages-xom&lt;/a&gt;.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=6232d896-acc1-4861-b593-e837578557b5" /&gt;</description>
      <comments>http://www.nesterovsky-bros.com/weblog/CommentView,guid,6232d896-acc1-4861-b593-e837578557b5.aspx</comments>
      <category>xslt</category>
    </item>
    <item>
      <trackback:ping>http://www.nesterovsky-bros.com/weblog/Trackback.aspx?guid=41fb6e80-8184-404b-aefe-2123225a72a0</trackback:ping>
      <pingback:server>http://www.nesterovsky-bros.com/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,41fb6e80-8184-404b-aefe-2123225a72a0.aspx</pingback:target>
      <dc:creator>Vladimir Nesterovsky</dc:creator>
      <georss:point>0 0</georss:point>
      <wfw:commentRss>http://www.nesterovsky-bros.com/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=41fb6e80-8184-404b-aefe-2123225a72a0</wfw:commentRss>
      <title>Dependency Injection</title>
      <guid isPermaLink="false">http://www.nesterovsky-bros.com/weblog/PermaLink,guid,41fb6e80-8184-404b-aefe-2123225a72a0.aspx</guid>
      <link>http://www.nesterovsky-bros.com/weblog/2016/10/06/DependencyInjection.aspx</link>
      <pubDate>Thu, 06 Oct 2016 11:27:42 GMT</pubDate>
      <description>  &lt;p&gt;
Our genuine love is C++. Unfortunately clients don&amp;#39;t always share our favors,
so we mostly occupied in the C#, java and javascript. Nevertheless, we&amp;#39;re closely
watching the evolution of the C++. It became more mature in the latest specs.
&lt;/p&gt;
&lt;p&gt;
Recently, we wondered how would we deal with dependency injection in C++. What we
found is only strengthened our commitment to C++.
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://en.cppreference.com/w/cpp/language/parameter_pack"&gt;Parameter packs&lt;/a&gt; introduced
in C++ 11 allow trivial implementation of constructor injection, while &lt;a href="http://en.cppreference.com/w/cpp/types/type_index"&gt;std::type_index&lt;/a&gt;, &lt;a href="http://en.cppreference.com/w/cpp/types/type_info"&gt;std::type_info&lt;/a&gt; and &lt;a href="http://en.cppreference.com/w/cpp/utility/any"&gt;std:any&lt;/a&gt; give
service containers. 
&lt;/p&gt;
&lt;p&gt;
In fact there are many DI implementations out there. The one we refer here is &lt;a href="http://boost-experimental.github.io/di/index.html"&gt;Boost.DI&lt;/a&gt;.
It&amp;#39;s not standard nor we can claim it&amp;#39;s the best but it&amp;#39;s good example
of how this concept can be implemented.
&lt;/p&gt;
&lt;p&gt;
So, consider &lt;a href="http://boost-experimental.github.io/di/tutorial/index.html"&gt;their
example&lt;/a&gt; seen in Java with CDI, in C# in .NET Core injection, and in C++:
&lt;/p&gt;
&lt;p&gt;
Java:
&lt;/p&gt;
&lt;blockquote&gt;&lt;pre style="white-space: pre-wrap"&gt;
@Dependent
public class Renderer 
{
  @Inject @Device
  private int device;
};

@Dependent
public class View 
{
  @Inject @Title
  private String title;
  @Inject
  private Renderer renderer;
};

@Dependent
public class Model {};

@Dependent
public class Controller 
{
  @Inject
  private Model model;
  @Inject
  private View view;
};

@Dependent
public class User {};

@Dependent
public class App 
{
  @Inject
  private Controller controller;
  @Inject
  private User user;
};

...
  Privider&amp;lt;App&gt; provider = ...

  App app = provider.get();
&lt;/pre&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
C#:
&lt;/p&gt;
&lt;blockquote&gt;&lt;pre style="white-space: pre-wrap"&gt;public class RenderedOptions
{
  public int Device { get; set; }
}
    
public class ViewOptions
{
  public int Title { get; set; }
}
    
public class Renderer 
{
  public Renderer(IOptions&amp;lt;RendererOptions&gt; options)
  {
    Device = options.Device;
  }

  public int Device { get; set; }
}

public class View 
{
  public View(IOptions&amp;lt;ViewOptions&gt; options, Renderer renderer)
  {
    Title = options.Title;
    Renderer = renderer;
  }

  public string Title { get; set; }
  public Renderer Renderer { get; set; }
}

public class Model {}

public class Controller 
{
  public Controller(Model model, View view) 
  {
    Model = model;
    View = view;
  }

  public Model Model { get; set; }
  public View View { get; set; }
};

public class User {};

public class App 
{
  public App(Controller controller, User user) 
  {
    Controller = controller;
    User = user;
  }

  public Controller Controller { get; set; }
  public User User { get; set; }
};

...
  IServiceProvider serviceProvider = ...

  serviceProvider.GetService&amp;lt;App&gt;();
&lt;/pre&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
C++:
&lt;/p&gt;
&lt;blockquote&gt;&lt;pre style="white-space: pre-wrap"&gt;#include &amp;lt;boost/di.hpp&gt;

namespace di = boost::di;

struct renderer 
{
  int device;
};

class view 
{
public:
  view(std::string title, const renderer&amp;) {}
};

class model {};

class controller 
{
public:
  controller(model&amp;, view&amp;) {}
};

class user {};

class app 
{
public:
  app(controller&amp;, user&amp;) {}
};

int main()
{
  /**
   * renderer renderer_;
   * view view_{"", renderer_};
   * model model_;
   * controller controller_{model_, view_};
   * user user_;
   * app app_{controller_, user_};
   */

  auto injector = di::make_injector();
  injector.create&amp;lt;app&gt;();
}
&lt;/pre&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
What is different between these DI flavors?
&lt;/p&gt;
&lt;p&gt;
Not too much from the perspective of the final task achieved.
&lt;/p&gt;
&lt;p&gt;
In java we used &lt;a href="http://docs.jboss.org/weld/reference/2.4.0.CR1/en-US/html/injection.html"&gt;member
injection&lt;/a&gt;, with &lt;a href="http://docs.jboss.org/weld/reference/2.4.0.CR1/en-US/html/injection.html#_qualifier_annotations"&gt;qualifiers&lt;/a&gt; to
inject scalars.
&lt;/p&gt;
&lt;p&gt;
In C# we used &lt;a href="https://docs.asp.net/en/latest/fundamentals/dependency-injection.html"&gt;constructor
injection&lt;/a&gt; with &lt;a href="https://docs.asp.net/en/latest/fundamentals/configuration.html#options-config-objects"&gt;Options
pattern&lt;/a&gt; to inject scalars.
&lt;/p&gt;
&lt;p&gt;
In C++ we used constructor injection with direct constants injected.
&lt;/p&gt;
&lt;p&gt;
All technologies have their API to initialize DI container, but, again, while API
is different, the idea is the same.
&lt;/p&gt;
&lt;p&gt;
So, expressiveness of C++ matches to those of java and C#.
&lt;/p&gt;
&lt;p&gt;
Deeper analysis shows that java&amp;#39;s CDI is more feature rich than DI of C# and C++,
but, personally, we consider it&amp;#39;s advantage of C# and C++ that they have such
a light DI.
&lt;/p&gt;
&lt;p&gt;
At the same time there is an important difference between C++ vs java and C#.
&lt;/p&gt;
&lt;p&gt;
While both java and C# are deemed to use reflection (C# in theory could use code generation
on the fly to avoid reflection), C++&amp;#39;s DI natively constructs and injects services.
&lt;/p&gt;
&lt;p&gt;
What does it mean for the user?
&lt;/p&gt;
&lt;p&gt;
Well, a lot! Both in java and in C# you would not want to use DI in a performance
critical part of code (e.g. in a tight loop), while it&amp;#39;s Ok in C++ due to near
to zero performance impact from DI. This may result in more modular and performant
code in C++.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=41fb6e80-8184-404b-aefe-2123225a72a0" /&gt;</description>
      <comments>http://www.nesterovsky-bros.com/weblog/CommentView,guid,41fb6e80-8184-404b-aefe-2123225a72a0.aspx</comments>
      <category>.NET</category>
      <category>C++</category>
      <category>Java</category>
      <category>Thinking aloud</category>
    </item>
    <item>
      <trackback:ping>http://www.nesterovsky-bros.com/weblog/Trackback.aspx?guid=2f514933-13db-476b-90c8-9cc9724b708d</trackback:ping>
      <pingback:server>http://www.nesterovsky-bros.com/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,2f514933-13db-476b-90c8-9cc9724b708d.aspx</pingback:target>
      <dc:creator>Vladimir Nesterovsky</dc:creator>
      <georss:point>0 0</georss:point>
      <wfw:commentRss>http://www.nesterovsky-bros.com/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=2f514933-13db-476b-90c8-9cc9724b708d</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
While reading on ASP.NET Core Session, and analyzing the difference with previous
version of ASP.NET we bumped into a problem...
</p>
        <p>
At <a href="https://docs.asp.net/en/latest/fundamentals/app-state.html#managing-application-state">Managing
Application State</a> they note:
</p>
        <blockquote>
          <i>Session is non-locking, so if two requests both attempt to modify the
contents of session, the last one will win. Further, Session is implemented as a coherent
session, which means that all of the contents are stored together. This means that
if two requests are modifying different parts of the session (different keys), they
may still impact each other.</i>
        </blockquote>
        <p>
This is different from previous versions of ASP.NET where session was blocking, which
meant that if you had multiple concurrent requests to the session, then all requests
were synchronized. So, you could keep consistent state.
</p>
        <p>
In ASP.NET Core you have no built-in means to keep a consistent state of the session.
Even assurances that the session is coherent does not help in any way.
</p>
        <p>
You options are:
</p>
        <ul>
          <li>
build your own synchronization to deal with this problem (e.g. around the database);</li>
          <li>
decree that your application cannot handle concurrent requests to the same session,
so client should not attempt it, otherwise behaviour is undefined.</li>
        </ul>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=2f514933-13db-476b-90c8-9cc9724b708d" />
      </body>
      <title>ASP.NET Core Session</title>
      <guid isPermaLink="false">http://www.nesterovsky-bros.com/weblog/PermaLink,guid,2f514933-13db-476b-90c8-9cc9724b708d.aspx</guid>
      <link>http://www.nesterovsky-bros.com/weblog/2016/09/28/ASPNETCoreSession.aspx</link>
      <pubDate>Wed, 28 Sep 2016 19:22:15 GMT</pubDate>
      <description>  &lt;p&gt;
While reading on ASP.NET Core Session, and analyzing the difference with previous
version of ASP.NET we bumped into a problem...
&lt;/p&gt;
&lt;p&gt;
At &lt;a href="https://docs.asp.net/en/latest/fundamentals/app-state.html#managing-application-state"&gt;Managing
Application State&lt;/a&gt; they note:
&lt;/p&gt;
&lt;blockquote&gt;&lt;i&gt;Session is non-locking, so if two requests both attempt to modify the
contents of session, the last one will win. Further, Session is implemented as a coherent
session, which means that all of the contents are stored together. This means that
if two requests are modifying different parts of the session (different keys), they
may still impact each other.&lt;/i&gt; &lt;/blockquote&gt; 
&lt;p&gt;
This is different from previous versions of ASP.NET where session was blocking, which
meant that if you had multiple concurrent requests to the session, then all requests
were synchronized. So, you could keep consistent state.
&lt;/p&gt;
&lt;p&gt;
In ASP.NET Core you have no built-in means to keep a consistent state of the session.
Even assurances that the session is coherent does not help in any way.
&lt;/p&gt;
&lt;p&gt;
You options are:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
build your own synchronization to deal with this problem (e.g. around the database);&lt;/li&gt;
&lt;li&gt;
decree that your application cannot handle concurrent requests to the same session,
so client should not attempt it, otherwise behaviour is undefined.&lt;/li&gt;
&lt;/ul&gt;
&lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=2f514933-13db-476b-90c8-9cc9724b708d" /&gt;</description>
      <comments>http://www.nesterovsky-bros.com/weblog/CommentView,guid,2f514933-13db-476b-90c8-9cc9724b708d.aspx</comments>
      <category>.NET</category>
      <category>ASP.NET</category>
      <category>Thinking aloud</category>
    </item>
    <item>
      <trackback:ping>http://www.nesterovsky-bros.com/weblog/Trackback.aspx?guid=2c8f3cc7-725b-4c89-abc4-dc785e14058e</trackback:ping>
      <pingback:server>http://www.nesterovsky-bros.com/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,2c8f3cc7-725b-4c89-abc4-dc785e14058e.aspx</pingback:target>
      <dc:creator>Vladimir Nesterovsky</dc:creator>
      <georss:point>0 0</georss:point>
      <wfw:commentRss>http://www.nesterovsky-bros.com/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=2c8f3cc7-725b-4c89-abc4-dc785e14058e</wfw:commentRss>
      <title>Angular1 ES 2015 with decorators</title>
      <guid isPermaLink="false">http://www.nesterovsky-bros.com/weblog/PermaLink,guid,2c8f3cc7-725b-4c89-abc4-dc785e14058e.aspx</guid>
      <link>http://www.nesterovsky-bros.com/weblog/2016/09/11/Angular1ES2015WithDecorators.aspx</link>
      <pubDate>Sun, 11 Sep 2016 08:32:54 GMT</pubDate>
      <description>  &lt;p&gt;
Angular 2 is already available though there are a lot of code and libraries that are
still in Angular 1.x. Here we outline how to write AngularJS 1.x in the modern javascript. 
&lt;/p&gt;
&lt;p&gt;
Prerequisites: &lt;a href="https://github.com/lukehoban/es6features"&gt;EcmaScript 2015&lt;/a&gt;, &lt;a href="https://github.com/wycats/javascript-decorators"&gt;javascript
decorators&lt;/a&gt;, &lt;a href="https://docs.angularjs.org/guide"&gt;AngularJS 1.x&lt;/a&gt;. &lt;b&gt;No
knowledge of &lt;a href="https://angular.io/"&gt;Angular 2.0&lt;/a&gt; is required.&lt;/b&gt;
&lt;/p&gt;
&lt;p&gt;
Please note that decorators we have introduced, while resemble those from Angular
2, do not match them exactly.
&lt;/p&gt;
&lt;p&gt;
A sample uses &lt;a href="https://nodejs.org/"&gt;nodejs&lt;/a&gt;, &lt;a href="https://www.npmjs.com/"&gt;npm&lt;/a&gt; and &lt;a href="http://gulpjs.com/"&gt;gulp&lt;/a&gt; as
a building pipeline. In addition we have added &lt;a href="https://www.visualstudio.com/en-us/features/node-js-vs.aspx"&gt;Visual
Studio Nodejs project&lt;/a&gt;, and &lt;a href="https://maven.apache.org/"&gt;maven project&lt;/a&gt;.
&lt;/p&gt;
&lt;p&gt;
Build pipeline uses &lt;a href="http://babeljs.io/"&gt;Babel&lt;/a&gt; with ES 2015 and decorator
plugins to transpile sources into javascript that today's browsers do support. Babel
can be replaced or augmented with Typescript compiler to support Microsoft's javascript
extensions. Sources are combinded and optionally minified into one or more javascript
bundles. In addition html template files are transformed into javascript modules that
export a content of html body as a string literals. In general all sources are in
src folder and the build's output is assembled in the dist folder. Details of build
process are in &lt;a href="gulpfile.js"&gt;gulpfile.js&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
So, let's introduce an API we have defined in &lt;a href="https://github.com/nesterovsky-bros/angular1-es6-with-decorators/tree/master/src/angular-decorators.js"&gt;angular-decorators.js&lt;/a&gt; module:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
Class decorators: 
&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;Component(name, options?)&lt;/code&gt; - a decorator to register angular component.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Controller(name)&lt;/code&gt; - a decorator to register angular controller.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Directive(name, options?)&lt;/code&gt; - a decorator to register angular directive.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Injectable(name)&lt;/code&gt; - a decorator to register angular service.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Module(name, ...require)&lt;/code&gt; - a decorator to declare an angular module;&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Pipe(name, pure?)&lt;/code&gt; - a decorator to register angular filter.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
Component's and Directive's options is the same object passed into &lt;code&gt;Module.component(),
Module.directive()&lt;/code&gt; calls with difference that no &lt;code&gt;options.bindings&lt;/code&gt;, &lt;code&gt;options.scope&lt;/code&gt;, &lt;code&gt;options.require&lt;/code&gt; is
specified. Instead &lt;code&gt;@Attribute(), @Input(), @Output(), @TwoWay(), @Collection(),
@Optional()&lt;/code&gt; are used to describe &lt;code&gt;options.bindings&lt;/code&gt;, and &lt;code&gt;@Host(),
Self(), SkipSelf(), @Optional()&lt;/code&gt; are used to describe &lt;code&gt;options.require&lt;/code&gt; 
&lt;/p&gt;
&lt;p&gt;
Every decorated class can use &lt;code&gt;@Inject()&lt;/code&gt; member decorator to inject a
service.
&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
Member decorators: 
&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;Attribute(name?)&lt;/code&gt; - a decorator that binds attribute to the property.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;BindThis()&lt;/code&gt; - a decorator that binds "&lt;code&gt;this&lt;/code&gt;" of the function
to the class instance.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Collection()&lt;/code&gt; - a decorator that binds a collection property to an expression
in attribute in two directions.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Host(name?)&lt;/code&gt; - a decorator that binds a property to a host controller
of a directive found on the element or its ancestors.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;HostListener(name?)&lt;/code&gt; - a decorator that binds method to a host event.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Inject(name?)&lt;/code&gt; - an injection member decorator.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Input(name?)&lt;/code&gt; - a decorator that binds a property to an expression in
attribute.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Optional()&lt;/code&gt; - a decorator that optionally binds a property.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Output(name?)&lt;/code&gt; - a decorator that provides a way to execute an expression
in the context of the parent scope.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Self(name?)&lt;/code&gt; - a decorator that binds a property to a host controller
of a directive found on the element.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;SkipSelf(name?)&lt;/code&gt; - a decorator that binds a property to a host controller
of a directive found on the ancestors of the element.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;TwoWay()&lt;/code&gt; - a decorator that binds a property to an expression in attribute
in two directions.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
If optional name is omitted in the member decorator then property name is used as
a name parameter. &lt;code&gt;@Host(), @Self(), @SkipSelf()&lt;/code&gt; accept class decorated
with &lt;code&gt;@Component()&lt;/code&gt; or &lt;code&gt;@Directive()&lt;/code&gt; as a name parameter. 
&lt;/p&gt;
&lt;p&gt;
&lt;code&gt;@Inject()&lt;/code&gt; accepts class decorated with &lt;code&gt;@Injectable()&lt;/code&gt; or &lt;code&gt;@Pipe()&lt;/code&gt; as
a name parameter.
&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
Other: 
&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;modules(...require)&lt;/code&gt; - converts an array of modules, possibly referred
by module classes, to an array of module names.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
Now we can start with samples. Please note that we used samples scattered here and
there on the Anuglar site.
&lt;/p&gt;
&lt;dl&gt;
&lt;dt&gt;&lt;code&gt;@Component(), @SkipSelf(), @Attribute()&lt;/code&gt;&lt;/dt&gt; 
&lt;dd&gt;
&lt;br /&gt;
In the &lt;a href="https://docs.angularjs.org/guide/component"&gt;Angular's component development
guide&lt;/a&gt; there is a sample &lt;code&gt;myTabs&lt;/code&gt; and &lt;code&gt;myPane&lt;/code&gt; components.&lt;br /&gt;
Here its rewritten form &lt;a href="https://github.com/nesterovsky-bros/angular1-es6-with-decorators/tree/master/src/components/myTabs.js"&gt;components/myTabs.js&lt;/a&gt;: &lt;pre style="white-space: pre-wrap"&gt;import { Component } from "&lt;a href="https://github.com/nesterovsky-bros/angular1-es6-with-decorators/tree/master/src/angular-decorators.js"&gt;../angular-decorators&lt;/a&gt;";
// Import decorators import template from "&lt;a href="https://github.com/nesterovsky-bros/angular1-es6-with-decorators/tree/master/src/templates/my-tabs.html"&gt;../templates/my-tabs.html&lt;/a&gt;";
// Import template for my-tabs component @Component("myTabs", { template, transclude:
true }) // Decorate class as a component export class MyTabs // Controller class for
the component { panes = []; // List of active panes select(pane) // Selects an active
pane { this.panes.forEach(function(pane) { pane.selected = false; }); pane.selected
= true; } addPane(pane) // Adds a new pane { if (this.panes.length === 0) { this.select(pane);
} this.panes.push(pane); } }&lt;/pre&gt;
&lt;a href="https://github.com/nesterovsky-bros/angular1-es6-with-decorators/tree/master/src/components/myTabs.js"&gt;components/myPane.js&lt;/a&gt;: &lt;pre style="white-space: pre-wrap"&gt;import { Component, Attribute, SkipSelf } "&lt;a href="https://github.com/nesterovsky-bros/angular1-es6-with-decorators/tree/master/src/angular-decorators.js"&gt;../angular-decorators&lt;/a&gt;";
// Import decorators import { MyTabs } from "&lt;a href="https://github.com/nesterovsky-bros/angular1-es6-with-decorators/tree/master/src/components/myTabs.js"&gt;./myTabs&lt;/a&gt;";
// Import container&amp;#39;s directive. import template from "&lt;a href="https://github.com/nesterovsky-bros/angular1-es6-with-decorators/tree/master/src/templates/my-pane.html"&gt;../templates/my-pane.html&lt;/a&gt;";
// Import template. @Component("myPane", { template, transclude: true }) // Decorate
class as a component export class MyPane // Controller class for the component { @SkipSelf(MyTabs)
tabsCtrl; //Inject ancestor MyTabs controller. @Attribute() title; // Attribute &amp;quot;@&amp;quot;
binding. $onInit() // Angular&amp;#39;s $onInit life-cycle hook. { this.tabsCtrl.addPane(this);
console.log(this); }; } &lt;/pre&gt;
&lt;/dd&gt;
&lt;dt&gt;@Component(), @Input(), @Output()&lt;/dt&gt; 
&lt;dd&gt;
In the &lt;a href="https://docs.angularjs.org/guide/component"&gt;Angular's component development
guide&lt;/a&gt; there is a sample &lt;code&gt;myTabs&lt;/code&gt; component.&lt;br /&gt;
Here its rewritten form &lt;a href="https://github.com/nesterovsky-bros/angular1-es6-with-decorators/tree/master/src/components/heroDetail.js"&gt;components/heroDetail.js&lt;/a&gt;:&lt;br /&gt;
&lt;pre style="white-space: pre-wrap"&gt;import { Component, Input, Output } from "&lt;a href="https://github.com/nesterovsky-bros/angular1-es6-with-decorators/tree/master/src/angular-decorators.js"&gt;../angular-decorators&lt;/a&gt;";
import template from "&lt;a href="https://github.com/nesterovsky-bros/angular1-es6-with-decorators/tree/master/src/templates/heroDetail.html"&gt;../templates/heroDetail.html&lt;/a&gt;";
@Component("heroDetail", { template }) // Decorate class as a component export class
HeroDetail // Controller class for the component { @Input() hero; // One way binding
&amp;quot;&amp;lt;&amp;quot; @Output() onDelete; // Bind expression in the context of the parent
scope &amp;quot;&amp;amp;&amp;quot; @Output() onUpdate; // Bind expression in the context of the
parent scope &amp;quot;&amp;amp;&amp;quot; delete() { this.onDelete({ hero: this.hero }); }; update(prop,
value) { this.onUpdate({ hero: this.hero, prop, value }); }; }&lt;/pre&gt;
&lt;/dd&gt;
&lt;dt&gt;&lt;code&gt;@Directive(), @Inject(), @Input(), @BindThis()&lt;/code&gt;&lt;/dt&gt; 
&lt;dd&gt;
&lt;div&gt;
&lt;br /&gt;
In the &lt;a href="https://docs.angularjs.org/guide/directive"&gt;Angular's directive development
guide&lt;/a&gt; there is a sample &lt;code&gt;myCurrentTime&lt;/code&gt; directive.&lt;br /&gt;
Here its rewritten form &lt;a href="https://github.com/nesterovsky-bros/angular1-es6-with-decorators/tree/master/src/directives/myCurrentTime.js"&gt;directives/myCurrentTime.js&lt;/a&gt;: 
&lt;/div&gt;
&lt;pre style="white-space: pre-wrap"&gt;import { Directive, Inject, Input, BindThis } from "&lt;a href="https://github.com/nesterovsky-bros/angular1-es6-with-decorators/tree/master/src/angular-decorators.js"&gt;../angular-decorators&lt;/a&gt;";
// Import decorators @Directive("myCurrentTime") // Decorate MyCurrentTime class as
a directive export class MyCurrentTime // Controller class for the directive { @Inject()
$interval; // &amp;quot;$interval&amp;quot; service is injected into $interval property @Inject()
dateFilter; // &amp;quot;date&amp;quot; filter service is injected into dateFilter property
@Inject() $element; // &amp;quot;$element&amp;quot; instance is injected into $element property.
@Input() myCurrentTime; // Input one way &amp;quot;&amp;lt;&amp;quot; property. timeoutId; //
updateTime is adapted as following in the constructor: // this.updateTime = this.updateTime.bind(this);
@BindThis() updateTime() { this.$element.text(this.dateFilter(new Date(), this.myCurrentTime));
} $onInit() // Angular&amp;#39;s $onInit life-cycle hook. { this.timeoutId = this.$interval(this.updateTime,
1000); } $onDestroy() // Angular&amp;#39;s $onDestroys life-cycle hook. { this.$interval.cancel(this.timeoutId);
} $onChanges(changes) // Angular&amp;#39;s $onChanges life-cycle hook. { this.updateTime();
} } &lt;/pre&gt;
&lt;/dd&gt;
&lt;dt&gt;&lt;code&gt;@Directive(), @Inject(), @HostListener(), @BindThis()&lt;/code&gt;&lt;/dt&gt; 
&lt;dd&gt;
&lt;br /&gt;
In the &lt;a href="https://docs.angularjs.org/guide/directive"&gt;Angular's directive development
guide&lt;/a&gt; there is a sample &lt;code&gt;myDraggable&lt;/code&gt; directive.&lt;br /&gt;
Here its rewritten form. &lt;a href="https://github.com/nesterovsky-bros/angular1-es6-with-decorators/tree/master/src/directives/myDraggable.js"&gt;directives/myDraggable.js&lt;/a&gt;: &lt;pre style="white-space: pre-wrap"&gt;import { Directive, Inject, HostListener, BindThis } from "&lt;a href="https://github.com/nesterovsky-bros/angular1-es6-with-decorators/tree/master/src/angular-decorators.js"&gt;../angular-decorators&lt;/a&gt;";
// Import decorators @Directive("myDraggable") // Decorate class as a directive export
class MyDraggable // Controller class for the directive { @Inject() $document; //
&amp;quot;$document&amp;quot; instance is injected into $document property. @Inject() $element;//
&amp;quot;$element&amp;quot; instance is injected into $element property. startX = 0; startY
= 0; x = 0; y = 0; // Listen mousedown event over $element. @HostListener() mousedown(event)
{ // Prevent default dragging of selected content event.preventDefault(); this.startX
= event.pageX - this.x; this.startY = event.pageY - this.y; this.$document.on('mousemove',
this.mousemove); this.$document.on('mouseup', this.mouseup); } @BindThis() mousemove(event)
// bind mousemove() function to &amp;quot;this&amp;quot; instance. { this.y = event.pageY
- this.startY; this.x = event.pageX - this.startX; this.$element.css({ top: this.y
+ 'px', left: this.x + 'px' }); } @BindThis() mouseup() // bind mouseup() function
to &amp;quot;this&amp;quot; instance. { this.$document.off('mousemove', this.mousemove); this.$document.off('mouseup',
this.mouseup); } $onInit() // Angular&amp;#39;s $onInit life-cycle hook. { this.$element.css(
{ position: 'relative', border: '1px solid red', backgroundColor: 'lightgrey', cursor:
'pointer' }); } }&lt;/pre&gt;
&lt;/dd&gt;
&lt;dt&gt;&lt;code&gt;@Injectable(), @Inject()&lt;/code&gt;&lt;/dt&gt; 
&lt;dd&gt;
&lt;br /&gt;
In the &lt;a href="https://docs.angularjs.org/guide/providers"&gt;Angular's providers development
guide&lt;/a&gt; there is a sample &lt;code&gt;notifier&lt;/code&gt; service.&lt;br /&gt;
Here its rewritten form. &lt;a href="https://github.com/nesterovsky-bros/angular1-es6-with-decorators/tree/master/src/services/notify.js"&gt;services/notify.js&lt;/a&gt;: &lt;pre style="white-space: pre-wrap"&gt;import { Inject, Injectable } from "&lt;a href="https://github.com/nesterovsky-bros/angular1-es6-with-decorators/tree/master/src/angular-decorators.js"&gt;../angular-decorators&lt;/a&gt;";
// Import decorators @Injectable("notifier") // Decorate class as a service export
class NotifierService { @Inject() $window; // Inject &amp;quot;$window&amp;quot; instance
into the property msgs = []; notify(msg) { this.msgs.push(msg); if (this.msgs.length
=== 3) { this.$window.alert(this.msgs.join('\n')); this.msgs = []; } } }&lt;/pre&gt;
&lt;/dd&gt;
&lt;dt&gt;&lt;code&gt;@Pipe()&lt;/code&gt;&lt;/dt&gt; 
&lt;dd&gt;
&lt;br /&gt;
In the &lt;a href="https://docs.angularjs.org/guide/filter"&gt;Angular's filters development
guide&lt;/a&gt; there is a sample &lt;code&gt;reverse&lt;/code&gt; custom filter.&lt;br /&gt;
Here its rewritten form. &lt;a href="https://github.com/nesterovsky-bros/angular1-es6-with-decorators/tree/master/src/filters/reverse.js"&gt;filters/reverse.js&lt;/a&gt;: &lt;pre style="white-space: pre-wrap"&gt;import { Pipe } from "&lt;a href="https://github.com/nesterovsky-bros/angular1-es6-with-decorators/tree/master/src/angular-decorators.js"&gt;../angular-decorators&lt;/a&gt;&lt; input.length; i++)
    {
      out = input.charAt(i) + out;
    }
    // conditional based on optional argument
    if (uppercase)
    {
      out = out.toUpperCase();
    }
    return out;
  }
}&lt;/pre&gt;";
// Import decorators @Pipe("reverse") // Decorate class as a filter export class ReverseFilter
{ transform(input, uppercase) // filter function. { input = input || ''; var out =
''; for(var i = 0; i 
&lt;/dd&gt;
&lt;dt&gt;Module(), modules(), angular.bootstrap()&lt;/dt&gt; 
&lt;dd&gt;
Here are an examples of a class representing angular module, and manual angular bootstrap: &lt;pre style="white-space: pre-wrap"&gt;import { angular, modules, Module } from "&lt;a href="https://github.com/nesterovsky-bros/angular1-es6-with-decorators/tree/master/src/angular-decorators.js"&gt;../angular-decorators&lt;/a&gt;";
// Import decorators import { MyController } from "&lt;a href="https://github.com/nesterovsky-bros/angular1-es6-with-decorators/tree/master/src/controllers/myController.js"&gt;./controllers/myController&lt;/a&gt;";
// Import components. import { HeroList } from "&lt;a href="https://github.com/nesterovsky-bros/angular1-es6-with-decorators/tree/master/src/components/heroList.js"&gt;./components/heroList&lt;/a&gt;";
import { HeroDetail } from "&lt;a href="https://github.com/nesterovsky-bros/angular1-es6-with-decorators/tree/master/src/components/heroDetail.js"&gt;./components/heroDetail&lt;/a&gt;";
import { EditableField } from "&lt;a href="https://github.com/nesterovsky-bros/angular1-es6-with-decorators/tree/master/src/components/editableField.js"&gt;./components/editableField&lt;/a&gt;";
import { NotifierService } from "&lt;a href="https://github.com/nesterovsky-bros/angular1-es6-with-decorators/tree/master/src/services/notify.js"&gt;./services/notify&lt;/a&gt;";
import { MyTabs } from "&lt;a href="https://github.com/nesterovsky-bros/angular1-es6-with-decorators/tree/master/src/components/myTabs.js"&gt;./components/myTabs&lt;/a&gt;";
import { MyPane } from "&lt;a href="https://github.com/nesterovsky-bros/angular1-es6-with-decorators/tree/master/src/components/myPane.js"&gt;./components/myPane&lt;/a&gt;";
import { ReverseFilter } from "&lt;a href="https://github.com/nesterovsky-bros/angular1-es6-with-decorators/tree/master/src/filters/reverse.js"&gt;./filters/reverse&lt;/a&gt;";
import { MyCurrentTime } from "&lt;a href="https://github.com/nesterovsky-bros/angular1-es6-with-decorators/tree/master/src/directives/myCurrentTime.js"&gt;./directives/myCurrentTime&lt;/a&gt;";
import { MyDraggable } from "&lt;a href="https://github.com/nesterovsky-bros/angular1-es6-with-decorators/tree/master/src/directives/myDraggable.js"&gt;./directives/myDraggable&lt;/a&gt;";
@Module( // Decorator to register angular module, and refer to other modules or module
components. "my-app", [ MyController, NotifierService, HeroList, HeroDetail, EditableField,
MyTabs, MyPane, ReverseFilter, MyCurrentTime, MyDraggable ]) class MyApp { } // Manual
bootstrap, with modules() converting module classes into an array of module names.
angular.bootstrap(document, modules(MyApp));&lt;/pre&gt;
&lt;/dd&gt;
&lt;/dl&gt;
&lt;p&gt;
Please see &lt;a href="https://github.com/nesterovsky-bros/angular1-es6-with-decorators/tree/master/src/angular-decorators.js"&gt;angular-decorators.js&lt;/a&gt; to
get detailed help on decorators.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=2c8f3cc7-725b-4c89-abc4-dc785e14058e" /&gt;</description>
      <comments>http://www.nesterovsky-bros.com/weblog/CommentView,guid,2c8f3cc7-725b-4c89-abc4-dc785e14058e.aspx</comments>
      <category>.NET</category>
      <category>AngularJS</category>
      <category>Announce</category>
      <category>Java</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>