 Here we go. Welcome to this talk. This talk is about building server applications using Objective-C and NewStep. Well, the reason I'm giving this talk, really, is because this is an argument which most people can't really know. Actually, NewStep is usually identified with this GUI development framework, mostly for GUI applications. But in fact, it's composed of two parts. One is NewStep base, which is a new graphical kind of foundation, Objective-C, and the other part is NewStep GUI, which is more for graphical stuff. Now, NewStep base is actually the most complete and truly tested and extensively polished part of NewStep. So it's actually a really cool and finished piece of software that you can use. But it's really little known, it's actually little known to the public in a sense. The company I work for has been running very large scale applications on this, like big messaging servers, or SMS with amplinos and stuff. And it really works really well. So I always wondered why nobody else was doing it. So I give this talk just to give an overview of what you can do or how you can use this stuff. By the way, if you've been to the Tokyo State, this is coming up in place with that. Objective-C, which is the language used by NewStep, is open to the programming language. If you're using NewStep to do several applications, you are going to use Objective-C. There's not much point otherwise. Well, there are some other options which we discussed in the end, but this is your main option. Obviously, Objective-C is a strict super set of C, meaning anything you can do in C also works in Objective-C. You can compile and link Objective-C libraries in your Objective-C program, which means particularly for server stuff. It's great. You can take open SSL, you can take whatever else you have. Just any C library, you can just link it in and use it. So the main difference between Objective-C and C is that Objective-C adds a number of new features, if you want. Some syntax constructs that you can use that allow you to define classes, name, object, instance, date, methods, invoke methods, etc. And actually, quite a few quick advanced stuff that sometimes you don't even find in higher level languages like forwarding or categories, etc. So why is Objective-C so special? In fact, why is Objective-C so good for server applications? Because I think it's a perfect match. And the reason is, first of all, it's just C. It's compatible with C libraries. It can be as fast as C if you just use the kind of C subset of it. So if you're writing your server and you just tap bit of code that really needs to go really fast, you just write C code. You just use C arrays and I can write everything. But if you can also use its object-orientated extensions to structure your software like in a very good high-level language, do your nice design patterns very dynamic. And then the nice thing is you can mix the two things. So once you know a bit of experience, you can actually kind of change your style and have a bit of part more of C-like, a bit of part more of small talk. So really compressive and a wide range of things and applications you can do with it. So it's extremely flexible. And actually for server applications, it's a foundation class library. It's really powerful. It's really good and brilliant. Now, why would you use object-orientated C for server applications? I've already said that. It's very fast. You can mix it with C. It's an high-level language which you can use to design your stuff properly. And you've got this powerful foundation library. So let's have a quick look at the foundation kit, which is what this talk is mostly about, basically. First of all, use that base, which is this thing, actually implements the foundation kit defined by this API from 1994, which defines a number of classes for an objective C foundation framework. We look through some of these classes later just to give you a better idea of the capabilities of this library. Obviously, you've got obviously the root objective C classes. You've got strings, numbers, data structures, arrays, dictionaries. Very interesting for servers. You've got one-groups, timers, I'll talk about later. You can do IO, notification, a lot of stuff. So this was the open step kind of API. This is how the open step actually does it. You can run your stuff on any operating system, in particular all the various unit variants, which are probably the two most interesting ones. You need a new objective C on time, which is shipped with a free software foundation GCC, so you don't really need to do much. And obviously, that's the base. Okay, so let's have a quick look at what actually you need to build server applications with the new step. First of all, you need GCC. Most Linux distributions, for example, have got a separate package for GCC, so GCC is what I've been able to see. It just gives you the objective C compiler and the objective C on time. You need a new step made, which is a small made file library. It's the official new step build system. Basically, you buy some very small and clean made files, and then the new step made will take care of all the compiling and linking and porting to other platforms. And finally, obviously, you need a new step base, which is this implementation of the foundation GCC, which provides you with this core objective C classes you can use. A couple of important dependencies that you actually need. I already gave an XML, which everyone has it. This one is a bit un-neutral. You need this library called FFI. That's because new step base supports forwarding, which means you send a method to an object, and then the object, without even really knowing that it was called, can forward the method to another object, which is very good in certain very advanced design. Anyway, you just download that library, install it, and that's it. If you want to use HTTPS, you can use the base. You want to be able to connect to HTTPS as servers, or actually write in HTTPS server. You probably want to use UnityOS for open as a self. Obviously, you just install those libraries. Now, I need a quick look, and this is just to give you an idea of how easy it is to install a boot. I just picked up an institution. You just need to do up-to-the-end or start package the boot, then get on your dependencies and you're ready to go. This is instead, if you're installing it manually, which, for example, is what my company does, we install all our servers manually. So, it looks imposing, but that's really all you have to do. It's not much. You need to install a couple of... So, GCC and XML open as a self, obviously. You get Libre for five from that. You just simply install it. Other quality may, if you do like that, it will be installed and you use lockouts, obviously. You just need to make sure that the link will find the libraries and it will have the lockout sort of thing. But you just have to make the configure-make-make install. You get new step-based and the same. We use open as a self, so you need to pass this lock and enable open as a self to be configured. And the only really unusual thing here is you need to source the script. There are ways where you don't need to source that at all. But as a first start, just to make sure it all works, you source this script which will set your part, set your library part, and you don't have to worry about that. Once you're a bit more familiar, you can actually do an FHS style store where your programs end up in USB, your libraries in USB, and you actually don't need that. Okay? So let's have a very quick look at how you compile it, actually, in objective-seeing user-based program. This is a three-day example, the same example used yesterday. So import, this is the main header for the foundation for user-based. So once you import this header, you have access to all the user-based functionality. And this is just the tiny NSLog, actually, right through Stannabarrow. So typically, you use it in service to log stuff. And that is a static string. The syntax at and then the string is actually a static NS string, which we'll talk about later. This is an example going to make file which compiles that thing. Actually, if you have more files to compile, the make file is exactly the same. You just list them all here, all your source code files, then you type make and it will work. So the structure of the new make file, first you include this comment on make, then you specify the name of your program, which is hello, and the objective-seeing file is composed of the program, and here you can just list them all. And then you include this thing, this other make file fragment, which builds tools. Now, there are different make file fragments, different things, like libraries, bundles, which is like a plugin that you can load in your program. The tool is basically just a non-graphical objective-seeing program. So for server stuff, if you're doing a server, it's exactly what you should use. Once you've written this, if you've sourced that script, which will actually redefine this variable, you have all the usual commands, so you can type make it with bin, you can do make clean, make this clean, you can do make install, which will install it. It will give you quite brief output, like compiling file. If you actually want to see the GCC command line, the link, exactly, just add these messages, yes, and it will be going to variables mode, and prints everything that it's doing. You can also use it for make install, for example, if you want to see where things are going. Actually, it then supports a lot of other stuff, like yes, all the stuff you usually expect. But probably, you just need to know that. And when you type make, it will tell you there's a special target you can run to get help, and it will be printed in the first line. Okay, at this stage, it was planning to do a quick demo, but with a thing that it would just keep down. Anyway, basically, if you put those two files in there, type make, it will compile them, so that it's not that great. Okay, now, if you're actually trying to do this, where do you start? First of all, you need to just know a bit about GCC, about this Gluster-based foundation you were using. This page has got a number of tutorials, which I actually wrote myself. And it's a good starting point, like for those make files, for some classes. You use the base as an extensive API reference, which I think is pretty complete. Okay, almost complete. And that's kind of where you're at. So when you don't know what a method does, what a class does, which class you use, you can go there and just walk around. You can actually, I don't know if you can hear, but you can actually also go on the Apple website and look at their foundation kit, which is a similar API. So sometimes they may be misleading, but... Now, okay, let's have a look, like the basic classes of Gluster-based, such as strings or arrays or dictionaries, etc. It's got quite an interesting design. You would expect you can't do much with those such basic stuff. Everyone knows that. Actually, Gluster-based foundation kit has some very interesting ideas in the design of these classes, mostly for performance. One thing it does, it uses this class-to-design, which means, basically, it's a way of optimizing the classes without kind of changing the API. So when you create a spring, which is a spring, you don't always get an object of the same class. You get an object of the... It's called a concrete subclass, which actually is optimized for that type of string. Well, because, objectively, it does dynamic dispatch. When you call a method of the object, then depending on the concrete class of the object, a different implementation will be used. That means if you create a unique string, or if you create an ASCII string, you use exactly the same API, you don't need to know which type of string you have created. That type of string will know, and when you do things on the string, it will use the optimized implementation for that type of string. That also is done for arrays, for dictionaries, in some cases, and you can even implement your own subclasses. So if you've got a particular type of string of array or array, or that you really have your own way to optimize it, you can actually implement the subclass, and then pass it around whenever a string is required. You can pass a string of your own class, your own optimized stuff, and it should work. The other thing is, there is a distinction between mutable objects and new mutable ones. So you've got NS string and you've got NS mutable string. That allows you, that allows the classes themselves, like when you put strings into arrays, or dictionaries, or do things, to actually optimize quite a lot because you know that a string, an NS string can never be changed while an NS... Yeah, so I didn't say that. So the difference is, a normal string, like an NS string, is a string you create and you can never change. If you plan on changing it, you should create an NS mutable string, which, and then you can add characters to them, et cetera. So let's very quickly have a look at these base classes. This is an example of NS string. This example is... the team also supports static strings, like this one. Again, this is basically allocated by a compiler. Obviously, NS string is a string class. It's got full, unical support. And one thing which is really key for server stuff is this class-class implementation means ASCII string is still extremely fast, even if there's full unical support. So you can... anytime you want to just put a unical string in it and it will work. But if you put an ASCII string, it will still be really fast. So, unlike Java, for example, where strings are really slow because it's always a kind of unical mode. It depends on the implementation. This is a typical array. That's a properties, which is a way of describing these collection classes and realizing how to serialize them. But anyway, it's just to make sure you understand an array is this thing. Well, the dictionary is kind of an associative array or ASCII will depend on you. The terminology used. So it's more like that one. So it's got keys equal value. Again, you've got... It's important to know if you use the API. The only thing you really need to know is you've got the array class, sorry, the NS array class, the static stuff. If you want to change that, you can use the NSMutable array. And prediction is actually the same. Now, I don't have time to go through all of the glue step base classes one by one. I just want to mention a few ones that may be good to know. So if you go and look at API, you know where to go. One thing you probably want to do if you're writing a server is like your server will start a run loop and wait for sockets to connect in or wait for some time to arrive to do something or for something to happen. That's a typical thing. So for that, you will use an NS run loop. You've got a full-length base model. You've got NS file handle. It allows you to do IO, which is your integrated with your run loop. You've got NS timer. You've got this class called NS thread, which you can use. For locking, you've got NS lock and there's another bunch. Another very nice feature of NS is called notifications. It's pretty easy once you get into it and it's really kind of addictive. It allows you to connect objects in a very flexible way. So you've got this thing called the notification center. That's the class NS notification center. You can have objects which can observe notifications. So you have an object that's waiting for the NS file download completion thing. When something else will post that notification, your object will be informed that that event has happened. You specify which method you want to be involved when that happens. So you've got a notification center with various observers that are observing notifications. Then something else will post the notification to the center and all the observers will get informed. That's nice. It's a standard design pattern because it allows you to link basically the observer to the object to post the notification without actually themselves access it flexible. Obviously, if you actually want to use the standard notification center, if you look in the NSF code, you will see it used a lot. And it's a very good idea to use it in code as well because it's really flexible. The other thing that NSF buys and NSF in general do a lot is using delegates. Now, this is not really implemented in the library to create delegates. But it's something that is almost everywhere in the API and it's actually something you want to do in Europe and APIs as well. A delegate, basically. The idea is in object-oriented stuff, usually subclassy class to extend it. The problem is sometimes that's very heavy. You have to create a subclass. It can be quite messy. You have to create a subclass without subclassy. So you've got your class that does something and then you add that and set delegate and a method to return the delegate. And then whenever you're using an instance of the class you can set a delegate. And then the class obviously, when it's processing at some point, you check if there is a delegate and if so, we call the method of the delegate to ask for to delegate some of the processing to it. It's very flexible and it's really good. So it's if you actually, even if you are not going to do this it's a really good thing to have a look and see how it works in the other step API, etc. That's just a C sharp delegate sorry, function pointers. It's similar to C sharp delegates, right? Where they're basically function pointers. No, it's really different. It's totally different. You just like usually if you're a delegate you can use the method or not. So it's totally dynamic. Whereas in C sharp it must be already there, it must be defined. It's not the runtime thing. So a delegate is an object for support. So you've got your object, then you've got another object. Let's say you've got an HTML parser and you want to do SUCKS stuff where when it finds a tag you could call a method in your code. So you could have a delegate which is what you're supposed to implement to actually react to events and then in the XML parser you send the delegate to whatever object you want. And then when it finds a tag you would call a method of the delegate which does something and goes back and it finds another tag and you call the method. So that's how it works, that's it, yeah. Okay, I'll see that actually because I think I was getting the point but I don't know that it's too different from my time, yeah. The only thing similar to that is the name which you saw, but it's really different things. Yeah, no, thanks. Anyway, I have to say it is a standard design pattern. I'm sure you can find it in almost all the other but here it's really new slide. In Java it's the listener. Listener to listener. Is it? Well, actually you can have delegates in Java as well. We'll do that in time. As an object of C, you do not invoke methods directly but there's actually a concept of the selector which represents a message and it's completely decoupled from the lookup process in the class. So the delegate or something as a delegate can be completely dynamic. You don't need to know what methods are implemented in there. For example, if you pass an X and R you can write class which has methods like begin for any tech you could write a method and of the X and R class could dynamically ask whether it's implemented or not. So it's quite common for us. Now I understand that but it's like a package that has actually been built. Yes, it should have. Another thing that can be another thing that can be something that most of these provides is something called distributed object. Again, that's basically it's remote method invocation. You have there's millions of implementation of that. But this is quite high level and natural and does use again some of these objectives see really dynamical stuff. So basically what you do is you've got your process, you've got an object in your process and you can expose it to the network processes can call methods to the object. The fact is the way you use the API it looks as if that object in the remote process is actually in your own process is like an object like everything else. It's very very natural to use. It's great if you've got a number of processes that need to talk to each other but are separate process and just sometimes involve methods of each other etc. Which can be handy when you're building servers etc. Now I don't have to go to that but I wrote a nice tutorial on this on that webpage so you can have a look and just get an idea. Now I thought I would look at a few of the most useful libraries you can use if you're doing server development with injectancy. Obviously the first thing you can use any C library you want which is a big big thing actually. If that does provide a number of server kind of libraries most of them are in their small human subversion but I go through the most interesting ones in this talk. Then you've got other parties that provide some very nice subjective C libraries. For example Soapy from the Open World Project which is a full application of server we'll briefly mention that later. And obviously there are some libraries for Apple Cocoa that you can reuse their written objectives in a very similar API. Some of them are actually officially ported to Blue Step so I don't know if you've got some weird format you need to parse you may find something for inclusion something for Apple that will just do it. First thing we'll quickly discuss is just the database libraries because if you're doing server development chances are you will need to connect to database. The first thing you can do obviously is just use your own favorite C library if you have one or so if you're connected to Postgres you could just use the Postgres C Binds and just use that. Genusna provides two database libraries which I will discuss in great detail the other one is called GDL2. Finally if you use Soapy for example Soapy has got his own database layer which obviously if you're using Soapy it's definitely the best choice if not I'm not so sure you probably just want to use one of those. Let's have a look at these two. First of all SQL Client SQL Client is just an SQL layer so it's pretty kind of low level in the sense you write a SQL code and just execute it. As for backend bundles a bundle as I was mentioning before the terminology for plugin has got plugins for the different databases Postgres. These are the ones that are currently provided in the standard distribution as Postgres or SQL SQLite and Oracle. The focus of this library is really on our performance and it really does provide cool stuff there. It does connection pooling obviously it does all the transaction support now because it does query caching so it can do a query and say that you want it to be cached for 10 minutes so if later on your code does the same query it will just hit the internal cache. The other thing you can do very nicely is batching updates or inserts If you're doing really high performance stuff it can become important to just batch a number of writes and a single transaction which is executed faster so this allows you to as your code goes cannot take statements to be executed to a transaction and when you reach the end you just execute them all and if the transaction fail you will actually if you want just retry all the insert of updates one by one to make sure that you if one of them is wrong as well as a completely different approach is trying to go for the high level stuff so this basically provides you an object-to-relationship mapping framework it will automatically convert your database stuff into objects it allows you to it does extensive use of those KBC, K viewer things which are cool in Objective-C which allow you to change stuff into other objects so then we have and basically strong MVC button very nice stuff I've got an SQL layer at the bottom which again I've got different adapters for different database it's really good for rapid development so you've got this classes but in other classes you can program to more than your database how do they compare well if you're performance oriented you just want to use a secure client that makes sense particularly if you're basically going to write and tune every single query anyway if you require that level of sophistication in terms of performance obviously you don't want anything to generate queries for you and then you should just go with a secure client if you're looking for an ideal framework where you can work properly with properly designed stuff etc models, objects etc you don't want to write SQL and GDF things for you performance in general I have to say it's a bit hard to get into because it's modeled over a load framework for next step called UF so the people who knew are you know everything about this the people who have never used it it's usually hard to get into but once you get into it usually people just fall in love with it and say it's the best thing ever question? how does the materiality of GDF2 compare to the materiality of EOF let's say in 5, 6 years ago good question anyone who might have been inspired I'm sorry I think GDF2 is supposed to be better at the moment I think there are people using it in a real life situation in production but for example I'm sure the doctors are full tested and the Postgres one works really well I'm not sure about the elements so it may not be as polished as Postgres my question was not so much about the adaption database adaption but it was more about framework itself I used to work with EOF from 2003 so I've been there since I looked at it and that's one of the reasons but it was really good and I can imagine that this could be better because I guess it had the same tactics as the doctors which has exactly the same EPI, the same class names but I can't tell you how mature this is I didn't test it okay I was just curious I think they are better suited ones excuse me ok is it a requirement of GDL2 that there is a database behind or is it is GDL2 just an object persistency no no no ok sorry it's not always like that so you've got my Postgres you've got it in your application to access Postgres you use GDL2 the point is you have a screen database in the first place and you want to use it but you could because I wanted to ask a kind of trick equation you say once you use the GDL2 you never want to use it but what about object oriented databases like Jamstone or I don't Halge yeah what about object oriented databases like no because Nikola said once you use the GDL2 you never want to use anything else but if you could just start the transaction and persist your object without doing anything that would be an object that we don't have on the object that's here right yes so the problem is just a map an object relation database map and you have lots of trouble like if you translate for example then your object graph that you want to save to the database is obviously not the same like in the context of the object to the database actually using GDL2 probably as well as using your FQ code write an object database because the high level stuff which for example so use interface to the database that's completely separate from the storage layer so if you have something that's just part of your object score which does all the mapping if you would want to you could just utilize the object and write them to the just the possible you can just graph file one or something else the question was what if there was a map in there you don't need to do the mapping using GDL2 is actually two parts one part is tracking the state of the object which you could use in the object database backup some kind of transaction in memory transaction so trace all the changes to the objects and when it saves those changes you could either write the objects as a serialized form that's where the mapping kicks in or you can serialize them to a SQL database but it's really independent those are two different parts there was also one time a platform adapter for UF you could just it's already met you don't need a database as such the one is there okay another library which is used to provide this library for web server library which allows you to connect basically to AP servers this is not really for building web pages it's more for API, transaction on APIs where someone is calling your API team do something connect to your database or something it provides a kind of full web server, usually use it without it's quite handy if you actually need to do that in case you need to interface with Java stuff there's a GNU step to Java interface which allows you to use Objective-C Object Classes etc from Java from Objective-C it's very cool, it does work there's a number of cons though it can be slow so you don't want to overuse it if you have a problem it's hard to debug because of the cross-language calls support for cross-language sub-classing is actually a bit limited and it's not easy to port to other platforms one of the last things I wanted to mention was Soaping which is a basically web application server environment it's got an extensive set of frameworks and a lot of stuff which you usually want to do with this thing it's kind of compatible with Apple Web Objects even if it's got its own concepts and extensions so it's not perfectly happy compatible it's kind of clearly derived and mostly it's not even trying it's not even trying it does do a lot of stuff to do XML processing XML RPC obviously it does MIME, IMAP etc it does LDAP it does horizon database stuff and it does icon processing if you're interested that's the URL where you will find more information we forgot to mention Twisted Web it's a library which is modeled or compatible to at the Web Objects or next Web Objects it was this time 4.5 I guess and it uses contrast to Web Objects today which is now Java based it's still an Objective C and the API is a little bit different the prefixes are not really O but GSW what I think you can configure that you can configure it I didn't know that it's supposed to be 100% comfortable with Web Objects and it's alternative to ZOP just looked at the glass names and I thought what's that so you don't know what we need internally we need to Web Objects which is this Web Development framework by next step originally now by Apple SOAP is a very good one but there's another project which is GoonStep Web which is more compatible less advanced though I don't know what do you mean I think they are stating that they want 100% compatible but I think that more compatibility is okay so we have four legacy applications the SOAP and they work any more questions thank you very much if you want more information on the website some main English gas questions and good luck