What is the best way to use Lucene from a Cocoa app? - cocoa

I'm interested in working with Lucene from a Cocoa application. I'm aware that there are many ways to do this, but my question is, "which way is best?" My investigations so far:
LuceneKit is an Objective-C port of Lucene, but is based on a version of Lucene that is ancient at this point, and in trying to use it, I've run into several major issues from the get go. (Improper subclass of NSDate; A basic query that works in Luke doesn't work with LuceneKit;) It appears to be a non-starter.
CLucene looked like it might be viable, but it fails a bunch of it's own tests on build, including an intermittent concurrency related problem where half the time I run the tests they deadlock. Not inspiring. This still may be the answer, but I'm very nervous considering my experience just building it and running its own tests.
Current Apache Lucene via JNI - Having simply never called a Java library from C, I'm unsure what's involved here. I certainly feel like the official Apache-curated incarnation of Lucene is likely to be the most mature and functional, but having not done the C <-> Java JNI thing before, I'm unclear how the effort involved would compare to working with CLucene.
Maybe there are other options. I'm not necessarily looking for a first-class Objective-C interface (although I wouldn't turn one down, either) just something functional and hopefully reasonably mature and reasonably performant. Anyone have any sage advice?

From my experience using JNI (although, not with Lucene), it's not too tricky to get something simple working, but you can wind up writing a lot of fairly monotonous code wiring everything up.
Another option you may want to consider is JCC, which is used by the PyLucene project to generate a boilerplate C++ wrapping around the JNI itnerface, which they then use to wrap a Python API around.

Related

How good enough it is to build a REST Api based server in C++?

