Skip to main content

Home/ ProgrammingPages/ Group items tagged generics

Rss Feed Group items tagged

Navneet Kumar

Bruce Eckel's MindView, Inc: 3-10-04 Generics Aren't - 0 views

  • Generics seem to only solve the problem of automatically casting in and out of containers.
  • So if we write generic code that actually takes a "type of anything," that type can only be an Object, and our generic code must only call Object methods on it.
  • generics have no advantage. In fact, it's confusing if you see them used, because you scratch your head and wonder "why does he need a generic here? What is the advantage?" Answer: none.
  • ...3 more annotations...
  • Java Generics use "erasure," which drops everything back to Object if you try to say "any type." So when I say <T>, it doesn't really mean "anything" like C++/ADA/Python etc. does, it means "Object."
  • So generics are really "autocasting."
  • That's the way of the Java world, and we are going to miss out on latent typing (it's actually possible to simulate latent typing using reflection, as I do once or twice in Thinking in Java, but it's messy and much less elegant).
  •  
    bruce Eckel article on java generics, and how it does  nothing more than  autocasting. Also templating or parameterized type in C++, Ruby, Python
Navneet Kumar

Ken Arnold's Blog: Generics Considered Harmful - 0 views

  • this: Enum is actually a generic class defined as Enum<T extends 
  • When used in public interfaces, generics are also invaluable to enforce correctness, prevent bugs and reduce testi
  • generics is reifying type relationships that are otherwise implic
  • ...4 more annotations...
  • The problem is that generics don't get on with arrays. The solution is obvious: ditch arrays. From a practical point of view, there's not a great deal of point in returning arrays from methods instead of collections of s
  • Note the circular reference in "Unique<T extends Unique>" It means that the implementing class needs to provide another unique class as the namespace for it's Id's. The really freaky thing is that it can provide itself. :) These two interfaces enable a way to describe uniquely identified objects with heirarchical namespaces in a typesafe manner. How much complex code did that save?
  • ype". You only need generics in strictly typed function dispatch languages like C++ and Java. You don't need them in message passing dynamically typed languages like Smalltalk and Objective C. To work around the first rule - "strict static typing doesn't really work all the time", we get hacks like templates and generics
  • call the Elvis/Einstein b
  •  
    discussion on java generics, too complex, dangerous or useful, type safety, when n how to use
Navneet Kumar

Generics in C#, Java, and C++ - 1 views

  • And really all they're doing in their implementation is automatically inserting those type casts for you. So you get the syntactic sugar, or some of it at least, but you don't get any of the execution efficiency
  • because Java's generics implementation relies on erasure of the type parameter, when you get to runtime, you don't actually have a faithful representation of what you had at compile time. When you apply reflection to a generic List in Java, you can't tell what the List is a List of.
  • C# does the instantiation at runtime.
Navneet Kumar

Inversion of Control Containers and the Dependency Injection pattern - 0 views

  • The main difference is that I expect a component to be used locally (think jar file, assembly, dll, or a source > > i mport). A service will be used remotely through some remot >e > i nterface, either synchronous or asynchronous > >
  • configuration through XML files and also through code
    • Navneet Kumar
       
      or can be stored in a DB table
  • dynamic service locator
  • ...16 more annotations...
  • Dependency injection and a service locator aren't necessarily mutually exclusive concepts.
  • With service locator the application class asks for it explicitly by a message to the locator. With injection there is no explicit request, the service appears in the application class - hence the inversion of control.
  • with a Service Locator every user of a service has a dependency to the locator. The locator can hide dependencies to other implementations, but you do need to see the locator.
  • In this kind of scenario I don't see the injector's inversion as providing anything compelling.The difference comes if the lister is a component that I'm providing to an application that other people are writing. In this case I don't know much about the APIs of the service locators that my customers are going to use. Each customer might have their own incompatible service locators
  • Since with an injector you don't have a dependency from a component to the injector, the component cannot obtain further services from the injector once it's been configured.
  • frameworks should minimize their impact upon application code, and particularly should not do things that slow down the edit-execute cycle. Using plugins to substitute heavyweight components does a lot help this process, which is vital for practices such as Test Driven Development.
  • a more general issue with object-oriented programming - should you fill fields in a constructor or with setters.
  • Another advantage with constructor initialization is that it allows you to clearly hide any fields that are immutable by simply not providing a setter. I think this is important - if something shouldn't change then the lack of a setter communicates this very well
  • The problem with classic Factory Methods for components assembly is that they are usually seen as static methods, and you can't have those on interfaces. You can make a factory class, but then that just becomes another service instance. A factory service is often a good tactic, but you still have to instantiate the factory using one of the techniques here
  • Factory Methods
  • start with constructor injection, but be ready to switch to setter injection
  • One case is where you have a simple application that's not got a lot of deployment variation. In this case a bit of code can be clearer than separate XML file.
  • configuration files or code on an API to wire up services
  • the Java world at the moment is a cacophony of configuration files,
  • using aspect oriented ideas with these containers
    • Navneet Kumar
       
      Aspect Oriented Programming AOP. can be possible with IoC.
  • When building application classes the two are roughly equivalent, but I think Service Locator has a slight edge due to its more straightforward behavior. However if you are building classes to used in multiple applications then Dependency Injection is a better choice.
  •  
    article by martin fowler on Inversion of control and dependency injection design patterns which are used in the spring framework.
