# Developing web application using Objective-C on FreeBSD



## ikevinjp (Feb 16, 2012)

I saw that the Clang 3.0 port includes Objective-C as a development language, and furthermore, I also found this port "libobjc2-1.6" (Replacement Objective-C runtime supporting Obj-C 2 features) and "ofc-0.8.1_5" (The Objective-C Foundation Classes library).

Let's say we are considering to use Objective-C on FreeBSD to develop a web-based application (vs. using Java and running it on Tomcat/Glassfish), how do we approach it?

Does Objective-C development actually work on FreeBSD (9.0)?

What are the things (frameworks/library) to download and install?

What IDE?

As I mentioned that let's say we intend to develop a web application, what are the library?/libraries (We also saw that there is "GNUstepWeb" - successor to WebObjects - is this the web library we should consider? Is this the ONLY ONE - what about other alternatives? Further, can GNUstep/GNUstepWeb compile under Clang 3.0 or make use of those Objective-C ports ("libobjc2-1.6" and "ofc-0.8.1_5") mentioned above? Are those ports relavant?

Has anyone successfully done a web application project development on FreeBSD using Objective-C (and deployed on FreeBSD)? 

Note: Web-based applications means it takes in HTTP (RESTful) calls and talks to a database (for traditional and/or NoSQL databases).


----------



## estrabd (Feb 16, 2012)

I'd use a tried and true application framework. I prefer Perl, but you can use Python or Ruby.


----------



## ikevinjp (Feb 17, 2012)

I just saw that it is possible to build GNUstep with clang:
http://wiki.gnustep.org/index.php/Building_GNUstep_with_Clang


----------



## throAU (Feb 17, 2012)

estrabd said:
			
		

> I'd use a tried and true application framework. I prefer Perl, but you can use Python or Ruby.



iOS / OS X not tried and tested enough?

I agree Objective-C is a bit weird for web development, but Objective-C itself has been around a lot longer than Perl, Python or Ruby.


That said, I'd steer clear of either C, Objective-C or any other C based language for internet-facing web apps if possible.  They were never really developed with security in mind and you're going to find it easy to write insecure code.

It's like driving nails with the blunt end of a screwdriver.  Sure you might be able to do it, but there are more appropriate tools available...


----------



## ikevinjp (Feb 17, 2012)

estrabd said:
			
		

> I'd use a tried and true application framework. I prefer Perl, but you can use Python or Ruby.



The reason I do not want to use those framework*s* is because they are so bad in performa*n*ce (when compared to C, C++ or Java) - I am a performance freak  !

Objective-C for web development (even for GNUstepWeb) seems to be unproven. 

Now, I am looking further and found these C++ frameworks:

http://en.wikipedia.org/wiki/CppCMS
http://en.wikipedia.org/wiki/Wt_-_Web_toolkit
http://en.wikipedia.org/wiki/Tntnet

CppCMS looks promising and I'm investigating further. (I recommend you to read the write-up regarding using C++ for web dev, esp. the part on performance.)

Also, I found this C framework:

http://thechangelog.com/post/4608227295/raphters-a-web-framework-for-c
... but this seems to be too simple and project dev looks like it is stalled.

It looks like C, C++ or Objective-C is the way to go for really high-performance web applications. I am looking further ...


----------



## qsecofr (Feb 21, 2012)

Not to rain your parade, but ..

whose performance are you freaky about: yours or the computer's?  You might spend a month (of your time) to save a millisecond (of its time).  Whose time is more valuable?

If your website is really that high-volume and/or computational/database-intensive, then you could certainly write critical routines in your choice of the C languages.  But usually functionality is the first goal over speed.  Nobody wants to shoot themself in the foot at the fastest rate possible.  Usually.


----------



## UNIXgod (Feb 21, 2012)

ikevinjp said:
			
		

> Note: Web-based applications means it takes in HTTP (RESTful) calls and talks to a database (for traditional and/or NoSQL databases).



Have you evaluated Ruby on Rails?

For more information look at http://rubyonrails.org/ and http://www.ruby-lang.org

a bit old but interesting video on the 15 minute blog:
https://www.youtube.com/watch?v=Gzj723LkRJY


----------



## throAU (Feb 21, 2012)

qsecofr said:
			
		

> If your website is really that high-volume and/or computational/database-intensive, then you could certainly write critical routines in your choice of the C languages.  But usually functionality is the first goal over speed.  Nobody wants to shoot themself in the foot at the fastest rate possible.  Usually.


Exactly.

Now correct me if I'm wrong, but isn't say, Java or Perl a lot easier to write threaded code in, than C?

You could spend a lot of time optimizing some inner loop in C(++/Obj-c), only to find that due to the lack of ability to easily write safe multi-threaded code, you're slower on a multi-core (i.e., any new) box anyway...

I'd prototype it in high level language of your choice, and then re-write PARTS in lower level languages as required if performance is inadequate.


----------



## fluca1978 (Feb 21, 2012)

throAU said:
			
		

> You could spend a lot of time optimizing some inner loop in C(++/Obj-c), only to find that due to the lack of ability to easily write safe multi-threaded code, you're slower on a multi-core (i.e., any new) box anyway...



I believe that multithreading is not always faster than single threaded applications. It depends on a lot of factors, and portability and security of process based applications compared to threaded ones is, for me, much more important.
That said, a minded adoption of multi-threaded will surely improve the application responsiveness.



			
				throAU said:
			
		

> I'd prototype it in high level language of your choice, and then re-write PARTS in lower level languages as required if performance is inadequate.



This is the right path!


----------



## ikevinjp (Feb 21, 2012)

UNIXgod said:
			
		

