P3: -CSS + Any

I have a proposition…

With the advent of web (2.0) people are more and more obsessed by the web applications and nowadays everything must be on the web. Why is that? I believe that there are multiple reasons behind this and I won’t go into details, what matters in the end is that’s the trend whether you like it or not. I personally don’t have issues with the trends, that’s only natural and things are happening for a reason. Not all trends lead to a success but when they fail we need to learn something from them so we can create new trends that lead to a better world in the end – I’ve digressed a lot so let me return to my proposition. But I do have issues with trends that are difficult to follow, in this case a typical web application is consisted of 3 moving parts: HTML + CSS + Javascript, and that’s only for the client-side of the app. Typical server side app is not using any of the mentioned technologies (I said typical, Node.js and similar are anything but typical). So there’s a fourth dimension in the story (the server) which is the core of the app. So to make an average modern web app you need to be fluent in a minimum of 4 different programming languages (if you add SQL that’s 5). Some would argue that you need to have different roles of programmers to address this problem which are fluent in a given set of technologies, so you could have a backend guy and UI designer and/or else. That’s ok but in my opinion 1 person should be capable of building the whole app without the need to be overburdened by the languages which are needed to build the app. Can we simplify this? I think we can. First of all I can’t get why is there a need for a CSS. If we look at the desktop apps (and they should be used as a source of inspiration for newer kinds of client apps) there’s no such thing as a CSS. HTML should be enough to code a view side (structure, layout, …), for example iOS apps have a XIB (view) and everything else is written in Objective-C (in this case a Javascript counterpart); Java Swing codes everything in Java (which isn’t very good for tooling – GUI builders are pretty bad); JavaFX uses FXML for a VIEW, and Java for everything else (CSS can be used with JavaFX but I personally think that CSS should be casted away) and so on and so forth. So CSS should be casted away and we have fewer dimensions to worry  about(HTML + Javascript + SERVER). But that’s still complex. Can we simplify this some more? Why are we obliged to script HTML pages with Javascript only (officially (IANA) there’s support for VBScript and Tcl but as far as I know that’s not supported in modern browsers)? I’d like if I could write something like this in a HTML file: <script type=”text/java”/> or <script type=”text/csharp”/> or <script type=”text/scala”/>As you probably know there are quite a lot of web frameworks that compile to HTML+Javascript (GWT, Vaadin, …) that’s just plain wrong, you’re trying to overcome issues by introducing new dimensions of problems, let’s go back to the root of the problem if we want web apps to be the apps of the future. Browsers are a platform and they should provide multiple choices for programmers. This would lead to a fewer web frameworks and I believe this would be easier for everyone, today it’s really difficult to choose the “right” framework.

Give the programmers a choice of language to build the client side of the web app!

Solution: lose CSS introduce new scripting options

P2: Calling C# from Java

Ever wondered how to call a C# method from Java? Here’s how….

Calling native code from Java involves using JNI (Java Native Interface), this piece of JVM is pretty old and hasn’t changed lately (it’s probably that good). JNI is meant to be used with native C/C++ code (aka unmanaged) and there’s plenty of documentation how that can be accomplished. But when trying to call C# code (aka managed) problems tend to surface. There are a couple of tutorials online but following them step by step doesn’t lead to a working application 😦 I’ll try to be as brief as possible and produce a working application. All the other tutorials start with Java code, I’ll do it the other way (seems more natural). This will be a simple application that calls a C# method which returns a String.

Development environment

  • Microsoft Windows XP SP3
  • Oracle Java Development Kit 1.7.0.5
  • Microsoft Visual C# 2010 Express
  • Microsoft Visual C++ 2010 Express

Numero uno: C#

I didn’t use a MS Visual C# for this because it’s dead simple and because I couldn’t manage to compile this the right way from Visual Studio. Command line rulez! Make a file “Runner.cs” with this content:

using System;
public class Runner{
  public Runner(){}
  public String ping(){
    return "Alive (C#)";
  }
}

Compile this class with this command:
csc.exe /target:module Runner.cs  
You can find csc.exe in .NET framework install folder

This command will produce a file Runner.netmodule in the current directory. It’s a special form of DLL which can be used in managed C++ code. Hopefully ping() method will be called from Java and it’s output printed using System.out.println.

Numero due: Java

In order to build a C++ application that calls a C# method we need a JNI header file. To produce a JNI header file write a Java class:

public class Runner{

  public native String ping();
  public static void main(String[] args){
    System.load("<absolute-path-to-a-dll>");
    System.out.println("Java RUNNER");
    Runner r = new Runner();
    System.out.println("Trying to ping C# assembly: " + r.ping());
  }
}

Command-line ops:
javac Runner.java
This generates a Runner.class
javah -jni Runner
This generates a Runner.h file which will be included in C++ code.

This class has a native method ping() which is implemented in C#. System.load() is responsible for loading the appropriate DLL which holds the implementation of ping().

Numero tre: C++

