My opinion on Javascript

Java Script is a good language for manipulating the DOM and maybe write some small scripts but I would hate to use it in a large project. This is because of the missing safety that strong typed languages have, refactoring or adding things in an existing javascript project would be a huge pain, maybe if you have test cases for everything you can do it with more confidence.

Prolog

Writing code with this programming language is always a chalange and always satisfing to solve problems with this language. I think the reason I like it so much is that it forces you to think in a different way, similar like FP programming does, I am planing to read some Prolog books in this weeked if I have time.

Public domain image from Pixabay

Flex Drag and Drop is broken

I am trying for  a week to make draging from a List or Tree into an HTMl work, but the framework is so broekn, soem events will nver fire like the dragdrop event, calling acceptDragDrop has no effect and later I noticed that mouseUp event are not fireing also(it works sometime in a test application so I fear is a layout thing, I read that  drops will not work on some containers but this seems to be a very stupid limitation.  

Flex setting the selectedItem on a tree freezes the application

application start freezing, after I debugged the code I found that the problem was the Tree setter selectedItem, googling I found this page http://forums.adobe.com/thread/823041 with people that have the same issue, the solution suggested was to call validateProperties before the problematic setter, this worked to make the app not freeze but the selectedItem did not done it's job so I used a callLater function to set the selectedItem  after an interval 

Egit merge

Today I made my first git merge, using EGit(an Eclipse plugin), I had to read a lot of documentation about egit, fix some conflicts and finaly commit the fixes. In the end all worked ok,not great  I am not sure I like how the conflict resolving works.

Accessing the ItemRenderer in a Flex spark DataGrid

I did not found a way to do this with the spark DataGrid, only with the mx one, the developers encapsulated very well the renderers. Because Flex is open source I read the code and finaly found a way to access the renderers. I could not use bindings in my case and I did not had other idea at that moment and because the renderers are very optimized it is hard to make them refresh.

 

 

My first scala steps

2Disclaimer(this is not a tutorial or how to, i am a newb to scala and i recod my thoughts)

I was reading about scala for a time now and yesterday i started coding. I started with a simple application, making some simple function and try to get used with the syntax. So i started coding without looking in the book(Programing in scala) or on the web(to really learn it,i used to copy paste or read then type code in the scala interpretor but those methods don’t let you make mistakes that will help you remember )



package scalaprim

object Main {

  /**
   * @param args the command line arguments
   */
  def main(args: Array[String]): Unit = {
    println("Hello, world!")
    println(divide(10,2))
    println(divide(10,3))
    println(isPrime(11))
    println(isPrime(4))
    //findPrimes(100)
    val primes=findPrimes3(100)
    //primes.foreach(println)
  //consecutivePrimes(primes);
  consecutivePrimes2(primes);
  }
def divide(number:Int,divizor:Int):Boolean=(number%divizor==0);
def isPrime(number:Int):Boolean={

  val range = 2.until(Math.sqrt(number).intValue +1)
  for (i <- range)
    {
    if(divide(number, i))
     return false;
  }
  return  true;
}
def findPrimes(number:Int):Unit={
    for(i <-2.until(number))
      {
        if(isPrime(i))
          println(i)
      }
  }
  def findPrimes2(number:Int):IndexedSeq[Int]={
    val range=2 until number+1
    val primes=range.filter(isPrime)
    return primes
  }
  def findPrimes3(number:Int):IndexedSeq[Int]={
    (2 until number+1)filter isPrime   
  }

  def consecutivePrimes(listOfPrimes:IndexedSeq[Int]):Unit={
    var i:Int=0;
    while(i{
        if(prev+2==curent)
          println(prev,",",curent)
         curent
        }})
  }
}


My conclusion on this project is that using scala i can write less code, especially it could be possible to skip using lots of for, i worked on a c++ program and i think i have more then 100 fors, and nested fors that could be easily replaced in scala with calls to filter or exist or something else. And reducing for is not only about code clarity but often you can make bugs in for loops, like mistaking the indices in nested loops or getting outside of the array bounds.

I will investigate Scala in my free time and hope i could put it to use in a large project.

P.S. blogilo is failing uploading my posts, hope eventualy this post will be uploaded(finding a fix and trying another apps)

C++ debugging tip(for gcc and STL)

I want to wrote this tip down for me,to find it when i forget the details and for others that are searcing for it.

So if you are using STL containers like a vector,some strange errors errors can appear if you use an out of range index to the container. If you use .at() method then you are safe ,but you used [] in a lot of places and you can use the flag -D_GLIBCXX_DEBUG to use a safe STL container that will check and will find this errors.

The problem with this errors is theat the program will crash usualy in other place not in the place were the bug is. In my case the program crashed in the ~vector destructor. Read on google about using this flags have some problems(the important one is that you must rebuild all the parts that interoperate with STL containers).

To add this flag in a Qt project you need to add this line in the .pro file

QMAKE_CXXFLAGS +=-D_GLIBCXX_DEBUG1