javascript list manipulation library/framework - list

I'm looking for a javascript library/framework to manipulate lists. Is there anything like this already out there?
Ideally I'd like something equivalent to .NET's List. One of the main requirements is the ability to remove items from anywhere in a list. Some LINQ-like functionality would be great.

Underscore.js
It's not a substitute for a completely functional List replacement, but:
it does get you a long way,
it's well designed,
well documented (and has a very nicely "literate-programming"-style annotated source),
easy to extend,
lightweight.
It has a nice expressiveness and power to memory footprint ratio.
(Note that is was inspired by the two following libraries, FunctionalJS and Data.js.)
FunctionalJS
It shares most of Underscore.js's attributes, and is definitely more oriented towards functional programming. However:
it is less actively maintained,
it is slightly harder to use if you're not familiar with functional concepts.
Data.js
More than a purely functional programming library like FunctionalJS, Data.js also covers storage aspects, graph-like data-structures and other goodies.
(It is funny to note that Data.js now lists Underscore.js has an influence in its newer iteration, while Underscore.js already lists Data.js as its own influence.)
List.js
List.js is for manipulating HTML lists. It may not be what you want, but I thought of adding it here as well as it does its job very well and fits a nice niche in terms of briding data and UI management in one (not necessarily a good idea, but works for some cases).
Others...
Dojo (and many other JS libraries nowadays) supports some of the newer JS APIs or provides substitute implementations if they are missing, with some of them fairly functional by nature and design.
However, they don't push the concept quite as far, and these libraries are more heavyweight, so I wouldn't recommend them if that's all you want out of them.
jLinq, as mentioned by JanusTroelsen in your question's comments, looks very promising as well but I would be more concerned about the maturity of the library and its memory footprint for what it is (but the code seems very "spaced", so a compressed version might be acceptable).

May linq.js what you're looking for ? http://neue.cc/reference.htm
Also, http://microjs.com/ is a good site to find a library corresponding to a specific need :)

Also you can try manipula package that implements all of C# LINQ methods and preserves its syntax:
https://www.npmjs.com/package/manipula

Related

Interactve and dynamic plots/charts in clojure