> Have you evaluated Ruby on Rails?
> 
> For more information look at http://rubyonrails.org/ and http://www.ruby-lang.org
> 
> ...



I did (evaluate it) when Ruby on Rails was very hot - probably in 2008 or 2009 era - and really wanted to use this language/framework. I didn't (use or adopted it) - due to lack of time and my busy schedule - and found that I was fortunate. The reason I said 'fortunate' is because later I found that Twitter had given up Ruby on Rails due to its scalability problems. I then took interest on Scala (because it is what Twitter decided to use, and considering the massive scalability it requires). However, I found that because XML is native within Scala and this is what I didn't appreciate about this language. I wished the built-in market up language is JSON instead. 

Now, I'm studying using C (instead of Objective-C or C++) and I think it is really a good idea - if performance is all I want.


----------



## ikevinjp (Feb 21, 2012)

throAU said:
			
		

> Exactly.
> 
> Now correct me if I'm wrong, but isn't say, Java or Perl a lot easier to write threaded code in, than C?
> 
> ...



C11 (the latest C version) has multithreaded built-in into the language. However, my preferred compiler (clang) still does not support this feature. I am investigating further...


----------



## ikevinjp (Feb 21, 2012)

Just to add a few more notes...

The reason I started this thread is I am really looking for a solution to write really fast, optimized server apps. I have spent more than 10 years working on server-side code using Java. I am expert on Java concurrency and performance. Now, I am looking for something to go beyond Java.

Admittedly, now I think Objective-C for FreeBSD is not a good choice - due to lack of mature tools, framework and libraries (I mean on FreeBSD NOT Apple platforms). 

I also looked at C++. CppCMS looks good but has not reached final version as of writing.

Now, I'm looking at C. C is simple but not object-oriented. That is not a problem, however. I can separate the tasks into different process and use shared memory techniques for interprocess communication. Each process (task/daemon) is like an object (as in OOP). I am still investigating further... and no finalization yet.

For all those languages/frameworks such PHP, Ruby on Rails, etc., I would say they are intepreted languages, so speed is far, far behind. If I have to use these, I would rather use Java.

Additional notes on why performance is so important (and possible):

Hypertable is written in C++ and is many times faster than Hbase or Cassandra. The CppCMS framework claims that it is faster than most other web framework available. This leads me to think that I can create a new framework/library using C - just for performance - is indeed very possible. 

Sure, you might say that I spend about 15 years doing object-oriented programming and going back to procedural probramming is wierd (as a matter of fact, there's a saying that programmers go from procedural to OOP and never look back). However, OOP cannot offer speed.

Of course, I'm also a security freak as well. Going back to C means I have to study all the security issues related to using this native language to write a web framework.

Any comments?


----------



## qsecofr (Feb 21, 2012)

If you haven't as yet worked with multi-threaded C programs, consider the learning curve.  It may well be much steeper than, say, Java.  Regarding multi-threaded programs, about the only thing you can assume is that you can't hardly assume much of anything.

Regarding speed of multi-threaded versus single-threaded applications: it depends on many variables, including workload, program design/logic, physical memory capacity, and even the task scheduler among surely others.  

Rather than reinvent the wheel, had you thought of extending some other existing frameworks?  What about Apache modules, for example?


----------



## throAU (Feb 22, 2012)

Along those lines:  why aren't you considering hand-tuned assembly?

I mean, well tuned assembly can be a lot faster than C or C++.


Why?  Because writing glue-code in low level languages is drudge work that can be more safely and easily done in something higher level.

Work out the performance hot spots... then optimize.  Even if you optimize the 90% of the code that does 10% of the run-time down to twice as fast, you've still only saved 5% total run time... why bother with that 90% of the low level work?


----------



## fluca1978 (Feb 22, 2012)

ikevinjp said:
			
		

> Any comments?



Sounds to me you are going to do a lot of work on your own. Is it really worth doing? Have you any real workload comparison that proves that C (or another compiled language) is really faster than <any other language>? And if you have, is the speed improvement worth your extra time for writing the code? Sorry if this sounds trivial, but I would not suppose I have any other extra-need that has not been already implemented by any framework around the planet.


----------



## UNIXgod (Feb 22, 2012)

ikevinjp said:
			
		

> Of course, I'm also a security freak as well. Going back to C means I have to study all the security issues related to using this native language to write a web framework.
> 
> Any comments?



avoid buffer overflows. 



			
				ikevinjp said:
			
		

> I did (evaluate it) when Ruby on Rails was very hot - probably in 2008 or 2009 era - and really wanted to use this language/framework. I didn't (use or adopted it) - due to lack of time and my busy schedule - and found that I was fortunate. The reason I said 'fortunate' is because later I found that Twitter had given up Ruby on Rails due to its scalability problems. I then took interest on Scala (because it is what Twitter decided to use, and considering the massive scalability it requires). However, I found that because XML is native within Scala and this is what I didn't appreciate about this language. I wished the built-in market up language is JSON instead.
> 
> Now, I'm studying using C (instead of Objective-C or C++) and I think it is really a good idea - if performance is all I want.



Twitter still uses Ruby on Rails. The hyperbole on the brownouts your referring to 5 years ago fueled by bloggers( mainly M$ .NET folk) spreading FUD about the new open source kid on the block. Parts of the Twitter app are in Scala but still Ruby and Rails at the core. If your lucky enough to have the same traffic and growth as Twitter with your web app you'll want to fine tune parts that may act as a bottle neck.

It really doesn't sound like you need a framework or language. What is sounds like is that you'd be best taking the time to learn about data structures and algorithms. 

C is only as fast as the algorithms you implement. (e.g. binary vs linear search etc.)


----------