I am looking from a security perspective and are there any frameworks available to build and use JSON?
I am interested because of the performance which C++ can offer. Currently, Python and Node.js are also available option for me. How can I decide which language+framework should I use ?
Appreciate your support.
Thanks !
PS. - Currently, I am using Java Spring to implement restful apis.
There's plenty of them out there. The absolute simplest one I found, and use, is this. https://github.com/eidheim/Simple-Web-Server .
There are clearly more sophisticated ones out there, just "ask the google". I don't know of any exhaustive comparisons between these frameworks and the ones you specified. However, you could write your own simple benchmarks around the domain you're most interested in. That's what really matters, right?
For json libs there's rapidjson and spirit json. Don't waste your time with boost::property_tree, it's not fully fleshed out wrt JSON.
As for speed. It's compiled so.... its a good possibility that a C++ framework will outperform one based on an interpreted language. So lets say it's faster, you have a heck of a learning curve to climb (assuming you don't know C++ already) but in the end, in my humble opinion it's worth it. I've done these before in Python and Ruby. I really enjoy having the compiler check types. My code is more robust, it does what I tell it to do, and I'm not forced to use exceptions.
Tip: get a code completion plugin like YouCompleteMe

GUI tools that are actively developed and well documented for Haskell

I've spent the better part of my morning and afternoon playing around with GUI frameworks in Haskell, as I need some visualization and interaction capabilities and I'm not in love with writing my core functionality in Haskell then piping out to a front end written in another GUI; I'd prefer to do it all from one language. The better part of that better part has been spent compiling and patching source code, or Googling obscure compilation errors.
I've spent plenty of time reading SO questions, plenty of time on haskell.org, and plenty of time reading documentation. What I've encountered is a very large swath of outdated or poorly documented information. I can boil it down to these three things:
A glut of options built on top of Gtk+ bindings. I don't care for Gtk+ very much, mostly because I find it to be quite unpleasant to look at, especially on OS X. Griping about the UI looking out of place and/or just plain ugly might seem silly, but that's important to me. Especially if I want other people to utilize any of the programs that I create.
wxHaskell, which is stable and incredibly easy to install but many of the existing tutorials seem to be for wx-0.1x and the conventions for bridging the wxWidgets 2.9.x docs to wx-0.90.x are very very spotty and hard to grok, when they even exist.
qtHaskell, which seems to be mostly abandoned (correct me if I'm wrong), only compiles with newer versions of GHC after applying a year-old patch, and spits out a massive amount of warnings that indicate they will soon become compile errors in newer versions of GHC.
In effect, I'm looking for Haskell's answer to Java's Swing; a library that is robust, maintained, well documented, easy to get started with, makes an attempt to be native in look and feel, can keep up with GHC's development pace, and not at high risk for abandonment. This seems to be exactly zero GUI frameworks, but then it seems that most of the "official" resources/wikis/pages/docs related to GUI frameworks are woefully unmaintained so I decided to turn to the community to see if there was something I just wasn't finding. I'm not terribly worried about the framework being cross platform, just so long as it works on modern versions of OS X.
To reiterate, I'm not really looking for someone to send me a link to haskell.org or the WikiBook. I've been there, and I didn't like what I saw. Most of the information there is just so out of date that it only creates more work, not less.
I realize that my "demands" are a little extreme, especially for a language with a smaller community like Haskell, but I was hoping that someone out there could be of assistance to me. In the mean time, I intend to simply try and ride out wxHaskell or qtHaskell until I succeed or die.
I hope I'm not coming across as gruff or frazzled.
wxHaskell is good, yes, and my go-to GUI middle level library. I admit there's been a focus on updating the code before the docs in the new version.
For modern, functional-reactive-programming fun stuff on top of it I gor for reactive banana, which is actively maintained, and has the added benefit that Heinrich Apfelmus himself may well turn up here to answer your questions.
Threepenny-gui is the most recent contender in the space of Haskell GUI libraries.
Its main selling point is that it is very easy to install, because it uses the web browser as a display. It's also easy to get started with.
On the other hand, it doesn't even attempt to have a native look and feel – the UI is built solely on HTML. (This may change in the future, as we have the option of using XUL). Also, the API is still very much in flux, so be prepared that new major versions of the library are likely to break backwards compatibility. (On the other hand, this means that it's actively developed. :-))
(Disclosure: I'm the author / maintainer of the threepenny-gui package.)
I feel your pain; this answer is an attempt to provide some alternatives that may be good enough and perhaps help you with your search.
First, there is a language called Concurrent Clean. It is supposed to be similar to Haskell, has GUI support and is meant for writing real-world applications. It differs in some respects; for instance, its I/O is based on unique types rather than Monads, which as far as I'm concerned, is a good thing :). Here is a link:
http://wiki.clean.cs.ru.nl/Clean
Next, I dug around for a Haskell compiled to the JVM, in the hopes that it would piggy-back on the Java libraries, ala Clojure. No dice. What I did find was a SO thread discussing the lack and the challenges thereof:
Haskell on JVM?
From that thread however, two other options were brought up. One is Frege:
http://code.google.com/p/frege/
The other is CAL:
https://github.com/levans/Open-Quark
There's also work on functional reactive programming in Haskell. It's supposed to enable things like GUIs, although whether or not you'll actually get a GUI out of it is another matter:
http://www.haskell.org/haskellwiki/Functional_Reactive_Programming
It's sad. Here we have the JVM and .NET and yet zilch for Haskell. It's worse than that; .NET has shown an alarming tendency to ditch promising implementations. Whatever happened to IronScheme, IronLisp and IronHaskell? All dead as far as I can tell.
Not good :(

Could Grand Central Dispatch (`libdispatch`) ever be made available on Windows?

I’m looking into multithreading, and GCD seems like a much better option than manually writing a solution using pthread.h and pthreads-win32. However, although it looks like libdispatch is either working on, or soon going to be working on, most newer POSIX-compatible systems… I have to ask, what about Windows? What are the chances of libdispatch being ported to Windows? What are the barriers preventing that from happening?
If it came down to it, what would I need to do to preform that portage?
Edit: Some things I already know, to get the discussion started:
We need a blocks-compatible compiler that will compile on Windows, no? Will PLBlocks handle that?
Can we use the LLVM blocks runtime?
Can’t we replace all the pthread.h dependencies in userspace libdispatch with APR calls, for portability? Or, alternatively, use pthreads-win32 I suppose…
Edit 1: I am hearing that this is completely and totally impossible, ever, because libdispatch depends (somehow) on kqueue, which can’t be made available on Windows… does anybody know if this is true?
Take a look at : http://opensource.mlba-team.de/xdispatch/
This project (and other third-party libs) brings libdispatch into platforms(windows, linux) other than macosx
https://github.com/DrPizza/libdispatch
The Windows equivalent of libdispatch, from my basic understanding of it, is the Concurrency Runtime for unmanaged code and a collection of technologies collectively known as Parallel Extensions for managed code. It appears to me that GCD maps pretty well to both of these, since they both abstract work units (or "tasks") in a similar way.
From a bit of research, it appears that there's already a fair bit of interest in a port, but that port would be a fairly drastic undertaking and might end up being basically just another implementation of the API and not actually sharing significant code with the original libdispatch. I did see some proposals to porting libdispatch to being based on the Apache Portable Runtime instead of POSIX which'd make it easier to make it cross-platform to Windows, but even this would not be an easy change.
Likely, this would be by no means a small undertaking.
I think that rather than libdispatch-on-pthreads and pthreads-on-Win32, or libdispatch-on-APR and APR-on-Win32, it might be better to implement libdispatch directly on the Win32 Thread Pool API. The good news is that the two APIs are similar enough that you could probably do the port yourself. The bad news is that there would probably be lots of corner cases where there are small semantic mismatches that make exact behavior hard to achieve.

BOINC: Is there an easy example how to code a programm for it and how to implement it into their client/server system?

I did a numeric method as my diploma thesis and coded it in java. It needs a lot of computational time when adequately executed. So I looked for an alternative and found BOINC. Unfortunately I didn't have time for doing my method in BOINC, because I'm an Aerospace student and not a programmer and I decided to keep my priority on my java program. Now it's finished an I still would like to port this to BOINC environment.
Unfortunately I'm learning in re-doing examples and I couldn't find any, neither on the official site http://boinc.berkeley.edu nor in the internet.
So do you know a good and easy example or do you have any experience in BOINC and would like to start a new platform for such a boinc project?
I'm realistic about my method, that it wouldn't run 24/7, because there aren't as many work units as for seti or folding projects. So I would like to have a platform for more than just my project so that another platform project can be worked on, when one part of the project does not have any work units at that moment.
But to start this, I would keep it simple and just want to know how to code it and use it in the client and server system. It doesn't matter what the example projects will work on, as long as it is simple enough, that I can understand it and extending it for my method.
Thank you in advance, Andreas! :)
PS: I know that BOINC supports JAVA as a programming language, and my method is coded in JAVA.
As far as I know, JavaApps is just an idea; I don't know if anyone actually tried it in a real BOINC project. And it's Windows-only. And it seems to be a bit of a pain to redistribute the entire JRE as part of the BOINC application (both technically and legally).
Also, I generally dislike using that kind of “wrapper” where the science app (using the BOINC API) starts another process that then does the real computation. It's usually unreliable. There are lots of things that could go wrong with the wrapper, especially related to controlling the child process (eg. if something kills the wrapper, the child process has to quit too).
However, I just found something pretty interesting that may let me do a better Java wrapper for BOINC... Stay tuned! (but don't hold your breath either; it's the holidays!)
Meanwhile, I suggest you start by reading BOINC wiki and setting up a server with a “hello world” application; and if you have any trouble, ask a specific question about your trouble either here or in the boinc_projects mailing list.
(Of course, payin’ me to install the server for you is also an option ;) but I can't guarantee anything; not even my mere availability at this time of the year)

Does it still make sense to learn low level WinAPI programming? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
Does it make sense, having all of the C#-managed-bliss, to go back to Petzold's Programming Windows and try to produce code w/ pure WinAPI?
What can be learn from it? Isn't it just too outdated to be useful?
This question is bordering on religious :) But I'll give my thoughts anyway.
I do see value in learing the Win32 API. Most, if not all, GUI libraries (managed or unmanaged) result in calls to the Win32 API. Even the most thorough libraries don't cover 100% of the API, and hence there are always gaps which need to be plugged by direct API calls or P/invoking. Some of the names of the wrappers around the API calls have similar names to the underlying API calls, but those names aren't exactly self-documenting. So understanding the underlying API, and the terminology used therein, will aid in understanding the wrapper APIs and what they actually do.
Plus, if you understand the nature of the underlying APIs that are used by frameworks, then you will make better choices with regards to which library functionality you should use in a given scenario.
Cheers!
I kept to standard C/C++ for years before learning Win32 API, and to be quite blunt, the "learning Win32 API" part is not the best technical experience of my life.
In one hand Win32 API is quite cool. It's like an extension of the C standard API (who needs fopen when you can have CreateFile. But I guess UNIX/Linux/WhateverOS have the same gizmo functions. Anyway, in Unix/Linux, they have the "Everything is a file". In Windows, they have the "Everything is a... Window" (no kidding! See CreateWindow!).
In the other hand, this is a legacy API. You will be dealing with raw C, and raw C madness.
Like telling one's structure its own size to pass through a void * pointer to some Win32 function.
Messaging can be quite confusing, too: Mixing C++ objects with Win32 windows lead to very interesting examples of Chicken or Egg problem (funny moments when you write a kind of delete this ; in a class method).
Having to subclass a WinProc when you're more familiar with object inheritance is head-splitting and less than optimal.
And of course, there is the joy of "Why in this fracking world they did this thing this way ??" moments when you strike your keyboard with your head once too many and get back home with keys engraved in your forehead, just because someone thought it more logical to write an API to enable the changing of the color of a "Window", not by changing one of its properties, but by asking it to its parent window.
etc.
In the last hand (three hands ???), consider that some people working with legacy APIs are themselves using legacy code styling. The moment you hear "const is for dummies" or "I don't use namespaces because they decrease the runtime speed", or the even better "Hey, who needs C++? I code in my own brand of object-oriented C!!!" (No kidding... In a professional environment, and the result was quite a sight...), you'll feel the kind of dread only condemned feel in front of the guillotine.
So... All in all, it's an interesting experience.
Edit
After re-reading this post, I see it could be seen as overly negative. It is not.
It is sometimes interesting (as well as frustrating) to know how the things work under the hood. You'll understand that, despite enormous (impossible?) constraints, the Win32 API team did wonderful work to be sure everything, from you "olde Win16 program" to your "last Win64 over-the-top application", can work together, in the past, now, and in the future.
The question is: Do you really want to?
Because spending weeks to do things that could be done (and done better) in other more high-level and/or object-oriented API can be quite de-motivational (real life experience: 3 weeks for Win API, against 4 hours in three other languages and/or libraries).
Anyway, you'll find Raymond Chen's Blog very interesting because of his insider's view on both Win API and its evolution through the years:
https://blogs.msdn.microsoft.com/oldnewthing/
Absolutely. When nobody knows the low level, who will update and write the high level languages? Also, when you understand the low level stuff, you can write more efficient code in a higher level language, and also debug more efficiently.
The native APIs are the "real" operating system APIs. The .NET library is (with few exceptions) nothing more than a fancy wrapper around them. So yes, I'd say that anybody who can understand .NET with all its complexity, can understand relatively mundane things like talking to the API without the benefit of a middle-man.
Just try to do DLL Injection from managed code. It can't be done. You will be forced to write native code for this, for windowing tweaks, for real subclassing, and a dozen other things.
So yes: you should (must) know both.
Edit: even if you plan to use P/Invoke.
On the assumption that you're building apps targeted at Windows:
it can sure be informative to understand lower levels of the system - how they work, how your code interacts with them (even if only indirectly), and where you have additional options that aren't available in the higher-level abstractions
there are times when your code might not be as efficient, high-performance or precise enough for your requirements
However, in more and more cases, folks like us (who never learned "unmanaged coding") will be able to pull off the programming we're trying to do without "learning" Win32.
Further, there's plenty of sites that provide working samples, code fragments and even fully-functional source code that you can "leverage" (borrow, plagiarize - but check that you're complying with any re-use license or copyright!) to fill in any gaps that aren't handled by the .NET framework class libraries (or the libraries that you can download or license).
If you can pull off the feats you need without messing around in Win32, and you're doing a good job of developing well-formed, readable managed code, then I'd say mastering .NET would be a better choice than spreading yourself thin over two very different environments.
If you frequently need to leverage those features of Windows that haven't received good Framework class library coverage, then by all means, learn the skills you need.
I've personally spent far too much time worrying about the "other areas" of coding that I'm supposed to understand to produce "good programs", but there's plenty of masochists out there that think everyone's needs and desires are like their own. Misery loves company. :)
On the assumption that you're building apps for the "Web 2.0" world, or that would be just as useful/beneficial to *NIX & MacOS users:
Stick with languages and compilers that target as many cross-platform environments as possible.
pure .NET in Visual Studio is better than Win32 obviously, but developing against the MONO libraries, perhaps using the Sharp Develop IDE, is probably an even better approach.
you could also spend your time learning Java, and those skills would transfer very well to C# programming (plus the Java code would theoretically run on any platform with the matching JRE). I've heard it said that Java is more like "write once, debug everywhere", but that's probably as true as (or even moreso than) C#.
Analogy: If you build cars for a living (programming), then its very pertinent to know how the engine works (Win32).
Simple answer, YES.
This is the answer to any question that is like.. "does it make sense to learn a low level language/api X even when a higher level language/api Y is there"
YES
You are able to boot up your Windows PC (or any other OS) and ask this question in SO because a couple of guys in Microsoft wrote 16-bit assembly code that loads your OS.
Your browser works because someone wrote an OS kernel in C that serves all your browser's requests.
It goes all the way up to scripting languages.
Big or small, there is always a market and opportunity to write something in any level of abstraction. You just have to like it and fit in the right job.
No api/language at any level of abstraction is irrelevent unless there is a better one competing at the same level.
Another way of looking at it: A good example from one of Michael Abrash's book: A C programmer was given the task of writing a function to clear the screen. Since C was a better (higher level) abstraction over assembly and all, the programmer only knew C and knew it well. He did his best - he moved the cursor to each location on the screen and cleared the character there. He optimized the loop and made sure it ran as fast as it could. But still it was slow... until some guy came in and said there was some BIOS/VGA instruction or something that could clear the screen instantly.
It always helps to know what you are walking on.
Yes, for a few reasons:
1) .net wraps Win32 code. .net is usually a superior system to code against, but having some knowledge of the underlying Win32 layer (oops, WinAPI now that there is 64-bit code too) bolsters your knowledge of what is really happening.
2) in this economy, it is better to have some advantages over the other guy when you are looking for a job. Some WinAPI experience may provide this for you.
3) some system aspects are not available through the .net framework yet, and if you want to access those features you will need to use p/invoke (see http://www.pinvoke.net for some help there). Having at least a smattering of WinAPI experience will make your p/invoke development effort a lot more efficient.
4) (added) Now that Win8 has been around for awhile, it is still built on top of the WinAPI. iOS, Android, OS/X, and Linux are all out there, but the WinAPI will still be out there for many many years.
Learning a new programming language or technology is for one of three reasons:
1. Need: you're starting a project for building a web application and you don't know anything about ASP.NET
2. Enthusiasm: you're very excited about ASP.NET MVC. why not try that?
3. Free time: but who has that anyway.
The best reason to learn something new is Need. If you need to do something that the .NET framework can't do (like performance for example) then WinAPI is your solution. Until then we keep ourself busy with learning about .NET
For most needs on the desktop you wont need to know the Win32, however there is a LOT of Win32 not in .NET, but it is in the outlaying stuff that may end up being less than 1% of your application.
USB support, HID support, Windows Media Foundation just off the top of my head. There are many cool Vista API's only available from Win32.
You will do yourself a large favor by learning how to do interop with a Win32 API, if you do desktop programing, because when you do need to call Win32, and you will, you won't spend weeks scratching your head.
Personally I don't really like the Win32 API but there's value in learning it as the API will allow more control and efficiency using the GUI than a language like Visual Basic, and I believe that if you're going to make a living writing software you should know the API even if you don't use it directly. This is for reasons similar to the reasons it's good to learn C, like how a strcpy takes more time than copying an integer, or why you should use pointers to arrays as function parameters instead of arrays by value.
Learning C or a lower level language can definitely be useful. However, I don't see any obvious advantage in using the unmanaged WinAPI.
I've seen low level Windows API code... it ain't pretty... I wish I could unlearn it. I think it benefits to learn low level as in C, as you gain a better understanding of the hardware architecture and how all that stuff works. Learning old Windows API... I think that stuff can be left to the people at Microsoft who may need to learn it to build higher level languages and API... they built it, let them suffer with it ;-)
However, if you happen to find a situation where you feel you just can't do what you need to do in a higher level language (few and far between), then perhaps start the dangerous dive into that world.
yes. take a look at uTorrent, an amazing piece of software efficiency. Half of it's small size is due to the fact that much of it's core components were re-written to not use gargatuian libraries.
Much of this couldn't be done without understanding how these libraries interface with the lower level API's
It's important to know what is available with the Windows API. I don't think you need to crank out code with it, but you should know how it works. The .NET Framework contains a lot of functionality, but it doesn't provide managed code equivalents for the entire Windows API. Sometimes you have to get a bit closer to the metal, and knowing what's down there and how it behaves will give you a better understanding of how to use it.
This is really the same as the question, should I learn a low level language like C (or even assembler).
Coding in it is certainly slower (though of course the result is much faster), but its true advantage is you gain an insight into what is happening at close to the system level, rather than than just understanding someone else's metaphor for what is going on.
It can also be better when things won't work well, or fast enough or with the sort of granularity that you need. (And do at least some subclassing and superclassing.)
I'll put it this way. I don't like programming to the Win32 API. It can be a pain compared to managed code. BUT, I'm glad I know it because I can write programs that otherwise I wouldn't be able to. I can write programs that other people can't. Plus it gives you more insight into what your managed code is doing behind the scenes.
The amount of value you get out of learning the Win32 API, (aside from the sorts of general insights you get from learning about how the nuts and bolts of the machine fit together) depends on what you're trying to achieve. A lot of the Win32 API has been wrapped nicely in .NET library classes, but not all of it. If for instance you're looking to do some serious audio programming, that portion of the Win32 API would be an excellent subject of study because only the most basic of operations are available from .NET classes. Last I checked even the managed DirectX DirectSound library was awful.
At the risk of shameless self-promotion....
I just came across a situation where the Win32 API was my only option. I want to have different tooltips on each item in a listbox. I wrote up how I did it on this question.
Even in very very high level languages you still make use of the API. Why? Well not every aspect of the API has been replicated by the various libraries, frameworks, etc. You need to learn the API for as long as you will need the API to accomplish what you are trying to do. (And no longer.)
Apart from some very special cases when you need direct access to APIs, I would say NO.
There is considerable time and effort required to learn to implement the native API calls correctly and the returning value is just not worth it. I would rather spend the time learning some new hot technology or framework that will make your life easier and programming less painful. Not decades-old obsolete COM libraries that nobody really uses anymore (sorry to COM users).
Please don't stone me for this view. I know a lot of engineers here have really curious souls and there is nothing wrong with learning how things work. Curiousity is good and really helps understanding. But from a managerial point of view, I would rather spend a week learning how to develop Android apps than how to calls OLEs or COMs.
If you planning to develop a cross platform application, If you use win32, then your application could easily run on linux through WINE. This results in a highly maintainable application. This is one of the advantages of learning win32.

Resources