Navneet Kumar

defmacro - Functional Programming For The Rest of Us - 0 views

  • In a lazy language you have no guarantee that the first line will be executed before the second! This means we can't do IO, can't use native functions in any meaningful way (because they need to be called in order since they depend on side effects), and can't interact with the outside world! If we were to introduce primitives that allow ordered code execution we'd lose the benefits of reasoning about our code mathematically
  • continuations, monads, and uniqueness typing.
  • Alonzo Church developed a formal system called lambda calculus. The system was essentially a programming language for one of these imaginary machines
  • ...18 more annotations...
  • Functions that operate on other functions (accept them as arguments) are called higher order functions.
  • currying is used to reduce the number of arguments
  • only executes code when it's required
  • A lazy compiler thinks of functional code exactly as mathematicians think of an algebra expression - it can cancel things out and completely prevent execution, rearrange pieces of code for higher efficiency, even arrange code in a way that reduces errors, all guaranteeing optimizations won't break the code.
  • John McCarthy (also a Princeton graduate) developed interest in Alonzo Church's work. In 1958 he unveiled a List Processing language (Lisp)
  • Lisp machine - effectively a native hardware implementation of Alonzo's lambda calculus!
  • it was proved that lambda calculus is equivalent to a Turing machine.
  • It turns out that functional programs can keep state, except they don't use variables to do it. They use functions instead. The state is kept in function parameters, on the stack. If you want to keep state for a while and every now and then modify it, you write a recursive function
  • Erlang engineers have been upgrading live systems without stopping them for years.
  • Erlang systems are not scalable and reliable. Java systems are. Erlang systems are simply rock solid
  • Ericsson designed a functional language called Erlang for use in its highly tolerant and scalable telecommunication switches.
  • Continuation Passing Style or CPS
  • A "continuation" is a parameter we may choose to pass to our function that specifies where the function should return.
  • continuations are a generalization of functions.
  • CPS version needs no stack! No function ever "returns" in the traditional sense, it just calls another function with the result instead. We don't need to push function arguments on the stack with every call and then pop them back, we can simply store them in some block of memory and use a jump instruction instead. We'll never need the original arguments - they'll never be used again since no function ever returns!
  • What does the stack contain? Simply the arguments, and a pointer to memory where the function should return. Do you see a light bulb? The stack simply contains continuation information! The pointer to the return instruction in the stack is essentially the same thing as the function to call in CPS programs!
  • A continuation and a pointer to the return instruction in the stack are really the same thing, only a continuation is passed explicitly, so that it doesn't need to be the same place where the function was called from
  • When we get a current continuation and store it somewhere, we end up storing the current state of our program - freezing it in time. This is similar to an OS putting itself into hibernation. A continuation object contains the information necessary to restart the program from the point where the continuation object was acquired.
  •  
    deals from the history of functional languages
    what are functional languages, benefits

Navneet Kumar

MySQL Performance Blog » MySQL Query Cache - 0 views

  • It does not cache the plan but full result sets
  • so it looks at first letter of the query and if it is “S” it proceeds with query lookup in cache if not - skips it.
  • Might not work with transactions
  • ...15 more annotations...
  • uses non-deterministic functions such as UUID(), RAND(), CONNECTION_ID() etc it will not be cached.
  • If table gets modification all queries derived from this table are invalidated at once
  • if you have high write application such as forums, query cache efficiency might be pretty low due to this.
  • all queries are removed from cache on table modifications - if there are a lot of queries being cached this might reduce update speed a bit
  • Qcache_free_memory and Qcache_lowmem_prunes
  • number of your selects - Com_select and see how many of them are cached. Query Cache efficiency would be Qcache_hits/(Com_select+Qcache_hits).
  • One portion of query cache overhead is of course inserts so you can see how much of inserted queries are used: Qcache_hits/Qcache_inserts Other portion of overhead comes from modification statements which you can calculate by (Com_insert+Com_delete+Com_update+Com_replace)/Qcache_hits
  • want to set query cache
  • means it is much more efficient as query which required processing millions of rows now can be instantly summoned from query cache
  • It also means query has to be exactly the same and deterministic, so hit rate would generally be less
  • full page caching
  • not using query_cache_wlock_invalidate=ON locking table for write would not invalidate query cache so you can get results evenif table is locked and is being prepared to be updated
  • it can serve responses very fast doing no extra conversion or processing.
  • but it is still not as fast as specially designed systems such as memcached or local shared memory.
  • It is not distributed If you have 10 slaves and use query cache on all of them cache content will likely be the same, so you have multiple copies of the same data in cache effectively wasting memory
  •  
    mysql query caching
1 - 6 of 6
Showing 20 items per page