Does clojure have any libraries for showing dynamic plots/charts, something as simple as oscillating sine wave for example?
Looked at incanter library, but it seems to only provide static plots.
Not really a plotting library, but you could use the quil interface to the Java Processing library.
If you're willing to use Clojurescript, I'd suggest looking at d3.js and the strokes library for using it from Clojurescript. However, this requires learning d3.js's quirky methodology, and will require quite a bit of thinking in terms of HTML, DOM, CSS, and Javascript even if you write most of the code in Clojure. [EDIT: I now think it's simpler to use d3.js directly from Clojurescript; strokes provides little benefit. There are also some Clojurescript chart libraries built on d3.js. I've found NVD3 useful, for example.]
There's also an all-Clojurescript C2 library, designed to implement some of the functionality of d3.js, but doesn't allow dynamic plotting, though you can add dynamic features using custom CSS. (C2 is not really growing, AFAIK, but it's actively maintained.)
Another option, which might actually be easier (or not) would be to use a Java library that does what you want. No doubt there are several, including JFreeChart. This also might require a bit of thinking Java-style, learning about Clojure-Java interop (which ranges from trivially easy to ugly, confusing, and verbose, depending on how the Java library is structured).
For whatever it's worth, there are libraries for interfacing Java with R, which has very nice plotting capabilities through it's built-in plotting, the ggplot2 library, and the lattice library. So in theory, you could use Clojure to control Java to control R, which may not be worth it. See this question for Java-to-R libraries.
You should also ask on the Incanter Google group. Maybe there are some hidden tricks, or something in development that will do what you want.
EDIT: Incanter does provide something called "dynamic plots". Not exactly what you want, I think: These are charts that have parameters attached to sliders so that you can see plot change over time. Nevertheless, the fact that Incanter can do this suggests that it might not be that difficult to create a chart that dynamically changes in response to changes in data.
ONE MORE EDIT: Since JFreeChart is what Incanter uses to draw charts, and JFreeChart is a Java library that is able to generate dynamic charts, an option is to use Java methods on the chart objects that Incanter produces, as this answer suggests.
(EDIT: A search for "clojure jfreechart" turns up a few libraries and tutorials intended to help one use JFreeChart with Clojure.)
Anndd ... one more EDIT: https://github.com/liebke/apogee
looks like it may be exactly what you wanted, jyriand. (I'm interested in related questions, and I keep noticing new potential answers to this one.)

Looking for Projects having extensive usage of (mostly used) design patterns

I want to get my hands dirty with some projects (in C++) which have used design patterns extensively.
I have already read design pattern documentation (as well as code) from net and other books (gang of four and Head first), but i am looking for a place where i can get already implemented projects (using design patterns), get my hands dirty with them, understand them, enhance them etc.
Could anybody point me to a place(s) from where I can get design experience in the best possible way? (Please note: Language C++, Complexity of the project can be intermediate to difficult)
ACE is a good example - uses many concurrency and communications patterns. There's a list of related tutorials on their website here.
If you are feeling ambitious take a look at Loki.

A generic C++ library that provides QtConcurrent functionality?

QtConcurrent is awesome.
I'll let the Qt docs speak for themselves:
QtConcurrent includes functional programming style APIs for parallel list processing, including a MapReduce and FilterReduce implementation for shared-memory (non-distributed) systems, and classes for managing asynchronous computations in GUI applications.
For instance, you give QtConcurrent::map() an iterable sequence and a function that accepts items of the type stored in the sequence, and that function is applied to all the items in the collection. This is done in a multi-threaded manner, with a thread pool equal to the number of logical CPU's on the system.
There are plenty of other function in QtConcurrent, like filter(), filteredReduced() etc. The standard CompSci map/reduce functions and the like.
I'm totally in love with this, but I'm starting work on an OSS project that will not be using the Qt framework. It's a library, and I don't want to force others to depend on such a large framework like Qt. I'm trying to keep external dependencies to a minimum (it's the decent thing to do).
I'm looking for a generic C++ framework that provides the same/similar high-level primitives that QtConcurrent does, and that works with STL collections. AFAIK boost has nothing like this (I may be wrong though). boost::thread is very low-level compared to what I'm looking for (but if the requested lib used boost::thread for the low-level work, that would be great).
I know C# has something very similar with their Parallel Extensions so I know this isn't a Qt-only idea.
What do you suggest I use?
I've heard good things about Intel's Threaded Building Blocks, though I haven't used it
As of Oct 2009, it doesn't seem to have map-reduce specifically. But people have expressed interest and suggested they were going to come up with something:
http://software.intel.com/en-us/forums/showthread.php?t=65053
"map reduce looks like a simple combination of a filter, a sort, and a reduction but it might need some magic to get it to be efficient"
Can you use Boost? I don't think it provides quite as high-abstraction a layer as Qt, but it should be possible to make one as a reasonably thin facade on top of Boost's primitives (indeed, maybe some of the existing add-ons already provide what you require -- I have to admit I'm not familiar with them in detail, which is why I say "maybe";-).
If you find out that existing add-ons are unsuitable, your facade would be an excellent add-on to contribute to the Boost Vault (or other open-source repo) yourself, "giving back" a useful reusable open-source contribution... I hope this motivates you to do this work if needed!-)

Write C++ in a graphical scratch-like way?

I am considering the possibility of designing an application that would allow people to develop C++ code graphically. I was amazed when I discovered Scratch (see site and tutorial videos).
I believe most of C++ can be represented graphically, with the exceptions of preprocessor instructions and possibly function pointers.
What C++ features do you think could be (or not be) represented by graphical items?
What would be the pros and cons of such an application ? How much simpler would it be than "plain" C++?
RECAP and MORE:
Pros:
intuitive
simple for small applications
helps avoid typos
Cons:
may become unreadable for large (medium?) - sized applications
manual coding is faster for experienced programmers
C++ is too complicated a language for such an approach
Considering that we -at my work- already have quite a bit of existing C++ code, I am not looking for a completely new way of programming. I am considering an alternate way of programming that is fully compatible with legacy code. Some kind of "viral language" that people would use for new code and, hopefully, would eventually use to replace existing code as well (where it could be useful).
How do you feel towards this viral approach?
When it comes to manual vs graphical programming, I tend to agree with your answers. This is why, ideally, I'll find a way to let the user always choose between typing and graphical programming. A line-by-line parser (+partial interpreter) might be able to convert typed code into graphical design. It is possible. Let's all cross our fingers.
Are there caveats to providing both typing and graphical programming capabilities that I should think about and analyze carefully?
I have already worked on template classes (and more generally type-level C++) and their graphical representation.
See there for an example of graphical representation of template classes. Boxes represent classes or class templates. First top node is the class itself, the next ones (if any) are typedef instructions inside the class. Bottom nodes are template arguments. Edges, of course, connect classes to template arguments for instantiations.
I already have a prototype for working on such type-level diagrams.
If you feel this way of representing template classes is plain wrong, don't hesitate to say so and why!
Much as I like Scratch, it is still much quicker for an experienced programmer to write code using a text editor than it is to drag blocks around, This has been proved time and again with any number of graphical programming environments.
Writing code is the easiest part of a developers day. I don't think we need more help with that. Reading, understanding, maintaining, comparing, annotating, documenting, and validating is where - despite a gargantuan amount of tools and frameworks - we still are lacking.
To dissect your pros:
Intuitive and simple for small applications - replace that with "misleading". It makes it look simple, but it isn't: As long as it is simple, VB.NET is simpler. When it gets complicated, visual design would get in the way.
Help avoid typos - that's what a good style, consistency and last not least intellisense are for. The things you need anyway when things aren't simple anymore.
Wrong level
You are thinking on the wrong level: C++ statements are not reusable, robust components, they are more like a big bag of gears that need to be put together correctly. C++ with it's complexity and exceptions (to rules) isn't even particulary suited.
If you want to make things easy, you need reusable components at a much higher level. Even if you have these, plugging them together is not simple. Despite years of struggle, and many attempts in many environments, this sometimes works and often fails.
Viral - You are correct IMO about that requriement: allow incremental adoption. This is closely related to switching smoothly between source code and visual representation, which in turn probably means you must be able to generate the visual representation from modified source code.
IDE Support - here's where most language-centered approaches go astray. A modern IDE is more than just a text editor and a compiler. What about debugging your graph - with breakpoints, data inspection etc? Will profilers, leak detectors etc. highlight nodes in your graph? Will source control give me a Visual Diff of yesterday's graph vs. today's?
Maybe you are on to something, despite all my "no"s: a better way to visualize code, a way to put different filters on it so that I see just what I need to see.
The early versions of C++ were originally written so that they compiled to C, then the C was compiled as normal.
What it sounds like you are describing is a graphical language that is compiled to C++, which will then be compiled as normal.
So really you are not creating a graphical C++, you are creating a new language that happens to be graphical. Nothing wrong with that, but don't let C++ restrict what you do, because eventually you may want to compile the graphical language straight to machine code, or even to something like CIL, Java ByteCode, or whatever else tickles your fancy.
Other graphical languages you may want to check out are LabVIEW, and more generally the category of visual programming languages.
Good luck in your efforts.
The complexity of a nontrivial program is usually too high to be represented with graphical symbols, which are low in their information content. Unless your approach is markedly different in some way, I am skeptical that this would be of value based on past efforts.
So, practically speaking, his will be useful only for instructional purposes and very simple programs. But that would still be a great target market for a product like this. sometimes people have trouble grasping the fundamentals, and a visual model might be just the thing to help things click.
Interesting idea. I doubt I'd use it though. I tend to prefer coding in a flat text editor, not even an IDE, and for tough problems I prefer a pad of paper. Most of the really experienced programmers I know work this way, Maybe it's because we grew up in a different environment, but I think it's also because of the way we think about programming. As you get more experience, you start seeing the code in your head more clearly than any GUI tool will show it to you.
As for your question, I'd nominate templates as one of the harder / more interesting sort of thing to try to represent well. They are ubiquitous and carry information that you won't have access to as you are designing your tool. Getting that to the user in a useful way should pose an interesting challenge.
What C++ features do you think could be [...] represented by graphical items?
Object Oriented Design. Hence classes, inheritance, polymorphism, mutability, const-ness etc. And, templates.
What would be the pros and cons of such an application?
It may be easier for beginners to start writing programs. For the experienced, it may be get rid of the boring parts of programming.
Think of any other code generator. They create a framework for you to write the more involved portion(s). They also lead to bloated-code (think of any WYSIWYG HTML editor).
The biggest challenge, as I see it, is that any such UI necessarily hinders the user's imagination.
How much simpler would it be than "plain" c++ ?
It can be a real pain, when you wade through truckloads of errors which is typical of code generators.
Further, since a lot of code is generated, you have no idea of what is going on -- debugging becomes difficult.
Also, for the experienced there may be some irritation to find that the generated code is not per their preferred coding style.
I prefer hot-keys instead graphical menus and buttons.
And I think same thing will happen with graphical development tool. Many peoples will prefer manual codding.
But, source code visualizer - should be nice thing.
I like the idea, but I suspect there comes a point where things get far too complicated to be represented graphically.
However, given recent experience at work; it would be useful to give such a graphical interface to a non-techie person to use to create basic drag-and-drop programs, leaving myself free to get on with some "proper" programming ;-) If it can do the job of allowing somebody non-skilled to build something functional it can be a very good thing (even if programming logic escapes them)
There comes a point in such a system where it becomes easier to define what you want to do using literal C++ code, rather than have a user interface getting in the way; it can get frustrating to the sessioned programmer knowing the precise code that needs to be written but then only being limited to the design GUI. I'm specifically thinking about a more common application, such as html editors/designers in which they allow newbies to build their websites without knowing any html at all.
It would be interesting to see how such a system would handle the dynamic allocation of memory, and the different states of a program as time progressed; I suspect that there are some very basic programming concepts that may be difficult to represent graphically.. Polymorphism..? Virtual Classes, LinkList, Stacks/Circular Queues. I wonder for a moment how you would explain an image compression algorithm (such as jpg) successfully too without the help of a gigantic display screen.
I also wonder if such a system would even go to such a low level, and whether you would be dealing with abstracted concepts and the compiler would be working out the best way to do something.
I've been working on a new model-driven software development paradigm named ABSE (http://www.abse.info) that supports end-user programming: It's a template-based system that can be complemented with transformation code. I also have an IDE (named AtomWeaver) implementing ABSE that is in pre-alpha stage right now.
With AtomWeaver, as an expert/architect, you build your knowledge Templates, and then the developers (or end-users if you make your meta-models simpler) can just "assemble" systems by building blocks, and then filling template parameters in form-style editors.
At the end, pressing the "Generate" button will create the final system as specified by the architect/expert.
I'm surprised you think function pointers would be a particular problem. How about anything at all to do with pointers?
A programming language can be represented by a hierarchy of nodes - that's exactly what the compiler turns it into. It is very strange that the UI for editing programs is still a sequence of characters that get parsed, because the degrees of freedom in the editor is way larger than the available set of allowed choices. But intellisense helps to reduce this problem a lot.
C++ would be a strange choice to base such a system on.
I think the major problem of this kind of IDEs are that the code generated becomes unmantainable easily.
This happened to Delphi. It's a really nice tool to develop some kind of applications, however, when we start adding complex relationships between the components, start adding Design Patterns, etc. the code grows to an unmantainable size.
I believe it's also because graphical tools don't apply the concept of MVC (or if they do, it's only in the way that the IDE understands).
It can be really helpful for prototypes and very small applications that don't tend to grow, otherwise it can become a mess for the developer(s)

How do you glue Lua to C++ code?

Do you use Luabind, toLua++, or some other library (if so, which one) or none at all?
For each approach, what are the pro's and con's?
I can't really agree with the 'roll your own' vote, binding basic types and static C functions to Lua is trivial, yes, but the picture changes the moment you start dealing with tables and metatables; things go trickier very quickly.
LuaBind seems to do the job, but I have a philosophical issue with it. For me it seems like if your types are already complicated the fact that Luabind is heavily templated is not going to make your code any easier to follow, as a friend of mine said "you'll need Herb Shutter to figure out the compilation messages". Plus it depends on Boost, plus compilation times get a serious hit, etc.
After trying a few bindings, Tolua++ seems the best. Tolua doesn't seem to be very much in development, where as Tolua++ seems to work fine (plus half the 'Tolua' tutorials out there are, in fact, 'Tolua++' tutorials, trust me on that:) Tolua does generate the right stuff, the source can be modified and it seems to deal with complicated cases (like templates, unions, nameless structs, etc, etc)
The biggest issue with Tolua++ seems to be the lack of proper tutorials, pre-set Visual Studio projects, or the fact that the command line is a bit tricky to follow (you path/files can't have white spaces -in Windows at least- and so on) Still, for me it is the winner.
To answer my own question in part:
Luabind: once you know how to bind methods and classes via this awkward template syntax, it's pretty straightforward and easy to add new bindings. However, luabind has a significant performance impact and shouldn't be used for realtime applications. About 5-20 times more overhead than calling C functions that manipulate the stack directly.
I don't use any library. I have used SWIG to expose a C library some time ago, but there was too much overhead, and I stop using it.
The pros are better performance and more control, but its takes more time to write.
Use raw Lua API for your bindings -- and keep them simple. Take inspiration in the API itself (AUX library) and libraries by Lua authors.
With some practice raw API is the best option -- maximum flexibility and minimum of unneeded overhead. You've got what you want and no more, the way you need it to be.
If you must bind large third-party libraries use automated generators like tolua, tolua++ (or even roll your own for the specific case). It would free you from manual work.
I would not recommend using Luabind. At the moment it's development stalled (however starting to come back to life), and if you would meet some corner case, you may be on your own. Also Luabind heavily uses template metaprogramming. This may (and may not) be unacceptable, depending on the point of view.