For this you’ll need a MS Visual C++ 2010 Express tool (or a full MS Visual Studio). Open up this tool and create a Win32 Project called Runner. You need to configure the project since we’ll be referencing JNI header file and .netmodule file (csharp) with other configuration options. In order to have a working application correct project configuration is a must! Follow this procedure:

  1. Include JVM header files (jni.h and related) – Project: Properties > Configuration Properties > C/C++ > General > Additional Include Directories. Add folders “include” and “include\win32” which are located in the JDK installation folder. This is needed for resolving #include <jni.h>.
  2. Reference Runner.netmodule – Project: Properties > Configuration Properties > C/C++ > General > Resolve #using References. Add folder where Runner.netmodule is located. This is needed for resolving #using “Runner.netmodule”.
  3. Specific project properties
    1. Project: Properties > Configuration Properties > C/C++ > Command Line = /clr
    2. Project: Properties > Configuration Properties > Linker > Command Line = /NOENTRY /NODEFAULTLIB:nochkclr.obj /NODEFAULTLIB:LIBCMTD
    3. Project: Properties > Configuration Properties > C/C++ > Code Generation
      1. Enable Minimal Rebuild = No (/Gm-)
      2. Enable C++ Exceptions = No
      3. Smaller Type Checks = No
      4. Basic Runtime Checks = Default
      5. Runtime Library = Multi-threaded DLL (/MD)
      6. Struct Member Alignment = Default
      7. Buffer Security Check = Yes (/GS)
      8. Enable Function-Level Linking = No (/Gy-)
      9. Enable Enhanced Instruction Set = Not Set

In the project folder create 2 subfolders “JAVA” and “MCPP”. In the JAVA folder put Runner.h file that was generated with javah command and in MCPP folder put Runner.h file which you created in step 2 (Numero due). In Visual C++ Express create a C++ file “Runner.cpp” with this content:

#include "stdafx.h"
#include "JAVA/Runner.h"
#include "MCPP/Runner.h"
#pragma once
#using <mscorlib.dll>
#using "Runner.netmodule"
JNIEXPORT jstring JNICALL Java_Runner_ping(JNIEnv *env, jobject obj){
 Runner^ t = gcnew Runner();
 String^ ping = t->ping();
 char* str = static_cast<char*>((System::Runtime::InteropServices::Marshal::StringToHGlobalAnsi(ping)).ToPointer());

 char cap[128];
 strcpy_s(cap, str);

 return env->NewStringUTF(cap);
}

Here we get a reference to Runner class (C#) with ping() implementation. Before returning the output from C# we need to convert the System::String to char* (using Marshal) and to jstring (using env).

Build the project and there you have it: Runner.dll!

Numero quattro: Finals

In the folder with Runner.class put previously generated Runner.dll and Runner.netmodule files. Run the Java: java Runner and the output should be like this:

c:\>java Runner
Java RUNNER
Trying to ping C# assembly: Alive (C#)

Cheers!

P1: Internet bankarstvo

Već neko vrijeme nastojim saznati kakva su iskustva s korištenjem pojedinih web frameworka na polju bankarskih aplikacija, konkretno internet bankarstva. Nažalost do tih podataka je jako teško ili nemoguće doći osim usmenom predajom. Stoga sam odlučio složiti jednostavnu anketu kako bih došao do tih podataka. Obzirom da se ovdje radi o mission-critical aplikacijama smatram da bi cijeloj “programerskoj” zajednici bilo od koristi znati kakva su iskustva s odabranim rješenjima.

Nadam se da će se biti nešto odaziva, a kad skupim neke podatke onda ću ih objaviti na ovom blogu.

p.s. slobodno prenesite ove informacije kolegicama i kolegama za koje znate da su radili na takvim rješenjima

Take Our Survey

P0: Početak

Kad narastem bit ću…..blogger!

Već neko vrijeme razmišljam o tome kako pri obavljanju svog posla često guglam kako bih riješio nekakav problem na kojeg sam naišao. Obzirom da je online zajednica ogromna onda dosta često nađem rješenje svog problema pa zato hvala svima onima koji su do tih informacija došli na teži način, a potom ih besplatno obznanili. Kao što već vidite radi se o jednosmjernoj vezi gdje se uzima, a ništa se ne daje.  Svaka “veza”, pa tako i ova,  bi se trebala zasnivati na uzajamnom davanju (tako su barem mene učili) pa se i ja nekako želim odužiti svima onima koji su mi pomogli pri rješavanju problema na koje sam naišao. Zašto blog? Ne znam, učinio mi se prikladnim….

Da se odmah razumijemo, ovaj blog će biti vezan isključivo uz teme softverskog inženjerstva tako da oni koje to ne zanima mogu odmah prestati čitati…… jeste prestali? Ok, sad smo se riješili otprilike 99% ljudi tako da možemo biti opušteniji 🙂 Zasad ne znam o čemu ću točno pisati, pretpostavljam da ću pisati o onome na što naletim, a učini mi se da bi moglo biti od koristi široj javnosti. To mogu biti linkovi na zanimljive članke, framework-e, proizvode, ljude,…svašta nešto. Isto tako to mogu biti i konkretna rješenja nekih problema na koja sam naišao.

Prije svega se nadam da ću biti produktivan i da će ovo biti nešto više od ideje. Isto tako se nadam da će vam postovi biti korisni. Slobodno komentirajte i širite dobru vijest 🙂

Ugodan nastavak surfanja,

Stjepan Buljat